Detecting a Window Close

BlitzPlus Forums/BlitzPlus Programming/Detecting a Window Close

Grey Alien(Posted 2005) [#1]
I have made a graphics window using Graphics and flag 2 on the end so that it has a title bar. Then I have captured the window handle and added a system menu and minimise and close buttons. I chose this rather than create window because it is a game not an app.

Someone posted a win_Close function a while ago that uses bwin.dll but this only detects when the close button is clicked not when the user presses Alt+F4 or uses the system menu to close (same as Alt+F4). Also using a custom .dll to detect this seems a bit lame.

Does anyone know how to use either Blitz commands or standard windows .dlls e.g. User32 etc to detect when a system menu close option or the close button has been selected? This would be really helpful.

Thanks


Blaine(Posted 2005) [#2]
Shouldn't the program terminate automatically when you do that? Unless you want it to do something besides that...


Kevin_(Posted 2005) [#3]
There is an 'isWindow' function in User32.dll that determines whether the specified window handle identifies an existing window. Haven't tried it myself though.

If you are trying to trap or stop the user from closing the window, another alternative is to use the 'BlockInput' function in User32.dll - That blocks all keyboard and mouse events from reaching your app.

Hope that helps.


Grey Alien(Posted 2005) [#4]
Thanks, but my problem is that when the game is in windowed mode and the user presses Alt+F4 the game doesn't shut down. It also doesn't work if they click the system menu and then Close. Also to make it shut down with the X in the top right, I had to use a custom dll to detect when it was clicked.

I think this is all because I have used Graphics with flag 2 to create the window instead of CreateWindow. I expect that with CreateWindow all this behaviour is default whereas it must be manually programmed in Graphics mode. As you can't detect events in graphics mode I have to use windows dll calls.

I really need some command to tell me that the window has received a close command so that I can handle it myself by freeing up stuff and shutting down. Any ideas?


Kevin_(Posted 2005) [#5]
I think you are better off using the gadget system. Create a window with a proper canvas. That way you will still be able to 'poll' to run your game but you'll also be able to trap for events. Thats the way I would do it anyway.

[EDIT] I would create a simple menu using graphics asking the user if they wanted windowed mode or full screen. Then pass control to one of two other executables - One made in windowed mode with gadgets, and one made with the graphics statement for full screen.


Grey Alien(Posted 2005) [#6]
I was trying to avoid that as the game is done and I just need this one thing now. Can you make a decent game with CreateWindow, in that will KeyDown, KeyHit, Flip, BackBuffer and all that stuff work? I didn't think some of them did.


Kevin_(Posted 2005) [#7]
Can you make a decent game with CreateWindow, in that will KeyDown, KeyHit, Flip, BackBuffer and all that stuff work?

Why not? All the commands are there. Remember though that 'flip' now referes to a canvass buffer so just include its handle after the flip.

e.g. FlipCanvas canvashandle[,vwait]


Grey Alien(Posted 2005) [#8]
hmm, OK maybe I'll give it a try. Thanks prof.