c# Wndproc的使用方法

來源:互聯網
上載者:User

標籤:style   blog   使用   os   io   strong   for   ar   

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 void WndProc(ref    Message m)          {              const int WM_SYSCOMMAND = 0x0112;              const int SC_CLOSE = 0xF060;              const int SC_MINIMIZE = 0xF020;              if (m.Msg == WM_SYSCOMMAND && ((int)m.WParam == SC_MINIMIZE || (int)m.WParam == SC_CLOSE))              {                  //最小化到系統欄                  this.Hide();                  return;              }              base.WndProc(ref    m);          } 

重寫 WndProc函數來同時實現無標題列的表單移動和禁止雙擊表單最大化

 

protected override void WndProc(ref Message m)         {             const int WM_NCHITTEST = 0x84;             const int HTCLIENT = 0x01;             const int HTCAPTION = 0x02;             const int WM_SYSCOMMAND = 0x112;             const int SC_MAXMIZE = 0xF030;             const int WM_NCLBUTTONDBLCLK = 0xA3;             switch (m.Msg)             {                 case 0x4e:                 case 0xd:                 case 0xe:                 case 0x14:                     base.WndProc(ref m);                     break;                 case WM_NCHITTEST://滑鼠點任意位置後可以拖動表單                                         this.DefWndProc(ref m);                     if (m.Result.ToInt32() == HTCLIENT)                     {                         m.Result = new IntPtr(HTCAPTION);                         return;                     }                     break;                 case WM_NCLBUTTONDBLCLK://禁止雙擊最大化                     Console.WriteLine(this.WindowState);                                             return;                                        break;                 default:                                         base.WndProc(ref m);                     break;             }         }

 

  

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.