const int WM_SYSCOMMAND = 0x112;
//窗体关闭消息
const int SC_CLOSE = 0xf060;
//窗体最小化消息
const int SC_MINIMIZE = 0xf020;
//窗体最大化消息
const int SC_MAXIMIZE = 0xf030;
//窗体还原消息
const int SC_NOMAL = 0xf120;
//窗体还原消息
const int SC_RESTORE = 61728;
//窗体按钮的拦截函数
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_SYSCOMMAND)
{
//If m.WParam.ToInt32() = SC_RESTORE Then
// '拦截还原按钮
// Exit Sub
//End If
if (m.WParam.ToInt32() == SC_NOMAL)
{
//拦截还原按钮
return;
}
//if (m.WParam.ToInt32() == SC_MINIMIZE)
//{
// //拦截最小化按钮
// //这里写操作代码
// return;
//}
if (m.WParam.ToInt32() == SC_MAXIMIZE)
{
//拦截窗体最大化按钮
//.....................
return;
}
//窗体关闭消息
if (m.WParam.ToInt32() == SC_CLOSE)
{
if (MessageBox.Show("您确认要退出吗?", "", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
System.Environment.Exit(System.Environment.ExitCode);
}
else
{
return;
}
}
}
base.WndProc(ref m);
}
}