有人能解释一下为什么下面实现的WndProc方法没有收到任何消息吗?如果我将这个类放在WinForms应用程序下面,并传入该应用程序的句柄,WndProc就会像我所期望的那样接收消息。但是,像下面这样使用从IntPtr返回的GetForegroundWindow()并不会产生相同的结果。(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);
}
}发布于 2010-05-24 05:21:00
您将不会收到另一个进程的消息。
https://stackoverflow.com/questions/2894876
复制相似问题