getWinSystemIcon

#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();
}

上一篇:A survey of best practices for RNA-seq data analysis RNA-seq数据分析指南


下一篇:第二章 Matlab面向对象编程基础