Dave's Brain

Browse - programming tips - cleanly end a windows program

Date: 2009may4
Platform: win32

Q.  How can I cleanly end my Windows program?

A.  There are lots of ways to do it.  The usual way is for the
user to click on [X] to close the main window of your program.

You can simulate this by doing:

	PostMessage(WM_CLOSE);

If your program is dialog based, this will do nearly the same thing:

	EndDialog(IDCANCEL);	- simulates clicking on [Cancel]

	or

	EndDialog(IDOK);	- simulates clicking on [OK]

Less elegantly you can post a quit message:

	PostQuitMessage(int nExitCode);

	An nExitCode of 0 (zero) means success and non-zero doesn't

If you want to rudely end your app use either of these:

	TerminateProcess(HANDLE hProcess, int nExitCode);

	exit(int nExitCode);
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2010, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.