0

In my wpf project, i am hosting a win 32 window with listbox control. In this, is it possible to get that Win 32 window in Message Hook event handler?

var view = new Win32Host(source.Handle, mViewMgr);
view.MessageHook += View_MessageHook;
IntPtr View_MessageHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
    handled = false;
}

Any one please provide your suggestion to me?

Muthalagu
  • 156
  • 1
  • 16

1 Answers1

0

I'm not sure what Win32Host is but if you have an HWND you may be able to get some associated object. It really depends on the class. So for example if the HWND is for a Windows Forms control then you can use the System.Windows.Forms.Control.FromHandle or FromChildHandle method. If the HWND was the window hosting WPF content then you would use HwndSource.FromHwnd and get the RootVisual from that to get the root element (e.g. a WPF Window or the root element of a Popup).

AndrewS
  • 6,054
  • 24
  • 31
  • Andrew-Here Win32Host is a HWND Host and i host that Win32Host as child to my wpf control. Here i want that Win32Host in MessageHook event. – Muthalagu Jun 13 '13 at 04:57
  • Then no there is no automatic way to do that. Why not just keep a Dictionary where the key is the Hwnd and the value is a weak reference to the Win32Host? If Win32Host is your own derived HwndHost then you could have it do that storage. Or perhaps more simply create a class that stores a reference to the Win32Host and it hooks the MessageHook event. – AndrewS Jun 13 '13 at 15:30