c# Wndproc的使用方法

来源:互联网 发布:java大学简明教程 编辑:程序博客网 时间:2024/05/12 16:57
c# Wndproc的使用方法
?
1
2
3
4
5
6
7
8
9
10
11
12
protectedoverride voidWndProc(refMessage m)
{
    constint WM_SYSCOMMAND = 0x0112;
    constint SC_CLOSE = 0xF060;
    if(m.Msg == WM_SYSCOMMAND && (int) m.WParam == SC_CLOSE)
    {
        // 屏蔽传入的消息事件
        this.WindowState = FormWindowState.Minimized;
        return;
     }
    base.WndProc(refm);
}

  

?
1
2
3
4
5
6
7
8
9
10
11
12
13
protectedoverride voidWndProc(ref   Message m)
        {
            constint WM_SYSCOMMAND = 0x0112;
            constint SC_CLOSE = 0xF060;
            constint 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函数来同时实现无标题栏的窗体移动和禁止双击窗体最大化

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
protectedoverride voidWndProc(refMessage m)
         {
             constint WM_NCHITTEST = 0x84;
             constint HTCLIENT = 0x01;
             constint HTCAPTION = 0x02;
             constint WM_SYSCOMMAND = 0x112;
             constint SC_MAXMIZE = 0xF030;
             constint WM_NCLBUTTONDBLCLK = 0xA3;
             switch(m.Msg)
             {
                 case0x4e:
                 case0xd:
                 case0xe:
                 case0x14:
                     base.WndProc(refm);
                     break;
                 caseWM_NCHITTEST://鼠标点任意位置后可以拖动窗体
                      
                    this.DefWndProc(refm);
                     if(m.Result.ToInt32() == HTCLIENT)
                     {
                         m.Result =new IntPtr(HTCAPTION);
                         return;
                     }
                     break;
                 caseWM_NCLBUTTONDBLCLK://禁止双击最大化
                     Console.WriteLine(this.WindowState);
                      
                        return;
  
                    
                    break;
  
                default:
                      
                    base.WndProc(refm);
                     break;
             }
         }

 

  

 

好文要顶关注我 收藏该文
拼博之路
关注 - 0
粉丝 - 6
+加关注
0
0
«上一篇:NET异常 在 getsockopt 或 setsockopt 调用中指定的一个未知的、无效的或不受支持的选项或层次。
»下一篇:Access使用参数化UPDATE数据时,数据无法更新的问题
posted on 2014-08-13 11:50 拼博之路 阅读(7747) 评论(0)编辑 收藏


0 0
原创粉丝点击