HwndSource.AddHook(HwndSourceHook) Method can add event handler that receives all window messages, is it what you want? If it is, you can use it like below.
public MainWindow()
{
InitializeComponent();
//SourceInitialized += WSInitialized;
SourceInitialized += HandleInitialized;
}
public void HandleInitialized(object o, EventArgs e)
{
IntPtr wptr = new WindowInteropHelper(this).Handle;
HwndSource hs = HwndSource.FromHwnd(wptr);
hs.AddHook(new HwndSourceHook(WpfHandleWinowMsg));
}
public IntPtr WpfHandleWinowMsg(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
switch (msg)
{
case 1:
break;
case 2:
break;
default:
break;
}
return IntPtr.Zero;
}
By the way, if I misunderstand, please point out.
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.