Recently I made a program to extract icons from EXE, DLL, or other files.
I collected some information from the Internet and found that only small icons can be extracted. The small icons are 16x16 and the large icons are 32x32, which far cannot meet the requirements. The following is a general practice:
QString filePath;
QFileInfo fileInfo (filePath );
QFileIconProvider fileIcon ();
QIcon icon = fileIcon (). icon (fileInfo );
QPixmap pixmap = icon. pixmap (128,128 );
Only 32x32 Icons can be obtained.
So I checked the implementation source file of QFileIconProvider and found that it was mainly implemented by the SHGetFileInfo function.
// Get the small icon
# Ifndef Q_ OS _WINCE
Val = SHGetFileInfo (const wchar_t *) QDir: toNativeSeparators (fileInfo. filePath (). utf16 (), 0, & info,
Sizeof (SHFILEINFO), SHGFI_ICON | SHGFI_SMALLICON | SHGFI_SYSICONINDEX | SHGFI_ADDOVERLAYS | SHGFI_OVERLAYINDEX );
// Get the big icon
# Ifndef Q_ OS _WINCE
Val = SHGetFileInfo (const wchar_t *) QDir: toNativeSeparators (fileInfo. filePath (). utf16 (), 0, & info,
Sizeof (SHFILEINFO), SHGFI_ICON | SHGFI_LARGEICON | SHGFI_SYSICONINDEX | SHGFI_ADDOVERLAYS | SHGFI_OVERLAYINDEX );
In this way, you can only get 16 small icons and 32 large icons.
Although QPixmap pixmap = icon. pixmap (128,128) is used above, only 32x32 Icons can be obtained.
So I figured out how to use the library under VS2010?
I thought it would be too low to come up with a solution, but I suddenly thought that I could use VS2010 to make a DLL for QT call.
Therefore, write an output function in VS2010:
# Include <ShellAPI. h>
# Include <CommCtrl. h>
# Include <commoncontrols. h>
# Include <windows. h>
EXTERN_C _ declspec (dllexport) HICON getJumbIcon (const tchar * filePath)
{
// Get the icon index using SHGetFileInfo
SHFILEINFOW sfi = {0 };
SHGetFileInfo (filePath,-1, & sfi, sizeof (sfi), SHGFI_SYSICONINDEX );
// Retrieve the system image list.
// To get the 48x48 icons, use SHIL_EXTRALARGE
// To get the 256x256 icons (Vista only), use SHIL_JUMBO
IImageList * imageList;
HRESULT hResult = SHGetImageList (SHIL_JUMBO, IID_IImageList, (void **) & imageList );
If (hResult = S_ OK ){
// Get the icon we need from the list. Note that the HIMAGELIST we retrieved
// Earlier needs to be casted to the IImageList interface before use.
HICON hIcon;
HResult = (imageList)-> GetIcon (sfi. iIcon, ILD_TRANSPARENT, & hIcon );
If (hResult = S_ OK ){
// Do something with the icon here.
Return hIcon;
}
}
}
Call the following in QT:
Typedef HICON (* getIcon) (const tchar * filePath); // defines the function pointer for future calls
HICON test (QString filePath)
{
QLibrary mylib ("./configure/dll/icon. dll"); // declare the dll file used
HICON jumbIcon;
If (mylib. load ())
{
GetIcon icon = (getIcon) mylib. resolve ("getJumbIcon"); // reference the add () function
If (icon) // whether the connection is successful add () function
{
FilePath. replace ("/","\\");
JumbIcon = icon (const tchar *) filePath. utf16 (); // The function pointer calls the add () function in dll.
Return jumbIcon;
}
Else
QMessageBox: information (NULL, "NO", "Linke to Function is not OK !!!! ");
}
Else
QMessageBox: information (NULL, "NO", "DLL is not loaded! ");
Return NULL;
}
HICON hicon = test (filePath );
QPixmap icon = QPixmap: fromWinHICON (hicon );
DestroyIcon (hicon );
The icon can display the 256X256 image.
You can change SHIL_JUMBO to determine the Icon size.
Finally, it is the DLL file.
This article is from the "leisurely and secluded" blog