c#中通过截获windows消息禁止改变窗体大小
?private const int WM_SYSCOMMAND = 0x112;
? ? ? ? private const int MF_REMOVE = 0x1000;
? ? ? ? private const int SC_RESTORE = 0xF120; ? ? //還原 ??
? ? ? ? private const int SC_MOVE = 0xF010; ? //移動 ??
? ? ? ? private const int SC_SIZE = 0xF000; ? //大小 ??
? ? ? ? private const int SC_SIZEChange = 0xF002; ? //大小 ??
? ? ? ? private const int SC_MINIMIZE = 0xF020; ? //最小化 ??
? ? ? ? private const int SC_MAXIMIZE = 0xF030; ? //最大化 ??
? ? ? ? private const int SC_CLOSE = 0xF060; ? //關閉 ? ??
? ? ? ? [DllImport("USER32.DLL")]
? ? ? ? public static extern int GetSystemMenu(int hwnd, int bRevert);
? ? ? ? [DllImport("USER32.DLL")]
? ? ? ? public static extern int RemoveMenu(int hMenu, int nPosition, int wFlags);
? ? ? ? private void SetCloseMenu()
? ? ? ? {
? ? ? ? ? ? int hMenu = GetSystemMenu(this.Handle.ToInt32(), 0);//移除關閉按鈕
? ? ? ? ? ? RemoveMenu(hMenu, SC_CLOSE, MF_REMOVE);
? ? ? ? }
?
protected override void WndProc(ref Message m)
? ? ? ? {
? ? ? ? ? ? switch (m.Msg)
? ? ? ? ? ? {
? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? case WM_SYSCOMMAND:
? ? ? ? ? ? ? ? ? ? switch (m.WParam.ToInt32())
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? case SC_MINIMIZE:
? ? ? ? ? ? ? ? ? ? ? ? ? ? base.WndProc(ref m);
? ? ? ? ? ? ? ? ? ? ? ? ? ? //捕獲最小化消息
? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? case SC_RESTORE:
? ? ? ? ? ? ? ? ? ? ? ? ? ? base.WndProc(ref m);
? ? ? ? ? ? ? ? ? ? ? ? ? ? //捕獲還原消息
? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? case SC_MAXIMIZE:
? ? ? ? ? ? ? ? ? ? ? ? ? ? this.Width = this.panel1.Width + this.textBox_Receiv.Width + 100;
? ? ? ? ? ? ? ? ? ? ? ? ? ? this.Height = this.panel1.Height * 20;
? ? ? ? ? ? ? ? ? ? ? ? ? ? //base.WndProc(ref m);
? ? ? ? ? ? ? ? ? ? ? ? ? ? //捕獲最大化消息
? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? case SC_SIZEChange:
? ? ? ? ? ? ? ? ? ? ? ? ? ? this.Width = this.panel1.Width + this.textBox_Receiv.Width + 100;
? ? ? ? ? ? ? ? ? ? ? ? ? ? this.Height = this.panel1.Height * 20;
? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? case 61443:
? ? ? ? ? ? ? ? ? ? ? ? ? ? this.Width = this.panel1.Width + this.textBox_Receiv.Width + 100;
? ? ? ? ? ? ? ? ? ? ? ? ? ? this.Height = this.panel1.Height * 20;
? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? case 61446:
? ? ? ? ? ? ? ? ? ? ? ? ? ? this.Width = this.panel1.Width + this.textBox_Receiv.Width + 100;
? ? ? ? ? ? ? ? ? ? ? ? ? ? this.Height = this.panel1.Height * 20;
? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? case 61441:
? ? ? ? ? ? ? ? ? ? ? ? ? ? this.Width = this.panel1.Width + this.textBox_Receiv.Width + 100;
? ? ? ? ? ? ? ? ? ? ? ? ? ? this.Height = this.panel1.Height * 20;
? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? default:
? ? ? ? ? ? ? ? ? ? ? ? ? ? base.WndProc(ref m);
? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? default:
? ? ? ? ? ? ? ? ? ? base.WndProc(ref m);
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? }
總結
以上是生活随笔為你收集整理的c#中通过截获windows消息禁止改变窗体大小的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 解决:com.mysql.jdbc.My
- 下一篇: C#中Monitor和Lock的用法区别