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

99封情书 提交于 2019-12-06 03:30:40

问题


I need to apply an Aero background blur to only part of a custom-shaped WPF window. The problem is that to apply the blur with DWM, I need to provide a window handle to the DwmEnableBlurBehindWindow function.

I have been told that the WPF popup control is actually a separate window. That is good. Can I get a popup's handle to apply blur to it? If so, how?


回答1:


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;



回答2:


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;



回答3:


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.



来源:https://stackoverflow.com/questions/7815121/is-it-possible-to-get-the-hwnd-of-a-wpf-popup-control

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