33 lines
840 B
C++
33 lines
840 B
C++
#include "stdafx.h"
|
|
#include "WinHelper.h"
|
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
|
#include <QtWin>
|
|
#else
|
|
#include <windows.h>
|
|
#endif
|
|
|
|
#include <Shlwapi.h>
|
|
#include <Shlobj.h>
|
|
|
|
QImage 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)
|
|
QImage Icon = QtWin::fromHICON(icon).toImage();
|
|
#else
|
|
QImage Icon = 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;
|
|
} |