拦截窗体关闭、最大、最小事件 - 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 }