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

大城市里の小女人 提交于 2019-12-04 07:29:56

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;
Cleber

Try this:

<Popup Name="MyPop" IsOpen="True" Height="50" Width="50">
    <!--or other control-->
    <Rectangle/> 
</Popup>


// only after MyPop.IsOpen is true
IntPtr 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!