Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF equivalent of Application.AddMessageFilter (Windows Forms)

I was using Application.AddMessageFilter() in my WinForms applications (when working with unmanaged code).

Now I'm switching to WPF and can't find this functionality.

Please advice where it can be found or implemented.

like image 766
Valentin V Avatar asked Jan 26 '09 07:01

Valentin V


People also ask

Is it possible to use Windows Forms in a WPF application?

A Windows Forms control that can be used to host a Windows Presentation Foundation (WPF) element.

Should I use WPF or Windows Forms?

WPF can be used to develop and design both Windows applications and web applications while WinForms can only be used to develop and design Windows applications. XAML (Extensible Application Markup Language) is used by WPF to define the user interface of a WPF application.


1 Answers

In WPF, you can use ComponentDispatcher.ThreadFilterMessage event.

ComponentDispatcher.ThreadFilterMessage += ComponentDispatcher_ThreadFilterMessage;
private void ComponentDispatcher_ThreadFilterMessage(ref MSG msg, ref bool handled)
{
     if (msg.message == 513)//MOUSE_LEFTBUTTON_DOWN
     {
         //todo
     }
}
like image 164
Jim Avatar answered Sep 17 '22 13:09

Jim