LoadIconWithScaleDown function (commctrl.h)

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.


HRESULT LoadIconWithScaleDown(
  [in]  HINSTANCE hinst,
  [in]  PCWSTR    pszName,
  [in]  int       cx,
  [in]  int       cy,
  [out] HICON     *phico


[in] hinst


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 system icon or a standalone icon file, set this parameter to NULL.

[in] pszName


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 the identifier (beginning with the IDI_ prefix) of a predefined system icon to load.

[in] cx

Type: int

The desired width, in pixels, of the icon.

[in] cy

Type: int

The desired height, in pixels, of the icon.

[out] phico

Type: HICON*

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

Return value


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

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


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.


Requirement Value
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