Created
July 3, 2015 11:05
-
-
Save suzukiplan/f3c0fda8cefe2ffd6619 to your computer and use it in GitHub Desktop.
get console hwnd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Windows.h> | |
#include <stdio.h> | |
HWND GetConsoleHwnd(void) | |
{ | |
#define MY_BUFSIZE 1024 | |
HWND hwndFound; | |
char pszNewWindowTitle[MY_BUFSIZE]; | |
char pszOldWindowTitle[MY_BUFSIZE]; | |
GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE); | |
wsprintf(pszNewWindowTitle,"%d/%d",GetTickCount(),GetCurrentProcessId()); | |
SetConsoleTitle(pszNewWindowTitle); | |
Sleep(40); | |
hwndFound=FindWindow(NULL, pszNewWindowTitle); | |
SetConsoleTitle(pszOldWindowTitle); | |
return hwndFound; | |
} | |
int main() | |
{ | |
printf("%p\n", GetConsoleHwnd()); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment