拦截窗体关闭、最大、最小事件 - Winform

RT,不赘述,代码以下:

 1 const int WM_SYSCOMMAND = 0x112;
 2 const int SC_CLOSE = 0xF060;
 3 const int SC_MINIMIZE = 0xF020;
 4 const int SC_MAXIMIZE = 0xF030;
 5 protected override void WndProc(ref Message m)
 6 {
 7     if (m.Msg == WM_SYSCOMMAND)
 8     {
 9         if (m.WParam.ToInt32() == SC_MINIMIZE)  
10         {
11 
12             //......
13         }
14 
15 
16         if (m.WParam.ToInt32() == SC_MAXIMIZE ) 
17 
18         { 
19 
20              //.....................
21 
22         }
23 
24         
25 
26         if (m.WParam.ToInt32() == SC_CLOSE ) 
27 
28         {   
29             //.....................
30         }
31 
32 
33     }
34     base.WndProc(ref m);
35 }        

 

posted @ 2013-08-08 09:27  Thyiad  阅读(241)  评论(0编辑  收藏  举报