A window handle (usually shortened to hWnd) is a unique identifer that Windows assigns to each window created. By window in this case we are referring to everything from command buttons and textboxes, to dialog boxes and full windows.
The window handle is used in APIs as the sole method of identifying a window. It is a Long (4 byte) value and you can get the handle for forms and almost all controls in Visual Basic by using the .hWnd property.
A form's .hWnd property
For those that don't have a .hWnd property, or windows outside your application, see "How can I find a window outside my program?".
You can use the hWnd for all operations involving windows. Most of these are encapsulated by Visual Basic as methods and properties, however there are a few that aren't (and this number will only increase as Windows is updated and VB isn't) such as alpha-blending (layering), sending messages (SendMessage/PostMessage), making a window always on top, etc.
For a demonstration of many of the things you can do if you know a window's handle, check out my CWindows+CWindow classes in the Codebank, which encapsulates a lot of this functionality into two easy to use classes and shows you how to use the window-related APIs.


Reply With Quote