2

有人可以解释一下为什么我WndProc下面实现的方法没有收到任何消息吗?如果我把这个类放在下面的 WinForms 应用程序中并传入应用程序的句柄,WndProc则会按预期接收消息。但是,使用下面返回的 IntPtrGetForegroundWindow()不会产生相同的结果。(FWIW,我的代码设置为GetForegroundWindow()在我的应用程序隐藏时执行,所以我确定 IntPtr 指的是外部应用程序。)我的目标是监视来自外部应用程序的某些事件。

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);
    }
}
4

1 回答 1

3

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

于 2010-05-24T05:21:00.240 回答