PickIconDlg function explained

In windows if you ever changed the icon of a shortcut then you’ll know what the API PickIconDlg does. Basically this function will let you select any icon embedded as a resource in a .dll or .exe file for use in your application. Just select in the dialog the icon that you like and click ok. Here is a shot of the dialog, in my case I’ve given devenv.exe and this is how it looks for me…
PickIcon dialog screenshot

PickIcon dialog screenshot

So the API for invoking the API is as follows…

[sourcecode language=”cpp”]int Index = 2;
const DWORD BuffSize = MAX_PATH*2;
TCHAR Path[BuffSize] = {_T("C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe")};
const int Sel = PickIconDlg(GetSafeHwnd(), Path, BuffSize, &Index);
 // The hinst parameter is assumed to have been initialized earlier.
 HMODULE hMod = ::LoadLibrary(Path);
 m_hIcon = ExtractIcon(hMod, Path, Index);
 // After some work destroy the icon

// Set the icon for this dialog using above extracted icon
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon [/sourcecode]

Now see my dialog titlebar after executing this code snippet…

Dialog with new icon

Dialog with new icon


Have fun! 🙂

Appreciate your comments...