LoadImage function
Loads an icon, cursor, animated cursor, or bitmap.
Syntax
HANDLE WINAPI LoadImage( _In_opt_ HINSTANCE hinst, _In_ LPCTSTR lpszName, _In_ UINT uType, _In_ int cxDesired, _In_ int cyDesired, _In_ UINT fuLoad );
Parameters
- hinst [in, optional]
-
Type: HINSTANCE
A handle to the module of either a DLL or executable (.exe) that contains the image to be loaded. For more information, see GetModuleHandle. Note that as of 32-bit Windows, an instance handle (HINSTANCE), such as the application instance handle exposed by system function call of WinMain, and a module handle (HMODULE) are the same thing.
To load an OEM image, set this parameter to NULL.
To load a stand-alone resource (icon, cursor, or bitmap file)—for example, c:\myimage.bmp—set this parameter to NULL.
- lpszName [in]
-
Type: LPCTSTR
The image to be loaded. If the hinst parameter is non-NULL and the fuLoad parameter omits LR_LOADFROMFILE, lpszName specifies the image resource in the hinst module. If the image resource is to be loaded by name from the module, the lpszName parameter is a pointer to a null-terminated string that contains the name of the image resource. If the image resource is to be loaded by ordinal from the module, use the MAKEINTRESOURCE macro to convert the image ordinal into a form that can be passed to the LoadImage function. For more information, see the Remarks section below.
If the hinst parameter is NULL and the fuLoad parameter omits the LR_LOADFROMFILE value, the lpszName specifies the OEM image to load. The OEM image identifiers are defined in Winuser.h and have the following prefixes.
Prefix Meaning OBM_ OEM bitmaps OIC_ OEM icons OCR_ OEM cursors To pass these constants to the LoadImage function, use the MAKEINTRESOURCE macro. For example, to load the OCR_NORMAL cursor, pass
MAKEINTRESOURCE(OCR_NORMAL)as the lpszName parameter, NULL as the hinst parameter, and LR_SHARED as one of the flags to the fuLoad parameter.If the fuLoad parameter includes the LR_LOADFROMFILE value, lpszName is the name of the file that contains the stand-alone resource (icon, cursor, or bitmap file). Therefore, set hinst to NULL.
- uType [in]
-
Type: UINT
The type of image to be loaded. This parameter can be one of the following values.
Value Meaning - IMAGE_BITMAP
- 0
Loads a bitmap.
- IMAGE_CURSOR
- 2
Loads a cursor.
- IMAGE_ICON
- 1
Loads an icon.
- cxDesired [in]
-
Type: int
The width, in pixels, of the icon or cursor. If this parameter is zero and the fuLoad parameter is LR_DEFAULTSIZE, the function uses the SM_CXICON or SM_CXCURSOR system metric value to set the width. If this parameter is zero and LR_DEFAULTSIZE is not used, the function uses the actual resource width.
- cyDesired [in]
-
Type: int
The height, in pixels, of the icon or cursor. If this parameter is zero and the fuLoad parameter is LR_DEFAULTSIZE, the function uses the SM_CYICON or SM_CYCURSOR system metric value to set the height. If this parameter is zero and LR_DEFAULTSIZE is not used, the function uses the actual resource height.
- fuLoad [in]
-
Type: UINT
This parameter can be one or more of the following values.
Return value
Type: HANDLE
If the function succeeds, the return value is the handle of the newly loaded image.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.
Remarks
If IS_INTRESOURCE(lpszName) is TRUE, then lpszName specifies the integer identifier of the given resource. Otherwise, it is a pointer to a null- terminated string. If the first character of the string is a pound sign (#), then the remaining characters represent a decimal number that specifies the integer identifier of the resource. For example, the string "#258" represents the identifier 258.
When you are finished using a bitmap, cursor, or icon you loaded without specifying the LR_SHARED flag, you can release its associated memory by calling one of the functions in the following table.
| Resource | Release function |
|---|---|
| Bitmap | DeleteObject |
| Cursor | DestroyCursor |
| Icon | DestroyIcon |
The system automatically deletes these resources when the process that created them terminates; however, calling the appropriate function saves memory and decreases the size of the process's working set.
Examples
For an example, see Using Window Classes.
Requirements
|
Minimum supported client |
Windows 2000 Professional [desktop apps only] |
|---|---|
|
Minimum supported server |
Windows 2000 Server [desktop apps only] |
|
Header |
|
|
Library |
|
|
DLL |
|
|
Unicode and ANSI names |
LoadImageW (Unicode) and LoadImageA (ANSI) |
See also
- Reference
- CopyImage
- LoadCursor
- LoadIcon
- Conceptual
- Resources
- Other Resources
- GetSystemMetrics
- LoadBitmap