Skip to content

Commit 4e92f3c

Browse files
committed
(#17) Windows implementation, WIP
1 parent c96a86a commit 4e92f3c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/win32/window_manager.cc

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include "../window_manager.h"
2+
#include <windows.h>
3+
4+
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lparam) {
5+
std::vector<int64_t>* windowHandles = reinterpret_cast<std::vector<int64_t>*>(lparam);
6+
if (windowHandles != nullptr) {
7+
windowHandles->push_back(reinterpret_cast<int64_t>(hwnd));
8+
}
9+
return TRUE;
10+
}
11+
12+
std::vector<int64_t> getWindows() {
13+
std::vector<int64_t> windowHandles;
14+
15+
EnumWindows (&EnumWindowsProc, reinterpret_cast<LPARAM>(&windowHandles));
16+
17+
return windowHandles;
18+
}
19+
20+
MMRect getWindowRect(const int64_t windowHandle) {
21+
HWND hWnd = reinterpret_cast<HWND>(windowHandle);
22+
RECT windowRect;
23+
GetWindowRect(hWnd, &windowRect);
24+
return MMRectMake(windowRect.left, windowRect.top, windowRect.right - windowRect.left, windowRect.bottom - windowRect.top);
25+
}
26+
27+
std::string getWindowTitle(const int64_t windowHandle) {
28+
HWND hWnd = reinterpret_cast<HWND>(windowHandle);
29+
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);
35+
}

0 commit comments

Comments
 (0)