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