Article ID: 242308 - Last Review: July 16, 2004 - Revision: 2.2 How To Find a Window Handle from an Instance HandleThis article was previously published under Q242308 On This PageSUMMARY
The Shell function in Microsoft Visual Basic is used to execute an application. Often, it is useful to get a Window handle (hWnd) to the application so you can manipulate it using the Windows APIs. However, the Shell function returns an Instance handle (hInstance), which is different from a Window handle. This article shows how to create and use a GetWinHandle() function to return a Window handle based on an Instance handle.
MORE INFORMATION
By using the FindWindow() and GetWindow() APIs (or using EnumWindows in Visual Basic 5.0 or later), you can loop through the Window handle list. For each window handle, you can check to see if it has a parent window with GetParent(). If the Window handle does not have a parent handle, you have reached the main window for an application. You can call GetWindowThreadProcessID(), which yields the instance handle of the process for the given window handle, to check the instance handle of the application against the instance handle received from the Shell() function.
Step-by-Step Example
REFERENCES
Topic in MSDN : "More about handles and process IDs" For additional information on using the EnumWindows functions to find a specified window, click the article number below to view the article in the Microsoft Knowledge Base: 183009
(http://support.microsoft.com/kb/183009/EN-US/
)
How To Enumerate Windows Using the WIN32 API
For additional information on performing this task in 16-bit versions of VB, click the article number below
to view the article in the Microsoft Knowledge Base:
127030
(http://support.microsoft.com/kb/127030/EN-US/
)
How to Find a Window Handle Based on an Instance Handle
APPLIES TO
| Article Translations
|
Back to the top
