LoadIconWithScaleDown function

Loads an icon. If the icon is not a standard size, this function scales down a larger image instead of scaling up a smaller image.

Syntax

HRESULT LoadIconWithScaleDown(
  HINSTANCE hinst,
  PCWSTR    pszName,
  int       cx,
  int       cy,
  HICON     *phico
);

Parameters

hinst

Type: HINSTANCE

A handle to the module of either a DLL or executable (.exe) file that contains the icon to be loaded. For more information, see GetModuleHandle.

To load a predefined icon or a standalone icon file, set this parameter to NULL.

pszName

Type: PCWSTR

A pointer to a null-terminated, Unicode buffer that contains location information about the icon to load.

If hinst is non-NULL, pszName specifies the icon resource either by name or ordinal. This ordinal must be packaged by using the MAKEINTRESOURCE macro.

If hinst is NULL, pszName specifies either the name of a standalone icon (.ico) file or the identifier of a predefined icon to load. The following identifiers are recognized. To pass these constants to the LoadIconWithScaleDown function, use the MAKEINTRESOURCE macro. For example, to load the IDI_ERROR icon, pass MAKEINTRESOURCE(IDI_ERROR) as the pszName parameter and NULL as the hinst parameter.

Value Meaning
IDI_APPLICATION
Default application icon.
IDI_ASTERISK
Same as IDI_INFORMATION.
IDI_ERROR
Hand-shaped icon.
IDI_EXCLAMATION
Same as IDI_WARNING.
IDI_HAND
Same as IDI_ERROR.
IDI_INFORMATION
Asterisk icon.
IDI_QUESTION
Question mark icon.
IDI_WARNING
Exclamation point icon.
IDI_WINLOGO
Windows logo icon.
IDI_SHIELD
Security Shield icon.

cx

Type: int

The desired width, in pixels, of the icon.

cy

Type: int

The desired height, in pixels, of the icon.

phico

Type: HICON*

When this function returns, contains a pointer to the handle of the loaded icon.

Return Value

Type: HRESULT

Returns S_OK if successful, or an error value otherwise, including the following:

Return code Description
E_INVALIDARG
The contents of the buffer pointed to by pszName do not fit any of the expected interpretations.

Remarks

This function will first search the icon file for an icon having exactly the same size. If a match is not found, then unless both cx and cy match one of the standard icon sizes—16, 32, 48, or 256 pixels— the next largest icon is selected and then scaled down to the desired size. For example, if an icon with an x dimension of 40 pixels is requested by the callign application, the 48-pixel icon is used and scaled down to 40 pixels. In contrast, the LoadImage function selects the 32-pixel icon and scales it up to 40 pixels.

If the function is unable to locate a larger icon, it defaults to the standard behavior of finding the next smallest icon and scaling it up to the desired size.

Requirements

   
Minimum supported client Windows Vista [desktop apps only]
Minimum supported server Windows Server 2008 [desktop apps only]
Target Platform Windows
Header commctrl.h
Library Comctl32.lib
DLL Comctl32.dll