diff --git a/include/MUtils/GUI.h b/include/MUtils/GUI.h index a5e9cf5..f11ef60 100644 --- a/include/MUtils/GUI.h +++ b/include/MUtils/GUI.h @@ -24,6 +24,10 @@ //MUtils #include +//Forward Declaration +class QIcon; +class QWidget; + /////////////////////////////////////////////////////////////////////////////// namespace MUtils @@ -41,6 +45,8 @@ namespace MUtils //Broadcast message MUTILS_API bool broadcast(int eventType, const bool &onlyToVisible); + MUTILS_API bool set_window_icon(QWidget *window, const QIcon &icon, const bool bIsBigIcon); + //Force quit application MUTILS_API void force_quit(void); } diff --git a/include/MUtils/Startup.h b/include/MUtils/Startup.h index 6017d83..0a30ba5 100644 --- a/include/MUtils/Startup.h +++ b/include/MUtils/Startup.h @@ -34,7 +34,7 @@ namespace MUtils typedef int (main_function_t)(int &argc, char **argv); //Startup Application - MUTILS_API int startup(int &argc, char **argv, main_function_t *const entry_point); + MUTILS_API int startup(int &argc, char **argv, main_function_t *const entry_point, const bool &debugConsole); //Initialize Qt MUTILS_API bool init_qt(int &argc, char **argv, const QString &appName); diff --git a/src/GUI.cpp b/src/GUI.cpp index 7453c6f..9bbf587 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -21,7 +21,11 @@ #include +//Internal +#include "Utils_Win32.h" + //Qt +#include #include #include @@ -62,7 +66,59 @@ bool MUtils::GUI::broadcast(int eventType, const bool &onlyToVisible) } /////////////////////////////////////////////////////////////////////////////// -// BROADCAST +// WINDOW ICON +/////////////////////////////////////////////////////////////////////////////// + +namespace MUtils +{ + namespace GUI + { + namespace Internal + { + class WindowIconHelper : public QObject + { + public: + WindowIconHelper(QWidget *const parent, const HICON hIcon, const bool &bIsBigIcon) + : + QObject(parent), + m_hIcon(hIcon) + { + SendMessage(parent->winId(), WM_SETICON, (bIsBigIcon ? ICON_BIG : ICON_SMALL), LPARAM(hIcon)); + } + + ~WindowIconHelper(void) + { + if(m_hIcon) + { + DestroyIcon(m_hIcon); + } + } + + private: + const HICON m_hIcon; + }; + } + } +} + +bool MUtils::GUI::set_window_icon(QWidget *window, const QIcon &icon, const bool bIsBigIcon) +{ + if((!icon.isNull()) && window->winId()) + { + const int extend = (bIsBigIcon ? 32 : 16); + if(HICON hIcon = qicon_to_hicon(icon, extend, extend)) + { + if(new Internal::WindowIconHelper(window, hIcon, bIsBigIcon)) + { + return true; + } + } + } + return false; +} + +/////////////////////////////////////////////////////////////////////////////// +// FORCE QUIT /////////////////////////////////////////////////////////////////////////////// void MUtils::GUI::force_quit(void) diff --git a/src/Startup.cpp b/src/Startup.cpp index 1558982..e06c464 100644 --- a/src/Startup.cpp +++ b/src/Startup.cpp @@ -64,19 +64,19 @@ static bool qt_event_filter(void *message, long *result) // STARTUP FUNCTION /////////////////////////////////////////////////////////////////////////////// -static int startup_main(int &argc, char **argv, MUtils::Startup::main_function_t *const entry_point) +static int startup_main(int &argc, char **argv, MUtils::Startup::main_function_t *const entry_point, const bool &debugConsole) { qInstallMsgHandler(qt_message_handler); - MUtils::Terminal::setup(argc, argv, MUTILS_DEBUG); + MUtils::Terminal::setup(argc, argv, MUTILS_DEBUG || debugConsole); return entry_point(argc, argv); } -static int startup_helper(int &argc, char **argv, MUtils::Startup::main_function_t *const entry_point) +static int startup_helper(int &argc, char **argv, MUtils::Startup::main_function_t *const entry_point, const bool &debugConsole) { int iResult = -1; try { - iResult = startup_main(argc, argv, entry_point); + iResult = startup_main(argc, argv, entry_point, debugConsole); } catch(const std::exception &error) { @@ -91,21 +91,21 @@ static int startup_helper(int &argc, char **argv, MUtils::Startup::main_function return iResult; } -int MUtils::Startup::startup(int &argc, char **argv, main_function_t *const entry_point) +int MUtils::Startup::startup(int &argc, char **argv, main_function_t *const entry_point, const bool &debugConsole) { int iResult = -1; #if (MUTILS_DEBUG) #ifdef _MSC_VER _CrtSetDbgFlag(_CRTDBG_CHECK_ALWAYS_DF || _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG)); #endif //_MSCVER - iResult = startup_main(argc, argv, entry_point); + iResult = startup_main(argc, argv, entry_point, debugConsole); #else //MUTILS_DEBUG #ifdef _MSC_VER __try { MUtils::ErrorHandler::initialize(); MUtils::OS::check_debugger(); - iResult = startup_helper(argc, argv, entry_point); + iResult = startup_helper(argc, argv, entry_point, debugConsole); } __except(1) { @@ -115,7 +115,7 @@ int MUtils::Startup::startup(int &argc, char **argv, main_function_t *const entr #else //_MSCVER MUtils::ErrorHandler::initialize(); MUtils::OS::check_debugger(); - iResult = startup_helper(argc, argv, entry_point); + iResult = startup_helper(argc, argv, entry_point, debugConsole); #endif //_MSCVER #endif //MUTILS_DEBUG return iResult; diff --git a/src/Utils_Win32.h b/src/Utils_Win32.h index f074410..97e0bbc 100644 --- a/src/Utils_Win32.h +++ b/src/Utils_Win32.h @@ -27,6 +27,9 @@ #include #endif //_INC_WINDOWS +//Qt +#include + /////////////////////////////////////////////////////////////////////////////// // QICON TO HICON ///////////////////////////////////////////////////////////////////////////////