From 81cc7aafd55f16fe90eaab00f27c8f1bd05d1f05 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Fri, 29 Apr 2005 08:42:02 +0000 Subject: [PATCH] check that GetConsoleTitle succeeded git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9887 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/support/ChangeLog | 5 +++++ src/support/os_win32.C | 19 +++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 1c4d217066..d6bea614ae 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,8 @@ +2005-04-29 Angus Leeming + + * os_win32.C (init): Merge changes from Asger's win32_kludge.diff + file, primarily checking that GetConsoleTitle succeeded. + 2005-04-25 Angus Leeming * abort.C: diff --git a/src/support/os_win32.C b/src/support/os_win32.C index 711eeb3b94..d62b0f4f39 100644 --- a/src/support/os_win32.C +++ b/src/support/os_win32.C @@ -53,7 +53,7 @@ void os::init(int /* argc */, char * argv[]) * * #if defined (_WIN32) * # define WIN32_LEAN_AND_MEAN - * # include // for __argc,__argv + * # include // for __argc, __argv * # include // for WinMain * #endif * @@ -63,7 +63,7 @@ void os::init(int /* argc */, char * argv[]) * #if defined (_WIN32) * int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) * { - * return mymain(__argc, __argv); + * return mymain(__argc, __argv); * } * #endif * @@ -89,12 +89,15 @@ void os::init(int /* argc */, char * argv[]) // Close the console when run (probably) // not run from command prompt char WindowTitle[1024]; - HWND hwndFound; - GetConsoleTitle(WindowTitle,1024); + if (GetConsoleTitle(WindowTitle, sizeof(WindowTitle)) == 0) { + // Could not get the title, so we just leave things as they are + return; + } + if ((strcmp(WindowTitle, argv[0]) == 0) || - (strcmp(WindowTitle,"LyX") == 0)) { + (strcmp(WindowTitle, "LyX") == 0)) { // format a "unique" newWindowTitle - wsprintf(WindowTitle,"%d/%d", + wsprintf(WindowTitle, "%d/%d", GetTickCount(), GetCurrentProcessId()); // change current window title @@ -102,9 +105,9 @@ void os::init(int /* argc */, char * argv[]) // ensure window title has been updated Sleep(40); // look for newWindowTitle - hwndFound=FindWindow(NULL, WindowTitle); + HWND const hwndFound = FindWindow(NULL, WindowTitle); // If found, hide it - if ( hwndFound != NULL) + if (hwndFound != NULL) ShowWindow( hwndFound, SW_HIDE); } }