Al

Al

  • NA
  • 1
  • 0

intercepting win32 messages and using managed code

May 27 2009 2:40 AM
I have this wpf window that is supposed to retrieve the WM_HOTKEY message and perform an action once it's received. So far, I have been able to retrieve the WM_HOTKEY message from an HwndSourceHook (yes, using a method called WndProc). For example:

HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
source.AddHook(new HwndSourceHook(WndProc));

However, I am not able to perform the desired action as the method is located outside of the HwndSourceHook.

For example, consider the code

private static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam, ref bool handled)
{
            switch(msg)
            {
                case WM_DESTROY:
                    System.Console.WriteLine("\nwe were sent a WM_DESTROY\n");
                    break;
                case WM_HOTKEY:
                    switch (wparam.ToInt32())
                    {
                        case 186:
                            Console.WriteLine("\nsomething should be done here\n");
                            break;
                        case 187:
                            Console.WriteLine("\nsomething else should be done here\n");
                            break;
                    }
                    break;
            }

            return IntPtr.Zero;
}

As you can see, it is a static method, but I want to use a different method from the class. Would that be possible?


Answers (1)