forked from NASAWorldWind/WorldWindJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWinUtil.cpp
More file actions
61 lines (49 loc) · 1.65 KB
/
WinUtil.cpp
File metadata and controls
61 lines (49 loc) · 1.65 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* Copyright (C) 2012 United States Government as represented by the Administrator of the
* National Aeronautics and Space Administration.
* All Rights Reserved.
*/
#include "../stdafx.h"
#include "WinUtil.h"
struct EnumWindowsArg {
wchar_t *windowClass;
HWND foundWindow;
};
/**
* Callback function invoked by EnumWindows.
*/
BOOL CALLBACK findChildWindowProc(HWND hWnd, LPARAM lparam)
{
const int BUFFER_SIZE = 256;
wchar_t windowClass[BUFFER_SIZE];
struct EnumWindowsArg *arg = (struct EnumWindowsArg*)lparam;
assert(arg != NULL && "Invalid argument to findChildWindowProc");
wchar_t *targetWindow = (wchar_t*)arg->windowClass;
assert(targetWindow != NULL && "Target window class is NULL");
int ret = GetClassName(hWnd, windowClass, BUFFER_SIZE);
assert(ret != 0 && "Failed to get class name of window");
// Search for the target string at the start of the window title
//wchar_t *match = wcsstr(arg->windowClass, targetWindow);
if (wcscmp(arg->windowClass, windowClass) == 0)
{
arg->foundWindow = hWnd;
return FALSE;
}
return TRUE;
}
HWND FindChildWindow(HWND parentWnd, wchar_t *windowClass)
{
struct EnumWindowsArg arg;
arg.windowClass = windowClass;
arg.foundWindow = NULL;
EnumChildWindows(parentWnd, findChildWindowProc, reinterpret_cast<LPARAM>(&arg));
return arg.foundWindow;
}
HWND FindThreadWindow(DWORD threadId, wchar_t *windowClass)
{
struct EnumWindowsArg arg;
arg.windowClass = windowClass;
arg.foundWindow = NULL;
EnumThreadWindows(threadId, findChildWindowProc, reinterpret_cast<LPARAM>(&arg));
return arg.foundWindow;
}