-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHideTaskbar.cpp
91 lines (72 loc) · 2.22 KB
/
HideTaskbar.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
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
#include <iostream>
#include <vector>
#include <Windows.h>
const BYTE ALPHA_HIDE = 0;
const BYTE ALPHA_SHOW = 255;
std::vector<HWND> global_windows;
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) {
const std::wstring& targetClass = *reinterpret_cast<std::wstring*>(lParam);
wchar_t className[256];
if (GetClassName(hwnd, className, 256) > 0) {
if (targetClass == className) {
global_windows.push_back(hwnd);
}
}
return TRUE;
}
std::vector<HWND> FindWindowsByClass(const std::wstring& class_name) {
global_windows.clear();
EnumWindows(EnumWindowsProc, reinterpret_cast<LPARAM>(&class_name));
return global_windows;
}
void SetWindowAlpha(HWND window_handle, BYTE alpha) {
SetWindowLong(window_handle, GWL_EXSTYLE, GetWindowLong(window_handle, GWL_EXSTYLE) | WS_EX_LAYERED);
SetLayeredWindowAttributes(window_handle, 0, alpha, LWA_ALPHA);
RedrawWindow(window_handle, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
}
std::vector<HWND> GetAllTaskbarWindows() {
auto primary_windows = FindWindowsByClass(L"Shell_TrayWnd");
auto secondary_windows = FindWindowsByClass(L"Shell_SecondaryTrayWnd");
primary_windows.insert(primary_windows.end(), secondary_windows.begin(), secondary_windows.end());
return primary_windows;
}
void SetTaskbarsHidden(bool hidden) {
auto window_handles = GetAllTaskbarWindows();
for (auto handle : window_handles) {
std::cout << handle << std::endl;
SetWindowAlpha(handle, hidden ? ALPHA_HIDE : ALPHA_SHOW);
}
}
void MainLoop() {
while (true) {
Sleep(1000);
SetTaskbarsHidden(true);
}
}
#ifdef NDEBUG
int WinMain(HINSTANCE _instance_handle, HINSTANCE _prev_instance_handle, LPSTR cmd_line, int _show_cmd) {
if (cmd_line == "--hide") {
SetTaskbarsHidden(true);
return 0;
}
if (cmd_line == "--show") {
SetTaskbarsHidden(false);
return 0;
}
MainLoop();
return 0;
}
#else
int main(int argc, char* argv[])
{
if (argv[1] == "--hide") {
SetTaskbarsHidden(true);
return 0;
}
if (argv[1] == "--show") {
SetTaskbarsHidden(false);
return 0;
}
MainLoop();
}
#endif