User32LoadImage Method

Loads an icon, cursor, animated cursor, or bitmap.

Definition

Namespace: DevCase.Win32.NativeMethods
Assembly: DevCase.net48 (in DevCase.net48.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
[DllImportAttribute("User32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static IntPtr LoadImage(
	IntPtr hInstance,
	string name,
	LoadImageType type,
	int width,
	int height,
	LoadImageFlags flags
)

Parameters

hInstance  IntPtr
A handle to the module of either a DLL or executable (.exe) that contains the image to be loaded.

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 a stand-alone resource (icon, cursor, or bitmap file), like for example c:\myimage.bmp, set this parameter to Zero.

name  String
The image to be loaded.

If the hInstance parameter is non-Zero and the flags parameter omits LoadFromFile, name specifies the image resource in the hInstance module.

If the image resource is to be loaded by name from the module, the name 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(IntPtr, String, LoadImageType, Int32, Int32, LoadImageFlags) function.

If the flags parameter includes the LoadFromFile value, name is the name of the file that contains the stand-alone resource (icon, cursor, or bitmap file).

Therefore, set hinst to .

type  LoadImageType
The type of image to be loaded.
width  Int32
The width, in pixels, of the icon or cursor.

If this parameter is zero and the fuLoad parameter is DefaultSize, the function uses the SM_CXICON or SM_CXCURSOR system metric value to set the width.

If this parameter is zero and DefaultSize is not used, the function uses the actual resource width.

height  Int32
The height, in pixels, of the icon or cursor.

If this parameter is zero and the fuLoad parameter is DefaultSize, the function uses the SM_CYICON or SM_CYCURSOR system metric value to set the height.

If this parameter is zero and DefaultSize is not used, the function uses the actual resource height.

flags  LoadImageFlags
Flags that determines how the image is loaded.

Return Value

IntPtr
If the function succeeds, the return value is the handle of the newly loaded image.

If the function fails, the return value is Zero.

To get extended error information, call GetLastWin32Error.

Remarks

See Also