forked from Public-Mirror/Textractor
Create small helpers to get icon from executable
This commit is contained in:
parent
615d372eeb
commit
dd4b8cfbb5
@ -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
|
||||
|
30
GUI/utils/windowshelpers.cpp
Normal file
30
GUI/utils/windowshelpers.cpp
Normal 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);
|
||||
}
|
||||
}
|
9
GUI/utils/windowshelpers.h
Normal file
9
GUI/utils/windowshelpers.h
Normal 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);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user