-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRadSwitch.cpp
642 lines (553 loc) · 20 KB
/
RadSwitch.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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
#include "Rad/Window.h"
#include "Rad/Windowxx.h"
#include <CommCtrl.h>
#include <Shlwapi.h>
#include <Shellapi.h>
#include <dwmapi.h>
#include <appmodel.h>
#include <algorithm>
#include <vector>
#include <iterator>
//#include <tchar.h>
#include "WindowsPlus.h"
#include "ListBoxPlus.h"
#include "UWPApps.h"
#include "Rad/AboutDlg.h"
#include "resource.h"
extern HINSTANCE g_hInstance;
Theme g_Theme;
#define HK_1_MOD (MOD_ALT | MOD_CONTROL | MOD_SHIFT)
#define HK_1_KEY (VK_OEM_FJ_TOUROKU)
#define HK_1 (100)
#define HK_2_MOD (MOD_ALT | MOD_CONTROL | MOD_SHIFT)
#define HK_2_KEY (VK_OEM_FJ_MASSHOU)
#define HK_2 (200)
static HHOOK g_hHook{ NULL };
static HWND g_hWnd{ NULL };
#define WM_START (WM_USER + 124)
#define WM_STOP (WM_USER + 532)
#define LIST_ID 101
inline bool IsTaskSwitcher(HWND hWnd)
{
TCHAR strClass[1024];
GetClassName(hWnd, strClass, ARRAYSIZE(strClass));
return lstrcmp(strClass, TEXT("MultitaskingViewFrame")) == 0;
}
inline bool IsKeyDown(_In_ int nVirtKey)
{
return GetKeyState(nVirtKey) < 0;
}
inline void ShowLastError(LPCTSTR msg, LPCTSTR function)
{
TCHAR fullmsg[1024];
wsprintf(fullmsg, TEXT("%s - Failed in %s"), msg, function);
MessageBox(g_hWnd, fullmsg, TEXT("Rad Switch"), MB_OK | MB_ICONERROR);
}
#define CHECK(x) if (!(x)) ShowLastError(TEXT(#x), TEXT(__FUNCTION__));
#if 0
void ForceForegroundWindow(HWND hWnd)
{
DWORD windowThreadProcessId = GetWindowThreadProcessId(GetForegroundWindow(), nullptr);
DWORD currentThreadId = GetCurrentThreadId();
if (AttachThreadInput(windowThreadProcessId, currentThreadId, true))
{
CHECK(BringWindowToTop(hWnd));
ShowWindow(hWnd, SW_SHOW);
CHECK(SetForegroundWindow(hWnd));
AttachThreadInput(windowThreadProcessId, currentThreadId, false);
}
else
{
DWORD timeout = 0;
DWORD zero = 0;
SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, &timeout, 0);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, &zero, 0);
CHECK(BringWindowToTop(hWnd));
ShowWindow(hWnd, SW_SHOW);
SetForegroundWindow(hWnd);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, &timeout, 0);
}
}
#endif
inline RECT CalcSizeListBox(HWND hWndLB, LONG max)
{
const int iItemHeight = ListBox_GetItemHeight(hWndLB, 0);
const int iItemCount = ListBox_GetCount(hWndLB);
RECT rc;
GetClientRect(hWndLB, &rc);
rc.bottom = rc.top + iItemHeight * std::min<LONG>(iItemCount, max / iItemHeight);
AdjustWindowRect(&rc, GetWindowStyle(hWndLB), FALSE);
return rc;
}
inline int ListBox_WrapIndex(HWND hWnd, int i)
{
const int count = ListBox_GetCount(hWnd);
if (i < 0)
i += count;
if (i >= count)
i -= count;
return i;
}
inline HANDLE GetProcessHandleFromHwnd(HWND hWnd)
{
DWORD pid = 0;
if (GetWindowThreadProcessId(hWnd, &pid) == 0)
return NULL;
return OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid);
}
inline BOOL QueryFullProcessImageNameFromHwnd(HWND hWnd, _Out_writes_to_(dwSize, dwSize) LPTSTR lpExeName, _Inout_ DWORD dwSize)
{
lpExeName[0] = TEXT('\0');
HANDLE hProcess = GetProcessHandleFromHwnd(hWnd);
if (hProcess == NULL)
return FALSE;
QueryFullProcessImageName(hProcess, 0, lpExeName, &dwSize);
CloseHandle(hProcess);
return TRUE;
}
void GetProductName(LPCTSTR strFileName, LPTSTR lpszBuffer)
{
DWORD Dummy = 0;
DWORD Size = GetFileVersionInfoSize(strFileName, &Dummy);
if (Size <= 0)
return;
void* Info = malloc(Size);
if (Info == nullptr)
return;
GetFileVersionInfoEx(FILE_VER_GET_LOCALISED, strFileName, 0, Size, Info);
struct LANGANDCODEPAGE
{
WORD wLanguage;
WORD wCodePage;
} *lpTranslate;
UINT cbTranslate;
VerQueryValue(Info, TEXT("\\VarFileInfo\\Translation"), (LPVOID*) &lpTranslate, &cbTranslate);
for (int i = 0; i < (int) (cbTranslate / sizeof(struct LANGANDCODEPAGE)); i++)
{
TCHAR SubBlock[50];
TCHAR* String;
UINT Length;
String = nullptr;
//_stprintf_s(SubBlock, TEXT("\\StringFileInfo\\%04x%04x\\FileDescription"), lpTranslate[i].wLanguage, lpTranslate[i].wCodePage);
swprintf_s(SubBlock, TEXT("\\StringFileInfo\\%04x%04x\\FileDescription"), lpTranslate[i].wLanguage, lpTranslate[i].wCodePage);
VerQueryValue(Info, SubBlock, (LPVOID*) &String, &Length);
if (String != nullptr)
{
//_tcscpy_s(lpszBuffer, String);
lstrcpy(lpszBuffer, String);
break;
}
}
free(Info);
}
static LRESULT CALLBACK KeyboardllHook(const int nCode, const WPARAM wParam, const LPARAM lParam)
{
if (nCode >= 0 && g_hWnd != NULL)
{
const KBDLLHOOKSTRUCT* kbdStruct = (KBDLLHOOKSTRUCT*) lParam;
static bool bCloseWhenRelease = false;
switch (wParam)
{
case WM_KEYDOWN: case WM_SYSKEYDOWN:
if (IsKeyDown(VK_MENU) && !IsTaskSwitcher(GetForegroundWindow()))
{
if (GetForegroundWindow() == g_hWnd)
{
PostMessage(GetFocus(), WM_KEYDOWN, kbdStruct->vkCode, 0); // TODO Set lParam
if (kbdStruct->vkCode == VK_TAB || kbdStruct->vkCode == VK_ESCAPE)
return 1;
}
else switch (kbdStruct->vkCode)
{
case VK_TAB:
//SendMessage(g_hWnd, WM_START, FALSE, (LPARAM) MonitorFromWindow(GetForegroundWindow(), MONITOR_DEFAULTTOPRIMARY));
bCloseWhenRelease = !IsKeyDown(VK_CONTROL);
SendHotKey(HK_1_MOD, HK_1_KEY);
return 1;
case VK_OEM_3: // Backtick
//PostMessage(g_hWnd, WM_START, TRUE, (LPARAM) MonitorFromWindow(GetForegroundWindow(), MONITOR_DEFAULTTOPRIMARY));
bCloseWhenRelease = !IsKeyDown(VK_CONTROL);
SendHotKey(HK_2_MOD, HK_2_KEY);
return 1;
}
}
break;
case WM_KEYUP: case WM_SYSKEYUP:
switch (kbdStruct->vkCode)
{
case VK_LMENU: case VK_RMENU:
{
if (bCloseWhenRelease && GetForegroundWindow() == g_hWnd)
{
PostMessage(g_hWnd, WM_STOP, 0, 0);
//return 1;
}
}
break;
}
break;
}
}
return CallNextHookEx(g_hHook, nCode, wParam, lParam);
}
RECT GetPosition(HMONITOR hMonitor)
{
MONITORINFO MonitorInfo = { sizeof(MONITORINFO) };
GetMonitorInfo(hMonitor, &MonitorInfo);
RECT r(MonitorInfo.rcMonitor);
InflateRect(&r, Width(MonitorInfo.rcMonitor) / -4, Height(MonitorInfo.rcMonitor) / -3);
return r;
}
class RootWindow : public Window
{
friend WindowManager<RootWindow>;
public:
static bool IsExisting() { return FindWindow(ClassName(), nullptr) != NULL; }
static ATOM Register() { return WindowManager<RootWindow>::Register(); }
static RootWindow* Create() { return WindowManager<RootWindow>::Create(); }
protected:
static void GetCreateWindow(CREATESTRUCT& cs);
static void GetWndClass(WNDCLASS& wc);
LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) override;
private:
BOOL OnCreate(LPCREATESTRUCT lpCreateStruct);
void OnDestroy();
void OnSize(UINT state, int cx, int cy);
void OnSetFocus(HWND hwndOldFocus);
int OnVkeyToItem(UINT vk, HWND hwndListbox, int iCaret);
void OnHotKey(int idHotKey, UINT fuModifiers, UINT vk);
void OnActivate(UINT state, HWND hwndActDeact, BOOL fMinimized);
void OnCommand(int id, HWND hWndCtl, UINT codeNotify);
HBRUSH OnCtlColor(HDC hDC, HWND hWndChild, int type);
static LPCTSTR ClassName() { return TEXT("RadSwitch"); }
void FillList(HWND hActiveWnd, BOOL FilterToActive, HMONITOR hMonitor);
void Switch(int iCaret);
ListBoxOwnerDrawnFixed m_hWndChild;
BOOL m_FilterToActive = FALSE;
HMONITOR m_hMonitor = NULL;
};
void RootWindow::GetCreateWindow(CREATESTRUCT& cs)
{
Window::GetCreateWindow(cs);
cs.lpszName = TEXT("Rad Switch");
cs.style = WS_POPUP | WS_BORDER;
cs.dwExStyle |= WS_EX_TOPMOST | WS_EX_TOOLWINDOW;
}
void RootWindow::GetWndClass(WNDCLASS& wc)
{
Window::GetWndClass(wc);
wc.hIcon = LoadIcon(wc.hInstance, MAKEINTRESOURCE(IDI_MAIN));
wc.hbrBackground = g_Theme.brWindow;
}
BOOL RootWindow::OnCreate(const LPCREATESTRUCT lpCreateStruct)
{
SetWindowBlur(*this);
RECT r;
GetWindowRect(*this, &r);
m_hWndChild.Create(*this, WS_CHILD | WS_VISIBLE | WS_VSCROLL | LBS_HASSTRINGS | LBS_WANTKEYBOARDINPUT | LBS_OWNERDRAWFIXED | LBS_NOTIFY, r, LIST_ID);
CHECK(RegisterHotKey(*this, HK_1, HK_1_MOD, HK_1_KEY));
CHECK(RegisterHotKey(*this, HK_2, HK_2_MOD, HK_2_KEY));
g_hWnd = *this;
g_hHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardllHook, NULL, 0);
//g_hHook2 = SetWindowsHookEx(WH_SHELL, ShellHook, NULL, 0); // TODO
return TRUE;
}
void RootWindow::OnDestroy()
{
PostQuitMessage(0);
UnhookWindowsHookEx(g_hHook);
g_hWnd = NULL;
}
void RootWindow::OnSize(const UINT state, const int cx, const int cy)
{
if (m_hWndChild)
{
SetWindowPos(m_hWndChild, NULL,
0, 0, cx, cy,
SWP_NOZORDER | SWP_NOACTIVATE);
}
}
void RootWindow::OnSetFocus(const HWND hWndOldFocus)
{
if (m_hWndChild)
SetFocus(m_hWndChild);
}
int RootWindow::OnVkeyToItem(UINT vk, HWND hWndListbox, int iCaret)
{
if (hWndListbox == m_hWndChild)
{
SetHandled(true);
switch (vk)
{
case VK_TAB: case VK_OEM_3:
m_hWndChild.SetCurSel(ListBox_WrapIndex(m_hWndChild, iCaret + (IsKeyDown(VK_SHIFT) ? -1 : +1)));
return -2;
case VK_ESCAPE:
ShowWindow(*this, SW_HIDE);
return -2;
case VK_RETURN: case VK_SPACE:
Switch(iCaret);
return -2;
case VK_LEFT:
{
ShowWindow(*this, SW_HIDE);
const std::vector<HMONITOR> ms = GetMonitors();
const auto itOrig = std::find(ms.begin(), ms.end(), m_hMonitor);
if (itOrig == ms.end())
SendMessage(g_hWnd, WM_START, m_FilterToActive, (LPARAM) GetPrimaryMonitor(ms));
else
{
auto it = itOrig;
do
{
it = it == ms.begin() ? ms.end() - 1 : std::prev(it);
if (SendMessage(g_hWnd, WM_START, m_FilterToActive, (LPARAM) *it))
break;
} while (it != itOrig);
}
return -2;
}
case VK_RIGHT:
{
ShowWindow(*this, SW_HIDE);
const std::vector<HMONITOR> ms = GetMonitors();
const auto itOrig = std::find(ms.begin(), ms.end(), m_hMonitor);
if (itOrig == ms.end())
SendMessage(g_hWnd, WM_START, m_FilterToActive, (LPARAM) GetPrimaryMonitor(ms));
else
{
auto it = itOrig;
do
{
it = it == (ms.end() - 1) ? ms.begin() : std::next(it);
if (SendMessage(g_hWnd, WM_START, m_FilterToActive, (LPARAM) *it))
break;
} while (it != itOrig);
}
return -2;
}
case VK_F1:
AboutDlg::DoModal(*this);
return -2;
default:
return -1;
}
}
else
return -1;
}
void RootWindow::OnHotKey(int idHotKey, UINT fuModifiers, UINT vk)
{
switch (idHotKey)
{
case HK_1: if (GetForegroundWindow() != *this) PostMessage(g_hWnd, WM_START, FALSE, (LPARAM) MonitorFromWindow(GetForegroundWindow(), MONITOR_DEFAULTTOPRIMARY)); break;
case HK_2: if (GetForegroundWindow() != *this) PostMessage(g_hWnd, WM_START, TRUE, (LPARAM) MonitorFromWindow(GetForegroundWindow(), MONITOR_DEFAULTTOPRIMARY)); break;
}
}
void RootWindow::OnActivate(UINT state, HWND hwndActDeact, BOOL fMinimized)
{
if (!state)
ShowWindow(*this, SW_HIDE);
}
void RootWindow::OnCommand(int id, HWND hWndCtl, UINT codeNotify)
{
switch (id)
{
case LIST_ID:
switch (codeNotify)
{
case LBN_DBLCLK:
Switch(m_hWndChild.GetCurSel());
}
break;
}
}
HBRUSH RootWindow::OnCtlColor(HDC hDC, HWND hWndChild, int type)
{
return g_Theme.brWindow;
}
LRESULT RootWindow::HandleMessage(const UINT uMsg, const WPARAM wParam, const LPARAM lParam)
{
LRESULT ret = 0;
switch (uMsg)
{
HANDLE_MSG(WM_CREATE, OnCreate);
HANDLE_MSG(WM_DESTROY, OnDestroy);
HANDLE_MSG(WM_SIZE, OnSize);
HANDLE_MSG(WM_SETFOCUS, OnSetFocus);
HANDLE_MSG(WM_VKEYTOITEM, OnVkeyToItem);
HANDLE_MSG(WM_HOTKEY, OnHotKey);
HANDLE_MSG(WM_ACTIVATE, OnActivate);
HANDLE_MSG(WM_COMMAND, OnCommand);
HANDLE_MSG(WM_CTLCOLORLISTBOX, OnCtlColor);
case WM_START:
{
SetHandled(TRUE);
const HWND hActiveWnd = GetAncestor(GetForegroundWindow(), GA_ROOTOWNER);
m_FilterToActive = (BOOL) wParam;
m_hMonitor = (HMONITOR) lParam;
FillList(hActiveWnd, m_FilterToActive, m_hMonitor);
if (m_hWndChild.GetCount() > 0) // TODO Maybe > 1
{
if (true)
{
RECT rcWnd(GetPosition(m_hMonitor));
const RECT rcList = CalcSizeListBox(m_hWndChild, Height(rcWnd));
rcWnd.bottom = rcWnd.top + Height(rcList);
AdjustWindowRect(&rcWnd, GetWindowStyle(*this), FALSE);
SetWindowPos(*this, NULL,
rcWnd.left, rcWnd.top, Width(rcWnd), Height(rcWnd),
SWP_NOZORDER | SWP_NOACTIVATE);
}
#if 1
ShowWindow(*this, SW_SHOW);
CHECK(BringWindowToTop(*this));
CHECK(SetForegroundWindow(*this));
#else
ForceForegroundWindow(*this);
#endif
ret = TRUE;
}
}
break;
case WM_STOP:
Switch(m_hWndChild.GetCurSel());
break;
}
if (!IsHandled())
ret = m_hWndChild.HandleChainMessage(uMsg, wParam, lParam);
if (!IsHandled())
ret = Window::HandleMessage(uMsg, wParam, lParam);
return ret;
}
void RootWindow::FillList(HWND hActiveWnd, BOOL FilterToActive, HMONITOR hMonitor)
{
TCHAR strActiveExe[MAX_PATH]{ TEXT("") };
if (!FilterToActive || !QueryFullProcessImageNameFromHwnd(hActiveWnd, strActiveExe, ARRAYSIZE(strActiveExe)))
strActiveExe[0] = TEXT('\0');
const std::vector<HWND> w = GetWindows();
int selected = -1;
m_hWndChild.ResetContent();
for (const HWND hWnd : w)
{
if (hWnd != *this)
{
// TODO Filter to this Virtual Desktop
// TODO Filter to this Monitor
UINT CloakedVal;
DwmGetWindowAttribute(hWnd, DWMWA_CLOAKED, &CloakedVal, sizeof(CloakedVal));
const DWORD dwStyle = GetWindowStyle(hWnd);
const DWORD dwExStyle = GetWindowExStyle(hWnd);
if (IsWindowVisible(hWnd)
&& (CloakedVal == 0)
&& NoneSet(dwExStyle, WS_EX_TOOLWINDOW)
&& (GetWindow(hWnd, GW_OWNER) == NULL)
&& (hMonitor == NULL || MonitorFromWindow(hWnd, MONITOR_DEFAULTTOPRIMARY) == hMonitor))
{
HWND hActualWnd = hWnd;
TCHAR strClass[MAX_PATH] = TEXT("");
GetClassName(hWnd, strClass, ARRAYSIZE(strClass));
if (wcscmp(strClass, L"ApplicationFrameWindow") == 0)
{
DWORD pid = 0;
GetWindowThreadProcessId(hWnd, &pid);
std::vector<HWND> wc = GetWindows(hWnd);
for (const HWND hWndChild : wc)
{
DWORD pidchild = 0;
GetWindowThreadProcessId(hWndChild, &pidchild);
if (pidchild != pid)
hActualWnd = hWndChild;
}
}
TCHAR strExe[MAX_PATH] = TEXT("");
QueryFullProcessImageNameFromHwnd(hActualWnd, strExe, ARRAYSIZE(strExe));
if (FilterToActive && lstrcmp(strActiveExe, strExe) != 0)
continue;
TCHAR title[1024] = TEXT("");
GetWindowText(hActualWnd, title, ARRAYSIZE(title));
//if (IsMinimized(hWnd))
//lstrcat(title, TEXT("*"));
const std::wstring strAppId = GetAppId(hWnd);
std::wstring strDisplayName;
if (strDisplayName.empty() && !strAppId.empty())
strDisplayName = GetDisplayName(strAppId);
if (strDisplayName.empty())
{
TCHAR strProduct[1024] = TEXT("");
GetProductName(strExe, strProduct);
strDisplayName = strProduct;
}
if (strDisplayName.empty())
strDisplayName = PathFindFileName(strExe);
HICON hIcon = NULL;
if (hIcon == NULL)
hIcon = reinterpret_cast<HICON>(static_cast<INT_PTR>(MySendMessageTimeout(hActualWnd, WM_GETICON, ICON_BIG, GetSystemMetrics(SM_CXICON), SMTO_ABORTIFHUNG | SMTO_ERRORONEXIT, 100)));
//if (hIcon == NULL && hActualWnd != hWnd)
//hIcon = ExtractIcon(g_hInstance, strExe, 0);
if (hIcon == NULL && !strAppId.empty())
hIcon = GetIconForAppId(strAppId, { GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) });
if (hIcon == NULL)
hIcon = reinterpret_cast<HICON>(GetClassLongPtr(hActualWnd, GCLP_HICON));
if (hIcon == NULL)
hIcon = LoadIcon(NULL, IDI_APPLICATION);
// TODO Get an icon for UWP apps
const int i = m_hWndChild.AddString(title);
m_hWndChild.SetItemIcon(i, hIcon);
m_hWndChild.SetItemRightString(i, strDisplayName.c_str());
m_hWndChild.SetItemGray(i, IsMinimized(hActualWnd));
m_hWndChild.SetItemData(i, reinterpret_cast<LPARAM>(hWnd));
if (hActiveWnd == hWnd || hActiveWnd == GetLastActivePopup(hWnd))
selected = i;
}
}
}
m_hWndChild.SetTopIndex(0);
m_hWndChild.SetCurSel(ListBox_WrapIndex(m_hWndChild, selected + (IsKeyDown(VK_SHIFT) ? -1 : +1)));
}
void RootWindow::Switch(int iCaret)
{
HWND hWnd = reinterpret_cast<HWND>(m_hWndChild.GetItemData(iCaret));
#if 0
if (IsMinimized(hWnd))
ShowWindow(hWnd, SW_NORMAL);
HWND hWndPopup = GetLastActivePopup(hWnd);
SetForegroundWindow(hWndPopup);
#else
SwitchToThisWindow(GetLastActivePopup(hWnd), TRUE);
#endif
//ShowWindow(*this, SW_HIDE);
}
bool Run(_In_ const LPCTSTR lpCmdLine, _In_ const int nShowCmd)
{
if (RootWindow::IsExisting())
{
MessageBox(NULL, TEXT("Process already exists."), TEXT("Rad Switch"), MB_ICONERROR | MB_OK);
return false;
}
if (true)
{
g_Theme.clrWindow = RGB(0, 0, 0);
g_Theme.clrHighlight = RGB(61, 61, 61);
g_Theme.clrWindowText = RGB(250, 250, 250);
g_Theme.clrHighlightText = g_Theme.clrWindowText;
g_Theme.clrGrayText = RGB(128, 128, 128);
}
g_Theme.brWindow = CreateSolidBrush(g_Theme.clrWindow);
g_Theme.brHighlight = CreateSolidBrush(g_Theme.clrHighlight);
if (RootWindow::Register() == 0)
{
MessageBox(NULL, TEXT("Error registering window class"), TEXT("Rad Switch"), MB_ICONERROR | MB_OK);
return false;
}
RootWindow* prw = RootWindow::Create();
if (prw == nullptr)
{
MessageBox(NULL, TEXT("Error creating root window"), TEXT("Rad Switch"), MB_ICONERROR | MB_OK);
return false;
}
// Needed to allow to capture foreground
//ShowWindow(*prw, nShowCmd);
//ShowWindow(*prw, SW_HIDE);
return true;
}