954,119 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Which Form event to use to clean up before shutting down?

I'm using Visual C++.NET. When the user clicked on the X in the upper right corner of my gui, I want to close my files and sockets before the gui terminates. Which form event would get triggered when the X is clicked? I don't know where to find the list of available Form events. In VB 6.0, Form_Terminate, Form_Unload, or Form_QueryUnload are events that may be used.

DotNetUser
Junior Poster in Training
69 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

WM_CLOSE (specifically when the X button is clicked)
WM_DESTROY (when the window is destroyed)

Example of a Dialog:

BOOL CALLBACK ExampleDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)


{[indent]switch (message){

[indent]case WM_INITDIALOG:

{[indent]// Almost like the dialogs constructor return TRUE; //Dialog will stay visible
[/indent]} 
[/indent][indent]case WM_CLOSE:  


{// Do stuff before closing the dialog[indent]EndDialog(hDlg, IDCANCEL);
break;

[/indent]}
[/indent][/indent]return FALSE;

 
}


NOTE: the EndDialog usage passes in IDCANCEL. Becuase the WM_COMMAND case is not shown in this example, most likly you would pass in a 0 or 1 instead of IDCANCEL.

BountyX
Posting Whiz in Training
230 posts since Mar 2004
Reputation Points: 28
Solved Threads: 9
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You