2 * $Id: uiutil.c,v 1.1 2001/09/05 19:10:01 cwolf Exp $
5 * Get the window handle of the controlling console of a console-mode
8 * This came right off Microsoft's MSDN library, so I doubt there's
9 * less kludgy way to handle this.
11 #define MY_BUFSIZE 1024 // Buffer size for console window titles.
13 HWND
getConsoleWindow()
15 HWND hwndFound
; // This is what is returned to the caller.
16 char pszNewWindowTitle
[MY_BUFSIZE
]; // Contains fabricated
18 char pszOldWindowTitle
[MY_BUFSIZE
]; // Contains original
21 // Fetch current window title.
22 GetConsoleTitle(pszOldWindowTitle
, MY_BUFSIZE
);
24 // Format a "unique" NewWindowTitle.
25 (void)wsprintf(pszNewWindowTitle
,"%d/%d", GetTickCount(),
26 GetCurrentProcessId());
28 // Change current window title.
29 SetConsoleTitle(pszNewWindowTitle
);
31 // Ensure window title has been updated.
34 // Look for NewWindowTitle.
35 hwndFound
=FindWindow(NULL
, pszNewWindowTitle
);
37 // Restore original window title.
38 SetConsoleTitle(pszOldWindowTitle
);