System command menu

  • Thread starter Thread starter Mr.Tickle
  • Start date Start date
Hi,

Override WndProc on the form. Here is a VB.Net example.

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)

Const WM_SYSCOMMAND = &H112

Const SC_CLOSE = &HF060&

If m.Msg = WM_SYSCOMMAND Then

' Do something

ElseIf m.Msg = SC_CLOSE Then

' Do something else

End If

' Need to call the mybase.wndproc or the app wont work

MyBase.WndProc(m)

End Sub

Ken
 
I find it stupid that the Form doesnt have an event for the system menu
while win32 has, to me this is a loss of functionality.
 
in win32 its

case WM_SYSCOMMAND:
{
if (LOWORD(wParam) == SC_CLOSE)
{
// handle close here
}
break;
}


so how come m.Msg has SC_CLOSE? that looks odd, shoudlnt it be in m.WParam
?
 
// found it..

I dono why MS cant provide us with the message constants, forcing us to
redefine them is just asking for problems. I always hated that about VB6.

I just see it as lazyness on theyre part.


protected override void WndProc(ref System.Windows.Forms.Message m)
{
const int WM_SYSCOMMAND = 0x112;
const int SC_CLOSE = 0xf060;


if (m.Msg == WM_SYSCOMMAND)
{
if (m.WParam.ToInt32() == SC_CLOSE)
{
return;
}
}
base.WndProc(ref m);
}
 
Back
Top