Create small helpers to get icon from executable

This commit is contained in:
tera8m4 2021-05-02 07:05:54 -07:00 committed by Akash Mozumdar
parent 615d372eeb
commit dd4b8cfbb5
3 changed files with 46 additions and 2 deletions

View File

@ -1,6 +1,10 @@
include(QtUtils)
msvc_registry_search()
find_qt5(Core Widgets)
find_qt5(Core Widgets WinExtras)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
add_executable(Textractor WIN32
main.cpp
@ -10,11 +14,12 @@ add_executable(Textractor WIN32
host/host.cpp
host/textthread.cpp
host/hookcode.cpp
utils/windowshelpers.cpp
Textractor.rc
Textractor.ico
)
target_precompile_headers(Textractor REUSE_FROM pch)
target_link_libraries(Textractor Qt5::Widgets shell32 winhttp)
target_link_libraries(Textractor Qt5::Widgets Qt5::WinExtras shell32 winhttp)
if (NOT EXISTS ${CMAKE_FINAL_OUTPUT_DIRECTORY}/Qt5Core.dll AND NOT EXISTS ${CMAKE_FINAL_OUTPUT_DIRECTORY}/Qt5Cored.dll)
add_custom_command(TARGET Textractor

View File

@ -0,0 +1,30 @@
#include "windowshelpers.h"
#include <QApplication>
#include <QIcon>
#include <QStyle>
#include <QPixmap>
#include <QtWinExtras/QtWin>
#include <shellapi.h>
namespace WindowsHepers {
HICON GetIconHandlerFromExe(const wchar_t* const filePath)
{
HICON bigIcon;
HICON smallIcon;
ExtractIconEx(filePath, 0, &bigIcon, &smallIcon, 1);
return bigIcon != 0 ? bigIcon : smallIcon;
}
QIcon CreateQIconFromHIcon(const HICON hIcon)
{
if (hIcon)
{
const QPixmap& pixmap = QtWin::fromHICON(hIcon);
return QIcon(pixmap);
}
const QStyle* style = QApplication::style();
return style->standardIcon(QStyle::SP_ComputerIcon);
}
}

View File

@ -0,0 +1,9 @@
#pragma once
#include <QtWinExtras/QtWin>
class QIcon;
namespace WindowsHepers
{
HICON GetIconHandlerFromExe(const wchar_t* const filePath);
QIcon CreateQIconFromHIcon(const HICON hIcon);
}