NativeWindow WndProc not receiving messages

Posted by BadNinja on Stack Overflow See other posts from Stack Overflow or by BadNinja
Published on 2010-05-24T05:19:08Z Indexed on 2010/05/24 5:20 UTC
Read the original article Hit count: 502

Filed under:
|
|

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.)

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

© Stack Overflow or respective owner

Related posts about c#

Related posts about handle