Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Before exit execute..

Author
Message
Michael P
18
Years of Service
User Offline
Joined: 6th Mar 2006
Location: London (UK)
Posted: 24th Jun 2008 15:12
How can I get the program to execute a function right before exiting. So, when the user clicks on the red X, the program executes a function and then exits. I know of 'atexit' but this only works when the return command is executed, not if the user clicks on the red X.
programing maniac
16
Years of Service
User Offline
Joined: 19th Apr 2008
Location: Bawk, Bawkity
Posted: 24th Jun 2008 16:04
well, I think you would want something like-

if ( redX == 1)
{
DoSomething;
return;
}

I am not sure if return is the function that closes the window, it might be something like exit, I am not sure.....

Really you just have to have it so that if a key is pressed, do something, and then right after, exit.

Hopefully this was helpful!


www.GlobalWarfare.tk
dbGamerX
16
Years of Service
User Offline
Joined: 23rd Nov 2007
Location:
Posted: 25th Jun 2008 05:10
You may want to have a look at: http://msdn.microsoft.com/en-us/library/system.windows.window.closing.aspx

Downside is that it uses the .NET framework, so you will need to distribute that with your game.

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 25th Jun 2008 05:12
I'm sure there is a way to do it without .NET. I know I've used many programs that open a message box on the click of the "X".
Codger
21
Years of Service
User Offline
Joined: 23rd Nov 2002
Location:
Posted: 25th Jun 2008 05:44
It maybe cheating but if you put up a window without the system controls or a real red x, make a sprite that fakes being the red x and or the title bar you could then use a mouse press as a signal to run your function prior to the exit

System
MacBook Pro
Windows XP Home on Boot Camp
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 25th Jun 2008 05:45
Vista UI vs. XP. Keep that in mind.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 25th Jun 2008 05:46 Edited at: 25th Jun 2008 05:47
I do remember reading that the window object isn't destroyed with the window. It is destroyed afterward. There should be a way to use that time for your function.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 25th Jun 2008 08:04
Would it be sufficient to remove the ability for the program to exit by that manner and restrict it to key presses or other programmatic means?

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 25th Jun 2008 08:09
Possibly. I would recommend MSDN. Their library might tell. I'd look it up now, but I'm busy with my own coding.
dbGamerX
16
Years of Service
User Offline
Joined: 23rd Nov 2007
Location:
Posted: 25th Jun 2008 14:38
If your game is going to be full-screen, I don't see the need to have a window border and controls set up. You can remove them by turning off the sizable controls property of the window border. Then again, I only know how to do this with the .NET framework.

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 25th Jun 2008 18:55
You'd have to get into the core GDK functions and calls to the API, I'm sure.
SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 28th Jun 2008 20:38 Edited at: 28th Jun 2008 23:29
There's a fairly easy way to accomplish this, actually. If you create a new window, Windows API style, the GDK doesn't respond properly, and the new window is controlled with the old window's frame. When the X is hit, the new window is sent WM_DESTROY and closes, doing apparently nothing to the window, but creating an event you can then use to do whatever you want, then close the GDK window with a return. I'll make an example if I have time later.

EDIT:
I worked it out a bit, and the window double-draw method works, but not exactly correctly. The GDK catches the new window's closing and prevents it from handling the message WM_DESTROY on its own. To see what I mean, I've got a quick code snippet.



If you compile and run that, the message box is never made, and therefore BeforeExit(); doesn't get called, like it should according to the switch that handles the second window's messages.

Sorry, this method isn't going to work. However, I've heard of some people catching windows messages with the GDK, perhaps you'd be able to do that instead?


My site, for various stuff that I make.
Michael P
18
Years of Service
User Offline
Joined: 6th Mar 2006
Location: London (UK)
Posted: 21st Jul 2008 16:44
After meditating for a few weeks I came up with a solution. Using a class and its destructor I can essentially say 'before exit.. do this'. Although some commands don't work (like cout for example), this is still a good way of performing some last second operations. Here is some code to demonstrate how this is done (before exiting a beep sound should be played from your computer's in built speaker):

Login to post a reply

Server time is: 2024-11-20 17:28:58
Your offset time is: 2024-11-20 17:28:58