Skip to content

Instantly share code, notes, and snippets.

@suzukiplan
Created July 3, 2015 11:05
Show Gist options
  • Save suzukiplan/f3c0fda8cefe2ffd6619 to your computer and use it in GitHub Desktop.
Save suzukiplan/f3c0fda8cefe2ffd6619 to your computer and use it in GitHub Desktop.
get console hwnd
#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