HWND GetConsoleHwnd(void)
{
#define MY_BUFSIZE 1024 // buffer size for console window titles
HWND hwndFound; // this is what is returned to the caller
char pszNewWindowTitle[MY_BUFSIZE]; // contains fabricated WindowTitle
char pszOldWindowTitle[MY_BUFSIZE]; // contains original WindowTitle
// fetch current window title
GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
// format a "unique" NewWindowTitle
wsprintf(pszNewWindowTitle,"%d/%d",
GetTickCount(),
GetCurrentProcessId());
// change current window title
SetConsoleTitle(pszNewWindowTitle);
// ensure window title has been updated
Sleep(40);
// look for NewWindowTitle
hwndFound=FindWindow(NULL, pszNewWindowTitle);
// restore original window title
SetConsoleTitle(pszOldWindowTitle);
return(hwndFound);
}
// Additional reference words: 3.10 3.50 4.00 95
// KBCategory: kbprg kbcode
// KBSubcategory: BseCon UsrWndw