Is it possible to get the Hwnd of a WPF Popup control? Is it possible to get the Hwnd of a WPF Popup control? wpf wpf

Is it possible to get the Hwnd of a WPF Popup control?


Try this

HwndSource source = (HwndSource)HwndSource.FromVisual(myPopup)

or this but this one only works for actual Windows, but might help for future references.

IntPtr handle = new WindowInteropHelper(myWindow).Handle;


Try this:

<Popup Name="MyPop" IsOpen="True" Height="50" Width="50">    <!--or other control-->    <Rectangle/> </Popup>// only after MyPop.IsOpen is trueIntPtr handle =  ((HwndSource)PresentationSource.FromVisual(MyPop.Child)).Handle;


Does it have a custom class name? If so, you can Find the window handle via class name (FindWindow).

I'm a bit of a hacker-type when it comes to this stuff in Windows, so that's what I usually try first, rather than trying to discover a "proper" method. All old stuff for me, though, I don't do much of this anymore - see blackbeltvb.com

Two other ways I've done this is 1) to hook the windows creation messages, watch for that pop up window, then do something to it (SetWindowsHookEx) and 2) enumerate all the window handles being used, then watch for the new one.