This repository has been archived by the owner on May 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
get-visible-windows.cpp
55 lines (48 loc) · 1.82 KB
/
get-visible-windows.cpp
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
// This code is a part of MagicCap which is a MPL-2.0 licensed project.
// Copyright (C) Jake Gealer <[email protected]> 2019.
#include <stdio.h>
#ifdef _WIN32
#include <Windows.h>
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM _)
{
if (IsWindowVisible(hwnd))
{
RECT WindowRect;
GetWindowRect(hwnd, &WindowRect);
printf("%i %i %i %i\n", (int)WindowRect.left, (int)WindowRect.top, (int)WindowRect.right - (int)WindowRect.left, (int)WindowRect.bottom - (int)WindowRect.top);
}
return true;
}
int main()
{
EnumWindows(EnumWindowsProc, 0);
return 0;
}
#elif __APPLE__
#include <ApplicationServices/ApplicationServices.h>
#include <string.h>
int main()
{
CFArrayRef WindowList = CGWindowListCopyWindowInfo(kCGWindowListExcludeDesktopElements | kCGWindowListOptionOnScreenAboveWindow, kCGNullWindowID);
int ArrLength = CFArrayGetCount(WindowList);
for (int i = 0; i < ArrLength; ++i) {
CFDictionaryRef ProcessRef = (CFDictionaryRef)CFArrayGetValueAtIndex(WindowList, i);
const char *WindowName = CFStringGetCStringPtr((CFStringRef)CFDictionaryGetValue(ProcessRef, kCGWindowName), kCFStringEncodingUTF8);
if (WindowName != NULL && strcmp(WindowName, "Dock") == 0) {
continue;
}
CFBooleanRef WindowBool = reinterpret_cast<CFBooleanRef>(CFDictionaryGetValue(ProcessRef, kCGWindowIsOnscreen));
if (WindowBool != NULL && CFBooleanGetValue(WindowBool) == true) {
CGRect ItemBounds;
CGRectMakeWithDictionaryRepresentation((CFDictionaryRef)CFDictionaryGetValue(ProcessRef, kCGWindowBounds), &ItemBounds);
printf("%i %i %i %i\n", (int)ItemBounds.origin.x, (int)ItemBounds.origin.y, (int)ItemBounds.size.width, (int)ItemBounds.size.height);
}
}
return 0;
}
#else
int main()
{
return 0;
}
#endif