-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwconwin.c
More file actions
33 lines (26 loc) · 757 Bytes
/
Copy pathwconwin.c
File metadata and controls
33 lines (26 loc) · 757 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <wconsole.h>
#if _WIN32_WINNT < 0x0500
static BOOL CALLBACK GetConsoleWindowProc(HWND hWnd, LPARAM lParam)
{
const char cConsoleClassName[] = "ConsoleWindowClass";
DWORD dwPid = (DWORD)-1;
char cBuf[sizeof(cConsoleClassName)] = "";
GetWindowThreadProcessId(hWnd, &dwPid);
if (dwPid != GetCurrentProcessId())
return TRUE;
if (GetClassName(hWnd, cBuf, sizeof cBuf) != sizeof(cConsoleClassName)-1)
return TRUE;
if (strcmp(cConsoleClassName, cBuf) != 0)
return TRUE;
*(HWND*)lParam = hWnd;
return FALSE;
}
HWND WINAPI GetConsoleWindow()
{
HWND hWnd = NULL;
EnumWindows((WNDENUMPROC)GetConsoleWindowProc, (LPARAM)&hWnd);
return hWnd;
}
#endif