Moved set_window_icon() function into MUtilities function.

This commit is contained in:
LoRd_MuldeR 2014-12-04 23:03:05 +01:00
parent 937904fb44
commit 37d89e834d
5 changed files with 75 additions and 10 deletions

View File

@ -24,6 +24,10 @@
//MUtils //MUtils
#include <MUtils/Global.h> #include <MUtils/Global.h>
//Forward Declaration
class QIcon;
class QWidget;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
namespace MUtils namespace MUtils
@ -41,6 +45,8 @@ namespace MUtils
//Broadcast message //Broadcast message
MUTILS_API bool broadcast(int eventType, const bool &onlyToVisible); 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 //Force quit application
MUTILS_API void force_quit(void); MUTILS_API void force_quit(void);
} }

View File

@ -34,7 +34,7 @@ namespace MUtils
typedef int (main_function_t)(int &argc, char **argv); typedef int (main_function_t)(int &argc, char **argv);
//Startup Application //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 //Initialize Qt
MUTILS_API bool init_qt(int &argc, char **argv, const QString &appName); MUTILS_API bool init_qt(int &argc, char **argv, const QString &appName);

View File

@ -21,7 +21,11 @@
#include <MUtils/GUI.h> #include <MUtils/GUI.h>
//Internal
#include "Utils_Win32.h"
//Qt //Qt
#include <QIcon>
#include <QApplication> #include <QApplication>
#include <QWidget> #include <QWidget>
@ -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) void MUtils::GUI::force_quit(void)

View File

@ -64,19 +64,19 @@ static bool qt_event_filter(void *message, long *result)
// STARTUP FUNCTION // 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); qInstallMsgHandler(qt_message_handler);
MUtils::Terminal::setup(argc, argv, MUTILS_DEBUG); MUtils::Terminal::setup(argc, argv, MUTILS_DEBUG || debugConsole);
return entry_point(argc, argv); 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; int iResult = -1;
try try
{ {
iResult = startup_main(argc, argv, entry_point); iResult = startup_main(argc, argv, entry_point, debugConsole);
} }
catch(const std::exception &error) catch(const std::exception &error)
{ {
@ -91,21 +91,21 @@ static int startup_helper(int &argc, char **argv, MUtils::Startup::main_function
return iResult; 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; int iResult = -1;
#if (MUTILS_DEBUG) #if (MUTILS_DEBUG)
#ifdef _MSC_VER #ifdef _MSC_VER
_CrtSetDbgFlag(_CRTDBG_CHECK_ALWAYS_DF || _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG)); _CrtSetDbgFlag(_CRTDBG_CHECK_ALWAYS_DF || _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG));
#endif //_MSCVER #endif //_MSCVER
iResult = startup_main(argc, argv, entry_point); iResult = startup_main(argc, argv, entry_point, debugConsole);
#else //MUTILS_DEBUG #else //MUTILS_DEBUG
#ifdef _MSC_VER #ifdef _MSC_VER
__try __try
{ {
MUtils::ErrorHandler::initialize(); MUtils::ErrorHandler::initialize();
MUtils::OS::check_debugger(); MUtils::OS::check_debugger();
iResult = startup_helper(argc, argv, entry_point); iResult = startup_helper(argc, argv, entry_point, debugConsole);
} }
__except(1) __except(1)
{ {
@ -115,7 +115,7 @@ int MUtils::Startup::startup(int &argc, char **argv, main_function_t *const entr
#else //_MSCVER #else //_MSCVER
MUtils::ErrorHandler::initialize(); MUtils::ErrorHandler::initialize();
MUtils::OS::check_debugger(); MUtils::OS::check_debugger();
iResult = startup_helper(argc, argv, entry_point); iResult = startup_helper(argc, argv, entry_point, debugConsole);
#endif //_MSCVER #endif //_MSCVER
#endif //MUTILS_DEBUG #endif //MUTILS_DEBUG
return iResult; return iResult;

View File

@ -27,6 +27,9 @@
#include <Windows.h> #include <Windows.h>
#endif //_INC_WINDOWS #endif //_INC_WINDOWS
//Qt
#include <QIcon>
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// QICON TO HICON // QICON TO HICON
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////