首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NativeWindow WndProc未接收消息

NativeWindow WndProc未接收消息
EN

Stack Overflow用户
提问于 2010-05-24 05:19:08
回答 1查看 2K关注 0票数 2

有人能解释一下为什么下面实现的WndProc方法没有收到任何消息吗?如果我将这个类放在WinForms应用程序下面,并传入该应用程序的句柄,WndProc就会像我所期望的那样接收消息。但是,像下面这样使用从IntPtr返回的GetForegroundWindow()并不会产生相同的结果。(FWIW,我的代码设置为在隐藏应用程序时执行GetForegroundWindow(),因此我确信IntPtr是指外部应用程序。)我在这里的目标是监视外部应用程序中的某些事件。

代码语言:javascript
复制
public class MyNativeWindow : NativeWindow
{
    [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
    private static extern IntPtr GetForegroundWindow();

    public MyNativeWindow()
    {
        this.AssignHandle(GetForegroundWindow());
    }

    // Never called... I set a breakpoint
    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
    protected override void WndProc(ref Message m)
    {
        base.WndProc(ref m);
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-05-24 05:21:00

您将不会收到另一个进程的消息。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2894876

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档