开发者

NativeWindow WndProc not receiving messages

Could someone shed some light on why my WndProc method as implemented below isn't receiving any messages? If I put this class below in a WinForms application and pass in that application's handle, WndProc receives messages as I would expect. However, using the IntPtr returned from GetForegroundWindow() as I have below doesn't yield the same results. (FWIW, I have my code set up to execute GetForegroundWindow() when my application is hidden, so I'm certain that the IntPtr is referring to an outside application.) My goal here is to monitor certain events from outside applications.

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


You won't recieve Messages of another process.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜