Microsoft KB Archive/35767: Difference between revisions
m (1 revision imported: importing part 1) |
m (Text replacement - ">" to ">") |
||
Line 36: | Line 36: | ||
<li>The hInstance parameter to the WinMain procedure is the application's instance handle. The application can save this value in a global variable, making it available throughout the application.</li> | <li>The hInstance parameter to the WinMain procedure is the application's instance handle. The application can save this value in a global variable, making it available throughout the application.</li> | ||
<li><p>The lParam parameter of the WM_CREATE message points to a CREATESTRUCT data structure, and the hInstance field of this structure is the application's instance handle. During the processing of the WM_CREATE message a window procedure can save this value in a static variable, as follows:</p> | <li><p>The lParam parameter of the WM_CREATE message points to a CREATESTRUCT data structure, and the hInstance field of this structure is the application's instance handle. During the processing of the WM_CREATE message a window procedure can save this value in a static variable, as follows:</p> | ||
<pre class="FIXEDTEXT"> hInst = ((LPCREATESTRUCT)lParam)- | <pre class="FIXEDTEXT"> hInst = ((LPCREATESTRUCT)lParam)->hInstance; </pre> | ||
<p>This variable would then be available during all subsequent calls to the window procedure.</p></li> | <p>This variable would then be available during all subsequent calls to the window procedure.</p></li> | ||
<li><p>Given a window handle for one of its windows, an application can obtain its instance handle by calling the GetWindowWord function:</p> | <li><p>Given a window handle for one of its windows, an application can obtain its instance handle by calling the GetWindowWord function:</p> |
Latest revision as of 10:19, 21 July 2020
HOWTO: Obtain an Application's Instance Handle |
Q35767
The information in this article applies to:
- Microsoft Windows Software Development Kit (SDK) versions 3.1, 3.0
SUMMARY
Many Windows API functions require an application's instance handle as a parameter. This article describes three methods that an application can use to obtain its instance handle.
MORE INFORMATION
Depending on the situation, an application might use any of the following three methods to obtain its instance handle:
- The hInstance parameter to the WinMain procedure is the application's instance handle. The application can save this value in a global variable, making it available throughout the application.
The lParam parameter of the WM_CREATE message points to a CREATESTRUCT data structure, and the hInstance field of this structure is the application's instance handle. During the processing of the WM_CREATE message a window procedure can save this value in a static variable, as follows:
hInst = ((LPCREATESTRUCT)lParam)->hInstance;
This variable would then be available during all subsequent calls to the window procedure.
Given a window handle for one of its windows, an application can obtain its instance handle by calling the GetWindowWord function:
GetWindowWord(hWnd, GWW_HINSTANCE)
Additional query words:
Keywords : kb16bitonly kbSDKPlatform kbGrpDSUser kbWndw
Issue type :
Technology : kbAudDeveloper kbWin3xSearch kbSDKSearch kbWinSDKSearch kbWinSDK300 kbWinSDK310
Last Reviewed: November 6, 1999 |