Posted: 15th Apr 2021 8:07
I've currently got something like so to handle window resizing:
+ Code Snippet
        IF NOT Opt.FullScreen
            IF NOT Opt.WinResWidth = GetWindowWidth() OR NOT Opt.WinResHeight = GetWindowHeight()
                Opt.WinResWidth  = GetWindowWidth()
                Opt.WinResHeight = GetWindowHeight()

                // @fix  is there a better way to do this?
                IF Opt.WinResWidth  < 512 : Opt.WinResWidth  = 512 : SetWindowSize( Opt.WinResWidth, Opt.WinResHeight, Opt.FullScreen, Opt.AllowOverSizedWindow ) : ENDIF
                IF Opt.WinResHeight < 512 : Opt.WinResHeight = 512 : SetWindowSize( Opt.WinResWidth, Opt.WinResHeight, Opt.FullScreen, Opt.AllowOverSizedWindow ) : ENDIF

                SetVirtualResolution( Opt.WinResWidth, Opt.WinResHeight )
            ENDIF
        ENDIF

However, when the window size goes below 512 the window flickers a lot and occasionally the window still ends up smaller that 512.
Is there a built-in way with the WinAPI to restrict window size? Can we get an AppGameKit command to restrict window size (min & max) while using SetWindowAllowResize(1)?
Posted: 15th Apr 2021 14:23
You could add a line in your main game loop to check window size and if it is below 512, make it 512.
Posted: 16th Apr 2021 22:29
That's what I'm doing in the Code Snippet.

It appears it is possible to restrict the minimum window size in WinAPI:
https://stackoverflow.com/questions/22261804/how-to-set-minimum-window-size-using-winapi
https://stackoverflow.com/questions/19035481/maximum-and-minimum-window-sizes-in-winapi
Posted: 17th Apr 2021 17:17
My window close plugin already hooks into the agk window callback so I added a few lines to set the MINMAXINFO structure

// Resizing Window
WC.SetMinTrackSize(300, 300)
WC.SetMaxTrackSize(900, 700)

Example: (plugin attached)
+ Code Snippet
// Project: WindowClose 
// Created: 2021-04-17

#import_plugin WindowClose as WC


// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "WindowClose" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts



// register the window with the plugin, sets user callback etc
agk_hwnd = WC.Register("WindowClose")

// Resizing Window
WC.SetMinTrackSize(300, 300)
WC.SetMaxTrackSize(900, 700)

// Maximized Window
// not sure why one would want to override the max window size and position
// but it was there in the structure so I exposed it
// WC.SetMaxSize(300, 300)
// WC.SetMaxPosition(100, 100)

close_count = 1
do
	// did the user try to close the window?
    if WC.GetClose()
		
		
		// close the window or
		WC.Close(agk_hwnd)
		
		// mimic some function to check for EG: save files before closing
		message("Close attempt: "+Str(close_count))
		
		// on 3rd attempt we close the window (for test)
		if close_count = 3
			close_count=1
			WC.Close(agk_hwnd)
		endif
		
		inc close_count, 1
	endif
	
	
    Print( agk_hwnd )
    Sync()
loop