WPF, get HWND of Window object
WPF
windows don't expose the underlying window handle (HWND) like
window-form forms (the
System.Windows.Forms.Control.Handle
property). The window handle is required in some situations
such as pinvoking, you can get the window handle of a WPF window
by using the
WindowInteropHelper
class. For example:
// get HWND of the main window, now can use
the
// window handle when pinvoking system functions
IntPtr windowHandle = new WindowInteropHelper(
Application.Current.MainWindow).Handle;