[RESOLVED] Windows Messages in WPF
I have a WPF app that I want to be able to handle certain Windows Messages that other apps send to it. In Windows Forms, I could overload the OnNotifyMessage method in my form and handle arbitrary messages there. How do I do this in WPF? All I know about the messages are the message ids (e.g., unsigned int WM_MyMessage = 0x8001).
Eric
Re: Windows Messages in WPF
After a bit more searching, I've found a solution:
// Handler must be added once the window is loaded
void Main_Loaded(object sender, RoutedEventArgs e)
{
HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
source.AddHook(new HwndSourceHook(WndProc));
}
private static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
// Handle messages here
return IntPtr.Zero;
}
The solution was originally found here: http://social.msdn.microsoft.com/For...-cb7cdb27bd83/
Eric