Load icon from file

I am searching through the registry and I want to load certain icons to a HICON. I found the following:
"shell32.dll,-152"

I want to load it into a HICON, I tried:
HICON hIcon = (HICON)LoadImage (NULL, _T("shell32.dll,-152"), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);

The return value is NULL. How can I load the icon?

Thanks....
SlaskAsked:
Who is Participating?
 
PriyeshConnect With a Mentor Commented:
You have to load the shell32.dll and 152 must be probably the ID of the ICON inside the shell32.dll if it contains the resource, i don't know, i havent tried it, but this seems logical to me.

Try this,

HMODULE hDll = ::LoadLibrary("shell32.dll") ;
HICON hIcon = ::LoadICon(hDll, MAKEINTRESOURCE(152)) ;
//Check if hIcon is valid

::FreeLibrary(hDll) ;

Regrds,
Priyesh.
0
 
SlaskAuthor Commented:
Great it worked. Lock the question, the points are yours...
0
 
zoferCommented:
Use FindResouce to get handle to the icon and then use LoadResource

HMODULE hDll = ::LoadLibrary("shell32.dll") ;

HRSRC hRes = FindResource( hDll, RT_ICON, _T("152"));

HICON hIcon = (HICON) LoadResource( hDll, hRes);

::FreeLibrary(hDll) ;

That should do it.
0
All Courses

From novice to tech pro — start learning today.