2
2
#include < windows.h>
3
3
4
4
BOOL CALLBACK EnumWindowsProc (HWND hwnd, LPARAM lparam) {
5
- std::vector<int64_t >* windowHandles = reinterpret_cast <std::vector<int64_t >*>(lparam);
5
+ std::vector<WindowHandle >* windowHandles = reinterpret_cast <std::vector<WindowHandle >*>(lparam);
6
6
if (windowHandles != nullptr ) {
7
- windowHandles->push_back (reinterpret_cast <int64_t >(hwnd));
7
+ windowHandles->push_back (reinterpret_cast <WindowHandle >(hwnd));
8
8
}
9
9
return TRUE ;
10
10
}
11
11
12
- std::vector<int64_t > getWindows () {
13
- std::vector<int64_t > windowHandles;
12
+ std::vector<WindowHandle > getWindows () {
13
+ std::vector<WindowHandle > windowHandles;
14
14
15
15
EnumWindows (&EnumWindowsProc, reinterpret_cast <LPARAM>(&windowHandles));
16
16
17
17
return windowHandles;
18
18
}
19
19
20
- MMRect getWindowRect (const int64_t windowHandle) {
20
+ MMRect getWindowRect (const WindowHandle windowHandle) {
21
21
HWND hWnd = reinterpret_cast <HWND>(windowHandle);
22
22
RECT windowRect;
23
- GetWindowRect (hWnd, &windowRect);
24
- return MMRectMake (windowRect.left , windowRect.top , windowRect.right - windowRect.left , windowRect.bottom - windowRect.top );
23
+ if (GetWindowRect (hWnd, &windowRect)) {
24
+ return MMRectMake (windowRect.left , windowRect.top , windowRect.right - windowRect.left , windowRect.bottom - windowRect.top );
25
+ }
26
+ return MMRectMake (0 , 0 , 0 , 0 );
25
27
}
26
28
27
- std::string getWindowTitle (const int64_t windowHandle) {
29
+ std::string getWindowTitle (const WindowHandle windowHandle) {
28
30
HWND hWnd = reinterpret_cast <HWND>(windowHandle);
29
31
auto BUFFER_SIZE = GetWindowTextLength (hWnd) + 1 ;
30
- LPSTR windowTitle = new CHAR[BUFFER_SIZE];
31
-
32
- GetWindowText (hWnd, windowTitle, BUFFER_SIZE);
33
-
34
- return std::string (windowTitle);
32
+ if (BUFFER_SIZE) {
33
+ LPSTR windowTitle = new CHAR[BUFFER_SIZE];
34
+ if (GetWindowText (hWnd, windowTitle, BUFFER_SIZE)) {
35
+ return std::string (windowTitle);
36
+ }
37
+ return " " ;
38
+ }
39
+ return " " ;
35
40
}
0 commit comments