-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
97 lines (90 loc) · 2.83 KB
/
main.c
File metadata and controls
97 lines (90 loc) · 2.83 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <windows.h>
#define MAX_TITLE_LEN 256
void* MainThread(void *arg);
void SetTitle(HWND hwnd);
void RestoreTitle(HWND hwnd);
int main(int argc, char** argv)
{
MainThread(NULL);
return 0;
}
void* MainThread(void *arg)
{
BOOL bWasPressed = FALSE;
int totalWindows = 1;
int *winList = malloc(totalWindows);
winList[0] = 0;
while(1)
{
Sleep(10);
if(GetAsyncKeyState(VK_LCONTROL) & GetAsyncKeyState(0x51) & 0x8000)
{
free(winList);
return NULL;
}
if(GetAsyncKeyState(VK_LCONTROL) & GetAsyncKeyState(VK_LSHIFT) & 0x8000)
{
if(bWasPressed == FALSE)
continue;
HWND hwnd = GetForegroundWindow();
BOOL addNew = TRUE;
for(int i = 0; i < totalWindows; i++)
{
if(winList[i] == GetWindowThreadProcessId(hwnd, NULL))
{
addNew = FALSE;
int *newList = malloc(totalWindows-1);
for(int x = 0, j = 0; j < totalWindows; j++)
{
if(j == i)
continue;
else
newList[x++] = winList[j];
}
free(winList);
winList = newList;
totalWindows--;
RestoreTitle(hwnd);
SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 1000, 800, SWP_NOMOVE | SWP_NOSIZE);
}
}
if(addNew == TRUE)
{
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 1000, 800, SWP_NOMOVE | SWP_NOSIZE);
if(totalWindows == 1)
{
winList[0] = GetWindowThreadProcessId(hwnd, NULL);
totalWindows++;
SetTitle(hwnd);
}
else
{
winList = realloc(winList, totalWindows + 1);
winList[totalWindows] = GetWindowThreadProcessId(hwnd, NULL);
totalWindows++;
SetTitle(hwnd);
}
}
bWasPressed = FALSE;
}
else
bWasPressed = TRUE;
}
free(winList);
}
void SetTitle(HWND hwnd)
{
char title[MAX_TITLE_LEN];
GetWindowTextA(hwnd, title, MAX_TITLE_LEN);
strncat(title, " (ONTOP)", MAX_TITLE_LEN - 1);
SetWindowTextA(hwnd, title);
}
void RestoreTitle(HWND hwnd)
{
char title[MAX_TITLE_LEN];
GetWindowTextA(hwnd, title, MAX_TITLE_LEN);
if(strstr(title, " (ONTOP)") == NULL)
return;
title[strlen(title) - strlen(" (ONTOP)")] = '\0';
SetWindowTextA(hwnd, title);
}