How to detect maximize button press in a window

BlitzMax Forums/MaxGUI Module/How to detect maximize button press in a window

codermax(Posted 2012) [#1]
I wanna thank those who helped me out recently! That EVENT_GADGETACTION stuff was making me angry. :D

After that, I was trying to find out if a user pressed the maximize button in a window. I needed to detect this, to scale the window's contents properly. I was planning on nixing the maximize button, but my app would look unprofessional if it didn't have the basic maximize button like all modern Microsoft windows do. EVENT_WINDOWSIZE would capture slight resizing on the window's borders, but NOT the maximize button at the top of a window! Why? I have no idea.

However, I just found a way to detect if a user JUST pressed the maximize button in a window.

The benefits: If you constantly draw to the window, your contents will flicker. Using some kind of mechanism like the one below, It keeps your window's content from flickering so freaking much! Also, any code you wish to be dependent on the maximize button will work properly.

In your main file...


Typical SuperStrict code, with all the proper declarations! I know there's a MaxGUI function, but I used the win32 function to check maximized states because I didn't know of any other functions to sub at the time. That's the minimal data you will need though.

So what's going on?

1. First, you declare all the proper data, and then grab the window handle as soon as you create a MaxGUI window.

2. In your main loop, you check for whether or not the window is maximized. You have two conditions for that. If the window is NOT maximized, the non_maximized counter will grow and zero out the maximized counter. Vice versa for the other maximized condition, THAT variable will grow and non_maximized will be zeroed out.

3. Here's the kicker - if EITHER counter is low but higher than 0(between 1 and 3), that means the user JUST pressed the maximize button! When that happens, the just_draw counter will get a small value. The condition that has the drawing code will get a couple repeats before the condition counts down just_draw and just_draw becomes 0, in which case drawing will not occur. 2-3 repeat draws is enough to refresh any window contents without flicker.

Also, when you maximize a window and then restore it, you may notice black rectangles on your labels or other such gadgets. This can be fixed by setting the problem gadget's color to anything lighter than black. The glitch WILL NOT OCCUR on the gadget anymore, leaving the user of your app none the wiser!

I just wanted to share all this, as I've not seen such a post anywhere here(believe me, I've tried!), but I've seen A LOT of of posts trying to find out how to use the maximize button to their advantage and get rid of those black rects. I didn't see such answers on the board.

Last edited 2012


Midimaster(Posted 2012) [#2]
Do you know there is a MaxGui event EVENT_WINDOWSIZE? It is working in my programs, when I maximize the window. And the Window has a MaxGui property WindowMaximized( window), which you can check!

Last edited 2012


codermax(Posted 2012) [#3]
Hi Midimaster. I have stated this already :)
" I know there's a MaxGUI function, but I used the win32 function to check maximized states because I didn't know of any other functions to sub at the time. "
Also thanks to the other users on the forums, I've learned never to use the variable extraction fucntions in BlitzMax, haha!

However, you can use any mechanism you want to detect the maximization of a window. I used this function, because for me EVENT_WINDOWSIZE doesn't work. And I did check all my events, now that I've sorted out EVENT_GADGETACTION, stupid thing. :)

I might have to update my current version. But regardless, if it works for you that's great. But I tend to work out problems on my own, since I happened to come across a lot of stuff using MaxGUI which I don't like and I search the forums a lot looking for solutions. But I don't wanna have to pay for GUI enhancements if I don't need to, hence my code. But hopefully no one will actually need it. :)