From dd4b8cfbb535cc10df7e5d29e81adc7ce1ff8b52 Mon Sep 17 00:00:00 2001 From: tera8m4 <82479019+tera8m4@users.noreply.github.com> Date: Sun, 2 May 2021 07:05:54 -0700 Subject: [PATCH] Create small helpers to get icon from executable --- GUI/CMakeLists.txt | 9 +++++++-- GUI/utils/windowshelpers.cpp | 30 ++++++++++++++++++++++++++++++ GUI/utils/windowshelpers.h | 9 +++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 GUI/utils/windowshelpers.cpp create mode 100644 GUI/utils/windowshelpers.h diff --git a/GUI/CMakeLists.txt b/GUI/CMakeLists.txt index be99474..0b07df8 100644 --- a/GUI/CMakeLists.txt +++ b/GUI/CMakeLists.txt @@ -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 diff --git a/GUI/utils/windowshelpers.cpp b/GUI/utils/windowshelpers.cpp new file mode 100644 index 0000000..2d657d9 --- /dev/null +++ b/GUI/utils/windowshelpers.cpp @@ -0,0 +1,30 @@ +#include "windowshelpers.h" + +#include +#include +#include +#include +#include + +#include + +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); + } +} diff --git a/GUI/utils/windowshelpers.h b/GUI/utils/windowshelpers.h new file mode 100644 index 0000000..405d4fe --- /dev/null +++ b/GUI/utils/windowshelpers.h @@ -0,0 +1,9 @@ +#pragma once + +#include +class QIcon; +namespace WindowsHepers +{ + HICON GetIconHandlerFromExe(const wchar_t* const filePath); + QIcon CreateQIconFromHIcon(const HICON hIcon); +}