Some technical things, mostly odd happenings from a remote office RSS Feed


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;
 
Posted by Ralph Arvesen | 2 Comments | Trackback Url | Bookmark with:        
Tags:

Links to this Post

Comments

Monday, 28 Dec 2009 11:59 by Kevin Rohling
Thanks Ralph! :)

Friday, 14 May 2010 07:40 by Yuri
Yes. But... IntPtr _windowHandle = new WindowInteropHelper(Application.Current.MainWindow).Handle; ALWAYS return IntPtr.Zero =)

Name:
URL:
Email:
Comments:

CAPTCHA Image Validation