c# Wndproc的使用方法

系统 4138 0
      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;

             }

         }


    

 

 

c# Wndproc的使用方法


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论