-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginHideTaskbar.cpp
More file actions
157 lines (138 loc) · 3.61 KB
/
PluginHideTaskbar.cpp
File metadata and controls
157 lines (138 loc) · 3.61 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
Copyright (C) 2016 Jeffrey Morley
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <Windows.h>
#include <cstdio>
#include "../../API/RainmeterAPI.h"
#include <shellapi.h>
// This isn't defined for me for some reason.
#ifndef ABM_SETSTATE
#define ABM_SETSTATE 0x0000000A
#define ABM_WINDOWPOSCHANGED 0x00000009
#endif
enum Instance
{
BOTH,
FIRST,
SECOND
};
struct Measure
{
Instance type;
void* rm;
Measure() : type(BOTH), rm() {}
};
PLUGIN_EXPORT void Initialize(void** data, void* rm)
{
Measure* measure = new Measure;
*data = measure;
measure->rm = rm;
}
PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
{
Measure* measure = (Measure*)data;
LPCWSTR barInstance = RmReadString(rm, L"BARINSTANCE", L"Both");
if (_wcsicmp(barInstance, L"BOTH") == 0)
{
measure->type = BOTH;
}
if (_wcsicmp(barInstance, L"FIRST") == 0)
{
measure->type = FIRST;
}
if (_wcsicmp(barInstance, L"SECOND") == 0)
{
measure->type = SECOND;
}
}
PLUGIN_EXPORT double Update(void* data)
{
Measure* measure = (Measure*)data;
double currentState = 0.0;
APPBARDATA abd = { sizeof abd };
UINT uState = (UINT)SHAppBarMessage(ABM_GETSTATE, &abd);
HWND hwnd = FindWindow(L"Shell_traywnd", L"");
switch (measure->type)
{
case BOTH:
hwnd = FindWindow(L"Shell_traywnd", L"");
break;
case FIRST:
hwnd = FindWindow(L"Shell_traywnd", L"");
break;
case SECOND:
hwnd = FindWindow(L"Shell_SecondaryTrayWnd", L"");
break;
}
currentState = (uState & ABS_AUTOHIDE) ? 2 : 1;
return (!IsWindowVisible(hwnd)) ? -currentState : currentState;
}
PLUGIN_EXPORT void ExecuteBang(void* data, LPCWSTR args)
{
Measure* measure = (Measure*)data;
APPBARDATA abd = { sizeof abd };
HWND hwnd = FindWindow(L"Shell_traywnd", L"");
HWND hwnd2 = FindWindow(L"Shell_SecondaryTrayWnd", L"");
if (_wcsicmp(args, L"HIDE") == 0)
{
if (measure->type == BOTH)
{
ShowWindow(hwnd, 0);
ShowWindow(hwnd2, 0);
}
else if (measure->type == FIRST)
{
ShowWindow(hwnd, 0);
}
else if (measure->type == SECOND)
{
ShowWindow(hwnd2, 0);
}
}
else if (_wcsicmp(args, L"SHOW") == 0)
{
if (measure->type == BOTH)
{
ShowWindow(hwnd, 8);
ShowWindow(hwnd2, 8);
}
else if (measure->type == FIRST)
{
ShowWindow(hwnd, 8);
}
else if (measure->type == SECOND)
{
ShowWindow(hwnd2, 8);
}
}
else if (_wcsicmp(args, L"AUTOHIDE") == 0)
{
abd.lParam = ABS_AUTOHIDE;
SHAppBarMessage(ABM_SETSTATE, &abd);
SHAppBarMessage(ABM_WINDOWPOSCHANGED, &abd);
}
else if (_wcsicmp(args, L"ALWAYSSHOW") == 0)
{
abd.lParam = ABS_ALWAYSONTOP;
SHAppBarMessage(ABM_SETSTATE, &abd);
SHAppBarMessage(ABM_WINDOWPOSCHANGED, &abd);
}
else
RmLogF(measure->rm, LOG_WARNING, L"HideTaskbar: Invalid command: %s", args);
}
PLUGIN_EXPORT void Finalize(void* data)
{
Measure* measure = (Measure*)data;
delete measure;
}