This is a mirror of official site: http://jasper-net.blogspot.com/

Win32 Handle (HWND) & WPF Objects - A Note

| Monday, December 6, 2010
Well, there is a common confusion for many who are working with WPF objects, is does it truly interoperable with Windows environment, or more precisely, does it act the same way as it does with normal Win32 objects?
The problem here comes with the fact that each WPF window has only one window handle (HWND) and each other controls are actually placed as content to the window and does not have any entry on Kernel table(no HWND) except of course Popup class in WPF. In this post I will try to cover the basis of HWND (for those of you who don't know) and later go on with what are the changes of it with WPF environment.

If you know what HWND is or how it works, please skip the next section.

Overview of Win32 HANDLE

Win32 Handle is very important for any Win32 applications. For every Win32 apps, Kernel maintains a Table which has entries to identify a memory address. A HANDLE is actually a DWORD (32 bit integer) which maps the memory address on the table. So if you get a HANDLE, you can easily locate the memory address it points to.  Each object that you have in Windows (like windows, buttons, mouse pointers, icon, menu, bitmap etc) has entries in the table and the object is traced using both internally by windows or by programs using those HANDLEs. Even though it is just an unsigned integer value, you should not edit the value, otherwise the HANDLE could not be used to point the object anymore.

Based on the Type of HANDLE can be categorized into HWND, HINSTANCE, HMENU.

HWND

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.

HINSTANCE

HINSTANCE is a special HANDLE which points to a program instance. Kernel keeps a HANDLE to the instance of the program so that later on the program could be communicated from outside.

HMENU

For every dropdown menu,  a HMENU handle will be associated with it. HMENU handle is used to alter content of the dropdown menu item.

WPF Objects and HWND

WPF objects are not HWND based. Then how does you it communicate with window handle ? Yes this question come into mind of every programmer who starts working with WPF after having considerable amount of exposure in Windows environment.

Read more: DOT NET TRICKS

Posted via email from .NET Info

0 comments: