Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get icon bitmap from HICON?

924 views
Skip to first unread message

szyk...@gmail.com

unread,
Feb 15, 2017, 12:14:19 AM2/15/17
to
Hi
I am writting program which must extract bitmap icons from Windows with WinApi. Next I will cache them and display with custom library. For now I have simple code (in C++ but it is very simple). But I don't know what to do with HICON - I don't find any function in WinApi which can extract icon from HICON handle. So maybe is there other way?
My current code is like this:
wchar_t* lFile = new wchar_t[lItem->fileName().size() + 1];
lItem->fileName().toWCharArray(lFile);
lFile[lItem->fileName().size()] = 0;
SHFILEINFOW lFileInfo;
HICON lIcon = SHGetFileInfo(lFile, FILE_ATTRIBUTE_NORMAL, &lFileInfo, sizeof(SHFILEINFO), SHGFI_USEFILEATTRIBUTES | SHGFI_ICON | SHGFI_SMALLICON);
delete [] lFile;
lFile = 0;

If you can tell me where is better group or forum to post this message please let me know.

thanks and best regards
Szyk Cech

Rick C. Hodgin

unread,
Feb 15, 2017, 4:47:57 AM2/15/17
to
See for several related algorithms:

https://msdn.microsoft.com/en-us/library/windows/desktop/dd162950(v=vs.85).aspx

Thank you,
Rick C. Hodgin

Christian Astor

unread,
Feb 15, 2017, 7:00:34 AM2/15/17
to
szyk...@gmail.com a écrit :

> I am writting program which must extract bitmap icons from Windows with WinApi. Next I will cache them and display with custom library. For now I have simple code (in C++ but it is very simple). But I don't know what to do with HICON - I don't find any function in WinApi which can extract icon from HICON handle. So maybe is there other way?

Use GetIconInfo()

or with an ImageList(ImageList_Create(), ImageList_AddIcon(),
ImageList_Draw())

Christian Astor

unread,
Feb 15, 2017, 7:06:48 AM2/15/17
to
Christian Astor a écrit :

> Use GetIconInfo()
>
> or with an ImageList(ImageList_Create(), ImageList_AddIcon(),
> ImageList_Draw())

...or DrawIcon(Ex) in a DC.

szyk...@gmail.com

unread,
Feb 16, 2017, 2:39:38 PM2/16/17
to
> ...or DrawIcon(Ex) in a DC.

Ok! I can imagine that I create dumb window and print on it an icon. But now other problem arises: how to get width and height of the icon? GetIconInfo(Ex) does not return such information. I must know that info from WinApi because I want icons for files type and icons for exe and dll. Their dimensions can be various so I must get it some how...

szyk...@gmail.com

unread,
Feb 17, 2017, 2:55:29 PM2/17/17
to
Ok! Now I found solution of my problem. I dig Qt sources (and after load them to memory I balanced on the edge of insufficient memory) I found in file:
Qt\5.6\Src\qtbase\src\gui\image\qpixmap_win.cpp
Function:
Q_GUI_EXPORT QPixmap qt_pixmapFromWinHICON(HICON icon)
Which is fine with me as I planed use Qt library. But without QFileIconProvider bloatware...

best regards
Szyk Cech
0 new messages