C#中的事件也是通过封装系统消息来实现的,如果你在WndProc函数中不处理该消息
那么,它会被交给系统来处理该消息,系统便会通过代理来实现鼠标单击的处理函数,因此你可以通过
WndProc函数来拦截消息
- protected override void WndProc(ref Message m)
- {
- const int WM_SYSCOMMAND = 0x0112;
- const int SC_CLOSE = 0xF060;
- if (m.Msg == WM_SYSCOMMAND && (int)m.WParam == SC_CLOSE)
- {
- // 屏蔽传入的消息事件
- this.WindowState = FormWindowState.Minimized;
- return;
- }
- base.WndProc(ref m);
- }
- protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
- {
- int WM_KEYDOWN = 256;
- int WM_SYSKEYDOWN = 260;
- if (msg.Msg == WM_KEYDOWN | msg.Msg == WM_SYSKEYDOWN)
- {
- switch (keyData)
- {
- case Keys.Escape:
- this.Close();
- break;
- }
- }
- return false;
- }