detecting 'x' systembox close on MDIChild

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I'd like to detect the 'x' systembox close on a MDIChild. The formClosing
event, ClosingReason just says 'UserClosing' and doesn't differentiate the
'x' close.

I have some code I used in the past. This works for modal and as I recall
worked for modeless. But it doesn't work when the window is a MDIChild.
Code is below.

Any suggestions?
jeff

private const int WM_SYSCOMMAND = 0x112;

private const int SC_CLOSE = 0xf060;

private const int WM_MDIACTIVATE = 0x222;

protected override void WndProc(ref Message m)

{

if ((((m.Msg == WM_SYSCOMMAND) && (m.WParam.ToInt32() == SC_CLOSE)) ? 1 : 0)
!= 0)

{

Debug.WriteLine("X Detected - Modal");

}


Debug.WriteLine(String.Format("msg:{0}
wparam:{1}",m.Msg,m.WParam.ToInt32()));

base.WndProc(ref m);

}


.