#include "stdafx.h" #include "WinHelper.h" #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #include #else #include #endif #include #include QPixmap LoadWindowsIcon(const QString& Path, quint32 Index) { std::wstring path = QString(Path).replace("/", "\\").toStdWString(); HICON icon = ExtractIconW(NULL, path.c_str(), Index); #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QPixmap Icon = QtWin::fromHICON(icon); #else QPixmap Icon = QPixmap::fromImage(QImage::fromHICON(icon)); #endif DestroyIcon(icon); return Icon; } bool PickWindowsIcon(QWidget* pParent, QString& Path, quint32& Index) { wchar_t iconPath[MAX_PATH] = { 0 }; Path.toWCharArray(iconPath); BOOL Ret = PickIconDlg((HWND)pParent->window()->winId(), iconPath, MAX_PATH, (int*)&Index); Path = QString::fromWCharArray(iconPath); return !!Ret; }