Download demo project - 12 Kb
Download source files - 1 Kb
We all know the Pick Icon common dialog that the Windows shell displays when you choose "Change icon". However, the function to do this is undocumented. This article explains how to use this common dialog.
You bring up the dialog by calling the function PickIconDlg. This function is exported by ordinal from shell32.dll and has ordinal 62.
However, the function has one drawback: it has a different signature in Windows NT and Windows 95/98. Therefore, i wrote a wrapper around the function that dynamically binds to shell32.dll and converts arguments when necessary.
I provided two versions of the wrapper function: a Unicode version and an ANSI version.
The function returns you the name of a the file that contains the icon and the index of the icon. This is a zero-based index, not a resource id. This means you can extract the icon with the function ExtractIcon.
The following piece of code (from the accompanying sample project) shows how to call the wrapper function:
if (::SelectIcon(m_hWnd, m_pszCurrentFile, MAX_PATH, &m_dwCurrentIndex))
m_hIcon = ::ExtractIcon(::AfxGetInstanceHandle(),