Sandboxie/SandboxiePlus/SandMan/Helpers/WinHelper.cpp

33 lines
853 B
C++
Raw Normal View History

2022-12-16 12:08:49 +00:00
#include "stdafx.h"
#include "WinHelper.h"
2022-12-16 12:32:48 +00:00
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QtWin>
#else
2022-12-16 12:08:49 +00:00
#include <windows.h>
2022-12-16 12:32:48 +00:00
#endif
2022-12-16 12:08:49 +00:00
#include <Shlwapi.h>
#include <Shlobj.h>
2022-12-21 09:14:31 +00:00
QPixmap LoadWindowsIcon(const QString& Path, quint32 Index)
2022-12-16 12:08:49 +00:00
{
std::wstring path = QString(Path).replace("/", "\\").toStdWString();
HICON icon = ExtractIconW(NULL, path.c_str(), Index);
2022-12-16 12:32:48 +00:00
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
2022-12-21 09:14:31 +00:00
QPixmap Icon = QtWin::fromHICON(icon);
2022-12-16 12:32:48 +00:00
#else
2022-12-21 09:14:31 +00:00
QPixmap Icon = QPixmap::fromImage(QImage::fromHICON(icon));
2022-12-16 12:32:48 +00:00
#endif
2022-12-16 12:08:49 +00:00
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;
}