Is it possible to get the Hwnd of a WPF Popup cont

2019-04-09 02:00发布

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?

3条回答
放荡不羁爱自由
2楼-- · 2019-04-09 02:16

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;
查看更多
时光不老,我们不散
3楼-- · 2019-04-09 02:30

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.

查看更多
SAY GOODBYE
4楼-- · 2019-04-09 02:35

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;
查看更多
登录 后发表回答