What message is called when the X in the upper right of a dialog is closed
-
I need to do some cleanup when my dialog closes. I tried overriding mydialog.Close() doing the cleanup there and then calling base.Close(). When the user exits it using the close button everything works as intended, but the X doesn't call Close() and leaves my app in a messedup state.
-
I need to do some cleanup when my dialog closes. I tried overriding mydialog.Close() doing the cleanup there and then calling base.Close(). When the user exits it using the close button everything works as intended, but the X doesn't call Close() and leaves my app in a messedup state.
The Windows recive
WM_SYSCOMMAND
Notification when you close minimize or maximize the window or you choose any command from the system menu So overrid your formWndProc
function and handle itconst int WM_SYSCOMMAND = 0x0112; const int SC_CLOSE = 0xF060;
protected override void WndProc(ref Message m)
{
if(m.Msg==WM_SYSCOMMAND)
{
if(m.WParam.ToInt32()==SC_CLOSE)
{
MessageBox.Show("Application will be close");
// call the default after you handle it
base.WndProc(ref m);
}
}
else
{
base.WndProc (ref m);
}
}if you don not handle other Message you can write it like
protected override void WndProc(ref Message m)
{
if(m.Msg==WM_SYSCOMMAND)
{
if(m.WParam.ToInt32()==SC_CLOSE)
{
MessageBox.Show("Application will be close");
}} base.WndProc (ref m);
}
for more information look at WM_SYSCOMMAND Notification[^] MCAD -- modified at 18:53 Friday 23rd September, 2005
-
I need to do some cleanup when my dialog closes. I tried overriding mydialog.Close() doing the cleanup there and then calling base.Close(). When the user exits it using the close button everything works as intended, but the X doesn't call Close() and leaves my app in a messedup state.
You should handle the
Closing
event ofSystem.Windows.Forms.Form
. This event is fired regardless of whether the dialog was closed via the system menu or a close button on your form. Regards, mav -
You should handle the
Closing
event ofSystem.Windows.Forms.Form
. This event is fired regardless of whether the dialog was closed via the system menu or a close button on your form. Regards, mav