Skip to content

Commit

Permalink
Use GetConsoleWindow() to get hwnd of the console window
Browse files Browse the repository at this point in the history
GetConsoleWindow() is available since Windows 2000, and we already use
it in os_win32.c.  Using it makes our code simpler.
  • Loading branch information
k-takata committed Feb 12, 2019
1 parent 05c00c0 commit caf1135
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions src/os_mswin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1043,11 +1043,6 @@ extern HWND g_hWnd; /* This is in os_win32.c. */
static void
GetConsoleHwnd(void)
{
# define MY_BUFSIZE 1024 // Buffer size for console window titles.

char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated WindowTitle.
char pszOldWindowTitle[MY_BUFSIZE]; // Contains original WindowTitle.

/* Skip if it's already set. */
if (s_hwnd != 0)
return;
Expand All @@ -1061,17 +1056,7 @@ GetConsoleHwnd(void)
}
# endif

GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);

wsprintf(pszNewWindowTitle, "%s/%d/%d",
pszOldWindowTitle,
GetTickCount(),
GetCurrentProcessId());
SetConsoleTitle(pszNewWindowTitle);
Sleep(40);
s_hwnd = FindWindow(NULL, pszNewWindowTitle);

SetConsoleTitle(pszOldWindowTitle);
s_hwnd = GetConsoleWindow();
}

/*
Expand Down

0 comments on commit caf1135

Please sign in to comment.