[MaxGUI] Setting the maximum window size

BlitzMax Forums/BlitzMax Beginners Area/[MaxGUI] Setting the maximum window size

kenshin(Posted 2006) [#1]
You can use SetMinWindowSize() to set the minimum size on a resizable window. Is there a way to set the maximum window size?


Grisu(Posted 2006) [#2]
None I know of.

But you could use "Setgadgetshape" to resize the window down each time the user tries to maximise it... :)


kenshin(Posted 2006) [#3]
Thanks Grisu. That works.

I found this anomaly in maxgui.bmx:
Rem
bbdoc: Set a window gadget's minimum size.
endrem
Function SetMinWindowSize( window:TGadget,w,h )
	window.SetMinimumSize( w,h )
End Function

Rem
bbdoc: Set a window gadget's maximum size.
endrem
Function MinimizeWindow( window:TGadget )
	window.Activate ACTIVATE_MINIMIZE
End Function

Looks like a SetMaxWindowSize() function was supposed to be put there.


ImaginaryHuman(Posted 2006) [#4]
Rather than wait for the window to be sized and then lock it back to the size you want, it would be better to use an event hook on the resize gadget so as soon as they click it, you force the window not to be bigger than a given size. Hopefully it would be fast enough that they wouldn't be able to resize the window past a couple pixels.


kenshin(Posted 2006) [#5]
@AngelDaniel : I tried your method but I don't think I can hook while the window is being resized. I tried a hook that's based on a timer. If you try and resize the window you'll see what I mean.

Const TICK_EVENT:Int=69
Function MyHook:Object( id:Int,data:Object,context:Object )
	Local ev:TEvent=TEvent(data)
	Select ev.id
		Case EVENT_WINDOWCLOSE
			End
		Case TICK_EVENT
			SetGadgetShape win,0,0,640,480 
	End Select
	Return Data
End Function
Local MY_EVENT:TEvent=CreateEvent(TICK_EVENT)
Local myTimer:TTImer = CreateTimer(10,MY_EVENT)
AddHook EmitEventHook,MyHook
Global win:TGadget
win=CreateWindow( "A window!",0,0,640,480, Null, WINDOW_TITLEBAR | WINDOW_RESIZABLE )
Global Canvas:Tgadget=CreateCanvas(0,0,640,480,Win)
While True
	WaitEvent
Wend

It's certainly doing it quickly enough, but unfortunately it only does it after the resize has been completed.

Any other ideas?


assari(Posted 2006) [#6]
Try something like this
Function MyHook:Object( id:Int,data:Object,context:Object )
	Local ev:TEvent=TEvent(data)
	If ev.source=Win And ev.id=EVENT_WINDOWSIZE
		SetGadgetShape win,0,0,640,480
	End If
	Return Data
End Function


Global win:TGadget
win=CreateWindow( "A window!",0,0,640,480, Null, WINDOW_TITLEBAR | WINDOW_RESIZABLE )

AddHook EmitEventHook,MyHook
While True
	WaitEvent
Wend

To handle the canvas (which I have taken out to make the program simpler) you have to trap an EVENT_GADGETPAINT as well.

See my tutorial to understand how eventhook works.


kenshin(Posted 2006) [#7]
Thanks assari. I'll stash a copy of your tutorial as I don't fully understand the EventHooks yet.

I've thought of a way to make this resize limiting better which may work. I'll have to leave it till tomorrow though...