diff options
author | Masakazu Ito <sakasama@mtc.biglobe.ne.jp> | 2013-12-31 03:08:07 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2013-12-31 03:17:38 +0400 |
commit | 3d40e3f9dbf60e21a49429218bad68836b014e5d (patch) | |
tree | f92cf35c00523f0a5a60212a7fb0779e1e20eab1 /intern | |
parent | a1c740a420ca1d6e10e91154247dc85eafe95e1d (diff) |
Fix console incorrectly showing on Windows Blender startup in some cases.
The console window is hidden by default, but we need to avoid this when
starting from the command prompt, because it would hide the window you just
typed the command in.
Previously it would check if Blender was started from "explorer.exe" to
determine that, but that wasn't working for application launchers like
Appetizer or Colibri. Instead we now check if the process ID is the same as
the process ID of the console window, which appears to work reliably.
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D122
Diffstat (limited to 'intern')
-rw-r--r-- | intern/ghost/intern/GHOST_SystemWin32.cpp | 52 |
1 files changed, 23 insertions, 29 deletions
diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp index ebb419b6c04..09d9fdfc493 100644 --- a/intern/ghost/intern/GHOST_SystemWin32.cpp +++ b/intern/ghost/intern/GHOST_SystemWin32.cpp @@ -1386,49 +1386,43 @@ void GHOST_SystemWin32::putClipboard(GHOST_TInt8 *buffer, bool selection) const } } +static bool isStartedFromCommandPrompt() +{ + HWND hwnd = GetConsoleWindow(); + + if (hwnd) { + DWORD pid = (DWORD)-1; + + GetWindowThreadProcessId(hwnd, &pid); + + if (pid == GetCurrentProcessId()) + return true; + } + + return false; +} + int GHOST_SystemWin32::toggleConsole(int action) { switch (action) { - case 3: //hide if no console + case 3: // startup: hide if not started from command prompt { - DWORD sp = GetCurrentProcessId(); - HANDLE ptree = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); - PROCESSENTRY32 e = {0}; e.dwSize = sizeof(PROCESSENTRY32); - - if (Process32First(ptree, &e)) { - do { //Searches for Blender's PROCESSENTRY32 - if (e.th32ProcessID == sp) { - sp = e.th32ParentProcessID; - Process32First(ptree, &e); - do { //Got parent id, searches for its PROCESSENTRY32 - if (e.th32ProcessID == sp) { - if (strcmp("explorer.exe", e.szExeFile) == 0) - { //If explorer, hide cmd - ShowWindow(GetConsoleWindow(), SW_HIDE); - m_consoleStatus = 0; - } - break; - } - - } while (Process32Next(ptree, &e)); - break; - } - } while (Process32Next(ptree, &e)); + if (isStartedFromCommandPrompt()) { + ShowWindow(GetConsoleWindow(), SW_HIDE); + m_consoleStatus = 0; } - - CloseHandle(ptree); break; } - case 0: //hide + case 0: // hide ShowWindow(GetConsoleWindow(), SW_HIDE); m_consoleStatus = 0; break; - case 1: //show + case 1: // show ShowWindow(GetConsoleWindow(), SW_SHOW); m_consoleStatus = 1; break; - case 2: //toggle + case 2: // toggle ShowWindow(GetConsoleWindow(), m_consoleStatus ? SW_HIDE : SW_SHOW); m_consoleStatus = !m_consoleStatus; break; |