Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 996
Maxim V. Pavlov Avatar asked Oct 18 '11 23:10

Maxim V. Pavlov


People also ask

How can I access a control in WPF from another class or window?

If you want to access a control on a wpf form from another assembly you have to use the modifier attribute x:FieldModifier="public" or use the method proposed by Jean. Save this answer.

What is Hwnd?

A Windows window is identified by a "window handle" ( HWND ) and is created after the CWnd object is created by a call to the Create member function of class CWnd . The window may be destroyed either by a program call or by a user's action.

How does Hwnd work?

HWND is a special HANDLE which points to a window object. HWND is said to be a pointer to a Window. To get any Window, its Child or Dialog box object, we need to use an HWND object. Communication between two windows is also done using HWND's.


2 Answers

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;
like image 113
dowhilefor Avatar answered Sep 19 '22 19:09

dowhilefor


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;
like image 34
Cleber Avatar answered Sep 19 '22 19:09

Cleber