CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2009
    Posts
    5

    [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

  2. #2
    Join Date
    Mar 2009
    Posts
    5

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured