WndProc(ref Message m)

 
WndProc(ref Message m)

protected virtual void WndProc(
   ref Message m
);
参数 m
      与当前 Windows 消息相关联的 Message。

备注
     当窗口消息发送到窗口的句柄时,将调用此方法。对继承者的说明: 重写此方法以实现特定消息处理。对未处理的消息调用 base.WndProc。

示例
      [Visual Basic, C#, C++] 下面的示例说明了如何利用窗口过程截获操作系统窗口消息。此示例将创建一个从 NativeWindow 继承的类来完成此操作。
      [Visual Basic, C#, C++] MyNativeWindowListener 类与窗体中传递给构造函数的窗口过程挂钩,并重写 WndProc 方法来截获 WM_ACTIVATEAPP 窗口消息。此类说明了如何使用 AssignHandle 和 ReleaseHandle 方法来标识 NativeWindow 将要使用的窗口句柄。句柄根据 Control.HandleCreated 和 Control.HandleDestroyed 事件进行分配。当收到 WM_ACTIVATEAPP 窗口消息时,该类会调用 form1 ApplicationActivated 方法。 [Visual Basic, C#, C++] 这段代码摘录自 NativeWindow 类概述中显示的示例。为了简洁,一些代码没有显示。有关全部代码的列表,请参见 NativeWindow。


1// NativeWindow class to listen to operating system messages.
2public class MyNativeWindowListener: NativeWindow{
3
4    // Constant value was found in the "windows.h" header file.
5    private const int WM_ACTIVATEAPP = 0x001C;
6
7    private Form1 parent;
8
9    public MyNativeWindowListener(Form1 parent){
10
11        parent.HandleCreated += new EventHandler(this.OnHandleCreated);
12        parent.HandleDestroyed+= new EventHandler(this.OnHandleDestroyed);
13        this.parent = parent;
14    }
15
16    // Listen for the control's window creation and then hook into it.
17    internal void OnHandleCreated(object sender, EventArgs e){
18        // Window is now created, assign handle to NativeWindow.
19        AssignHandle(((Form1)sender).Handle);
20    }
21    internal void OnHandleDestroyed(object sender, EventArgs e) {
22        // Window was destroyed, release hook.
23        ReleaseHandle();
24    }
25[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
26    protected override void WndProc(ref Message m){
27        // Listen for operating system messages
28
29        switch (m.Msg){
30            case WM_ACTIVATEAPP:
31
32                // Notify the form that this message was received.
33                // Application is activated or deactivated,
34                // based upon the WParam parameter.
35                parent.ApplicationActived(((int)m.WParam != 0));
36
37                break;              
38        }
39        base.WndProc(ref m);
40    }      
41}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值