2021-10-28 17:33:56 +00:00
|
|
|
#pragma once
|
|
|
|
#include <QQuickImageProvider>
|
|
|
|
#include <Windows.h>
|
2021-11-12 14:31:48 +00:00
|
|
|
#include <QRegularExpression>
|
2021-10-28 17:33:56 +00:00
|
|
|
class ExeImageProvider : public QQuickImageProvider {
|
|
|
|
public:
|
|
|
|
ExeImageProvider()
|
|
|
|
: QQuickImageProvider(QQuickImageProvider::Image)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage requestImage(const QString& id, QSize* size, const QSize& requestedSize) override
|
|
|
|
{
|
|
|
|
HICON icon = 0;
|
2021-11-12 14:31:48 +00:00
|
|
|
std::wstring path = QString(id).replace(QRegularExpression(("\\%5C")), "\\").toStdWString();
|
2021-10-28 17:33:56 +00:00
|
|
|
icon = (HICON)LoadImage(
|
|
|
|
0,
|
|
|
|
path.data(),
|
|
|
|
IMAGE_ICON,
|
|
|
|
GetSystemMetrics(SM_CXSMICON),
|
|
|
|
GetSystemMetrics(SM_CYSMICON),
|
|
|
|
LR_LOADFROMFILE | LR_LOADMAP3DCOLORS);
|
|
|
|
if (!icon) {
|
|
|
|
ExtractIconEx(path.data(), 0, &icon, nullptr, 1);
|
|
|
|
if (!icon) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QImage::fromHICON(icon);
|
|
|
|
}
|
|
|
|
};
|