How to handle WndProc messages in WPF?

前端 未结 9 1101
不知归路
不知归路 2020-11-22 10:46

In Windows Forms, I\'d just override WndProc, and start handling messages as they came in.

Can someone show me an example of how to achieve the same thi

9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 11:12

    HwndSource src = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
    src.AddHook(new HwndSourceHook(WndProc));
    
    
    .......
    
    
    public IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
    {
    
      if(msg == THEMESSAGEIMLOOKINGFOR)
        {
          //Do something here
        }
    
      return IntPtr.Zero;
    }
    

提交回复
热议问题