#include <QtGui/QImage>
#include <QtGui/QPixmap>
void getSystemIcon(const chConstStringA& fileType, xPixmap& dst)
{
if (fileType.empty())
{
return;
}
CoInitialize(NULL);
SHFILEINFOA sfi = { 0 };
// 除了SHGFI_ICON之外还有SHGFI_LARGEICON(大图标), SHGFI_SMALLICON(小图标)
SHGetFileInfoA(fileType.c_str(), 0, &sfi, sizeof(sfi), SHGFI_USEFILEATTRIBUTES | SHGFI_ICON);
QImage image;
if (sfi.hIcon != NULL)
{
QPixmap pixIcon = QPixmap::fromWinHICON(sfi.hIcon);
if (!pixIcon.isNull())
{
image = pixIcon.toImage();
image = image.scaled(QSize(30, 30), Qt::KeepAspectRatio);
dst.loadFromPixelData((xPixel*)image.constBits(), image.width(), image.height());
}
DestroyIcon(sfi.hIcon);
}
CoUninitialize();
}
转载于:https://www.cnblogs.com/hqu-ye/p/5916564.html