#include <MUtils/GUI.h>
+//Internal
+#include "Utils_Win32.h"
+
//Qt
+#include <QIcon>
#include <QApplication>
#include <QWidget>
}
///////////////////////////////////////////////////////////////////////////////
-// 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)
// 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)
{
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)
{
#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;