-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
65 lines (60 loc) · 1.68 KB
/
main.c
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
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <dwmapi.h>
int revert = 0;
int setTheme(HWND hwnd, int dwm){
BOOL iconic = !dwm;
BOOL enabled = 0;
enum DWMNCRENDERINGPOLICY k = (dwm==1) ? DWMNCRP_USEWINDOWSTYLE : DWMNCRP_DISABLED;
if(DwmGetWindowAttribute(hwnd, DWMWA_NCRENDERING_ENABLED, &enabled, sizeof(enabled)) != S_OK) return -1;
if(dwm != enabled){
DwmSetWindowAttribute(
hwnd,
DWMWA_NCRENDERING_POLICY,
&k,
sizeof(k)
);
DwmSetWindowAttribute(
hwnd,
DWMWA_FORCE_ICONIC_REPRESENTATION,
&iconic,
sizeof(iconic)
);
}
return 0;
}
BOOL CALLBACK windowProc(HWND hwnd, LPARAM lparam){
setTheme(hwnd, revert);
return TRUE;
}
void CALLBACK eventProc(
HWINEVENTHOOK hWinEventHook,
DWORD event,
HWND hwnd,
LONG idObject,
LONG idChild,
DWORD idEventThread,
DWORD dwmsEventTime){
if (idObject != OBJID_WINDOW || idChild != CHILDID_SELF || event == EVENT_OBJECT_CREATE || hwnd == NULL) return;
setTheme(hwnd, revert);
return;
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){
const char* revertCmdLine = "-reverse";
revert = 0;
if(strstr(lpCmdLine, revertCmdLine) != NULL){
revert = 1;
}
EnumWindows(windowProc, 0);
HWINEVENTHOOK createEvt = SetWinEventHook(EVENT_OBJECT_CREATE, EVENT_OBJECT_CREATE, 0, eventProc, 0, 0, WINEVENT_OUTOFCONTEXT|WINEVENT_SKIPOWNPROCESS);
HWINEVENTHOOK fgEvt = SetWinEventHook(EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND, 0, eventProc, 0, 0, WINEVENT_OUTOFCONTEXT|WINEVENT_SKIPOWNPROCESS);
MSG msg;
while(GetMessage(&msg, NULL, 0, 0) > 0){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
UnhookWinEvent(createEvt);
UnhookWinEvent(fgEvt);
return 0;
}