Thursday, April 21, 2011

Load the Default Icon For the Shell

The default icon in Vista is listed under:

HKEY_CLASSES_ROOT \ Unknown \ DefaultIcon

As:

%SystemRoot%\System32\shell32.dll,0

I want to load a 48x48 version of that Icon in C++. I have tried:

hIcon = (HICON)::LoadImage(hmShell32, MAKEINTRESOURCE(0), IMAGE_ICON, 48, 48, LR_DEFAULTCOLOR);

However I get back a NULL hIcon and when I call ::GetLastError() it returns: ERROR_RESOURCE_TYPE_NOT_FOUND

How do I load the default icon out of Shell32.dll?

Thanks in advance, Wayne Walter Berry

{6230289B-5BEE-409e-932A-2F01FA407A92}

From stackoverflow
  • If you only have to support Vista/7 then this should work.

    SHSTOCKICONINFO iconInfo;
    iconInfo.cbSize = sizeof(iconInfo);
    if(SUCCEEDED(SHGetStockIconInfo(SIID_DOCNOASSOC, SHGSI_ICONLOCATION, &iconInfo)))
    {    
        wcex.hIcon = (HICON)::LoadImage(LoadLibrary(iconInfo.szPath), MAKEINTRESOURCE(-iconInfo.iIcon), IMAGE_ICON, 48, 48, LR_DEFAULTCOLOR);
    }
    

0 comments:

Post a Comment