SendMessage(parent->winId(), WM_SETICON, (bIsBigIcon ? ICON_BIG : ICON_SMALL), LPARAM(hIcon));
}
- ~WindowIconHelper(void)
+ virtual ~WindowIconHelper(void)
{
if(m_hIcon)
{
if((!icon.isNull()) && window->winId())
{
const int extend = (bIsBigIcon ? 32 : 16);
- if(HICON hIcon = (HICON) MUtils::Win32Utils::qicon_to_hicon(icon, extend, extend))
+ if(const HICON hIcon = (HICON) MUtils::Win32Utils::qicon_to_hicon(icon, extend, extend))
{
- if(new Internal::WindowIconHelper(window, hIcon, bIsBigIcon))
- {
- return true;
- }
+ new Internal::WindowIconHelper(window, hIcon, bIsBigIcon); /*will be free'd using QObject parent mechanism*/
+ return true;
}
}
return false;
//The log file
static QScopedPointer<QFile> g_terminal_log_file;
+//Terminal icon
+static HICON g_terminal_icon = NULL;
+
///////////////////////////////////////////////////////////////////////////////
// HELPER FUNCTIONS
///////////////////////////////////////////////////////////////////////////////
return out;
}
+static inline void set_hicon(HICON *const ptr, const HICON val)
+{
+ if (*ptr)
+ {
+ DestroyIcon(*ptr);
+ }
+ *ptr = val;
+}
+
///////////////////////////////////////////////////////////////////////////////
// TERMINAL SETUP
///////////////////////////////////////////////////////////////////////////////
if(stdout) freopen_s(&temp[0], "NUL", "wb", stdout);
if(stderr) freopen_s(&temp[1], "NUL", "wb", stderr);
FreeConsole();
+ set_hicon(&g_terminal_icon, NULL);
g_terminal_attached = false;
}
}
if(g_terminal_attached && (!(icon.isNull() || MUtils::OS::running_on_wine())))
{
- typedef DWORD(__stdcall *SetConsoleIconFun)(HICON);
- if(const SetConsoleIconFun setConsoleIconFun = MUtils::Win32Utils::resolve<SetConsoleIconFun>(QLatin1String("kernel32"), QLatin1String("SetConsoleIcon")))
+ if(const HICON hIcon = (HICON) MUtils::Win32Utils::qicon_to_hicon(icon, 16, 16))
{
- if(HICON hIcon = (HICON) MUtils::Win32Utils::qicon_to_hicon(icon, 16, 16))
+ typedef BOOL(__stdcall *SetConsoleIconFun)(HICON);
+ bool success = false;
+ if (const SetConsoleIconFun pSetConsoleIconFun = MUtils::Win32Utils::resolve<SetConsoleIconFun>(QLatin1String("kernel32"), QLatin1String("SetConsoleIcon")))
+ {
+ const DWORD before = GetLastError();
+ qWarning("[Before: 0x%08X]", before);
+ if (pSetConsoleIconFun(hIcon))
+ {
+ success = true;
+ }
+ else
+ {
+ const DWORD error = GetLastError();
+ qWarning("SetConsoleIcon() has failed! [Error: 0x%08X]", error);
+ }
+ }
+ if (!success)
+ {
+ const HWND hwndConsole = GetConsoleWindow();
+ if ((hwndConsole != NULL) && (hwndConsole != INVALID_HANDLE_VALUE))
+ {
+ SendMessage(hwndConsole, WM_SETICON, ICON_SMALL, LPARAM(hIcon));
+ success = true;
+ }
+ }
+ if (success)
{
- setConsoleIconFun(hIcon);
- DestroyIcon(hIcon);
+ set_hicon(&g_terminal_icon, hIcon);
}
}
}