forked from sinjs/HideTaskbar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHideTaskbar.cpp
More file actions
74 lines (56 loc) · 2.07 KB
/
HideTaskbar.cpp
File metadata and controls
74 lines (56 loc) · 2.07 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
#include <string>
#include <vector>
#include <Windows.h>
#include <print>
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 (GetClassNameW(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) {
SetWindowAlpha(handle, hidden ? ALPHA_HIDE : ALPHA_SHOW);
}
}
int main(int argc, char* argv[])
{
std::string hide {"--hide"};
std::string show {"--show"};
if(argv[1] != nullptr && (argv[1] != hide && argv[1] != show)){
std::print("Ingresar un argumento válido:\n\t--hide, Sin argumentos\tEsconder la barra de tareas\n\t--show\t\t\tMostrar la barra de tareas\n");
return 0;
}
if (argv[1] == nullptr || argv[1] == hide) {
SetTaskbarsHidden(true);
return 0;
}
if (argv[1] == show) {
SetTaskbarsHidden(false);
return 0;
}
}