[Bf-blender-cvs] [3d40e3f] master: Fix console incorrectly showing on Windows Blender startup in some cases.

Masakazu Ito noreply at git.blender.org
Tue Dec 31 00:18:27 CET 2013


Commit: 3d40e3f9dbf60e21a49429218bad68836b014e5d
Author: Masakazu Ito
Date:   Tue Dec 31 00:08:07 2013 +0100
https://developer.blender.org/rB3d40e3f9dbf60e21a49429218bad68836b014e5d

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

===================================================================

M	intern/ghost/intern/GHOST_SystemWin32.cpp

===================================================================

diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp
index ebb419b..09d9fdf 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;




More information about the Bf-blender-cvs mailing list