-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStart.cpp
577 lines (488 loc) · 11.5 KB
/
Start.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
#include "Start.h"
#include "Pane.h"
#include "Resource.h"
extern HINSTANCE hDllInst;
extern BOOL fDisableMetro;
extern BOOL fHideTrayShowDesktop;
HWND hStartWnd = NULL;
HWND hRebarWnd = NULL;
HWND hTaskbarWnd = NULL;
HWND hSyslistWnd = NULL;
HWND hTrayShowDesktopWnd = NULL;
ATOM atomStart = 0;
HWND hProgmanWnd = NULL;
HWND hNetworkWnd = NULL;
HWND hOrigStartWnd = NULL;
BOOL fEnterDesktop = FALSE;
BOOL fStartEnabled = TRUE;
BOOL fMouseLeftWnd = TRUE;
BOOL fPreShowDesktop = TRUE;
HICON hStartIcon16 = NULL;
HICON hStartIcon32 = NULL;
WNDPROC wpOrigRebarProc = NULL;
WNDPROC wpOrigTaskbarProc = NULL;
WNDPROC wpOrigProgmanProc = NULL;
WNDPROC wpOrigNetworkProc = NULL;
WNDPROC wpOrigTrayShowDesktopProc = NULL;
// Start
static LRESULT CALLBACK StartProc(HWND, UINT, WPARAM, LPARAM);
void OnStartPaint();
void OnStartMouseMove();
void OnStartRButtonUp();
// Rebar
static LRESULT CALLBACK RebarProc(HWND, UINT, WPARAM, LPARAM);
void OnRebarWindowPosChanging(LPARAM);
void OnRebarWindowPosChanged(LPARAM);
// Taskbar
static LRESULT CALLBACK TaskbarProc(HWND, UINT, WPARAM, LPARAM);
void OnTaskbarEnterDesktop();
void OnTaskbarSetWindowProc();
void OnTaskbarShowEdgeui(BOOL);
// Progman
static LRESULT CALLBACK ProgmanProc(HWND, UINT, WPARAM, LPARAM);
// Network
static LRESULT CALLBACK NetworkProc(HWND, UINT, WPARAM, LPARAM);
// TrayShowDesktop
static LRESULT CALLBACK TrayShowDesktopProc(HWND, UINT, WPARAM, LPARAM);
HRESULT CreateStart(HWND hWnd)
{
HWND htray;
WNDCLASSEX wcex;
hRebarWnd = hWnd;
hTaskbarWnd = GetParent(hWnd);
htray = FindWindowEx(hTaskbarWnd, NULL, TEXT("TrayNotifyWnd"), NULL);
if (!htray)
return E_FAIL;
hTrayShowDesktopWnd = FindWindowEx(htray, NULL,
TEXT("TrayShowDesktopButtonWClass"), NULL);
if (!hTrayShowDesktopWnd)
return E_FAIL;
wpOrigTrayShowDesktopProc = (WNDPROC)SetWindowLongPtr(hTrayShowDesktopWnd,
GWLP_WNDPROC, (LONG_PTR)TrayShowDesktopProc);
if (!wpOrigTrayShowDesktopProc)
return E_FAIL;
hOrigStartWnd = FindWindowEx(hTaskbarWnd, NULL, TEXT("Start"), NULL);
if (hOrigStartWnd)
ShowWindow(hOrigStartWnd, SW_HIDE);
wpOrigRebarProc = (WNDPROC)SetWindowLongPtr(hRebarWnd, GWLP_WNDPROC,
(LONG_PTR)RebarProc);
if (!wpOrigRebarProc)
return E_FAIL;
wpOrigTaskbarProc = (WNDPROC)SetWindowLongPtr(hTaskbarWnd, GWLP_WNDPROC,
(LONG_PTR)TaskbarProc);
if (!wpOrigTaskbarProc)
return E_FAIL;
hStartIcon16 = (HICON)LoadImage(hDllInst, MAKEINTRESOURCE(IDI_START),
IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
if (!hStartIcon16)
return E_FAIL;
hStartIcon32 = (HICON)LoadImage(hDllInst, MAKEINTRESOURCE(IDI_START),
IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR);
if (!hStartIcon32)
return E_FAIL;
wcex.cbClsExtra = 0;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.cbWndExtra = 0;
wcex.hbrBackground = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hIcon = NULL;
wcex.hIconSm = NULL;
wcex.hInstance = hDllInst;
wcex.lpfnWndProc = StartProc;
wcex.lpszClassName = TEXT("Start");
wcex.lpszMenuName = NULL;
wcex.style = CS_VREDRAW | CS_HREDRAW;
atomStart = RegisterClassEx(&wcex);
if (!atomStart)
return E_FAIL;
hStartWnd = CreateWindowEx(0, TEXT("Start"), NULL,
WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
0, 0, 0, 0, hTaskbarWnd, NULL, hDllInst, NULL);
if (!hStartWnd)
return E_FAIL;
return CreatePane();
}
void ShowStart(BOOL fShow, DWORD dwBandID)
{
LRESULT index;
index = SendMessage(hRebarWnd, RB_IDTOINDEX, dwBandID, 0);
SendMessage(hRebarWnd, RB_SHOWBAND, index, FALSE); //hide this band
SendMessage(hTaskbarWnd, WM_SIZE, 0, 0);
if (hStartWnd)
ShowWindow(hStartWnd, fShow ? SW_SHOW : SW_HIDE);
}
void UpdateStart()
{
if (hStartWnd)
{
InvalidateRect(hStartWnd, NULL, TRUE);
UpdateWindow(hStartWnd);
}
}
void CloseStart()
{
ClosePane();
if (hStartWnd)
{
DestroyWindow(hStartWnd);
hStartWnd = NULL;
}
if (atomStart)
{
UnregisterClass(TEXT("Start"), hDllInst);
atomStart = 0;
}
if (hStartIcon32)
{
DestroyIcon(hStartIcon32);
hStartIcon32 = NULL;
}
if (hStartIcon16)
{
DestroyIcon(hStartIcon16);
hStartIcon16 = NULL;
}
if (wpOrigNetworkProc)
{
SetWindowLongPtr(hNetworkWnd, GWLP_WNDPROC,
(LONG_PTR)wpOrigNetworkProc);
wpOrigNetworkProc = NULL;
}
if (wpOrigProgmanProc)
{
SetWindowLongPtr(hProgmanWnd, GWLP_WNDPROC,
(LONG_PTR)wpOrigProgmanProc);
wpOrigProgmanProc = NULL;
}
if (wpOrigTaskbarProc)
{
SetWindowLongPtr(hTaskbarWnd, GWLP_WNDPROC,
(LONG_PTR)wpOrigTaskbarProc);
wpOrigTaskbarProc = NULL;
}
if (wpOrigRebarProc)
{
SetWindowLongPtr(hRebarWnd, GWLP_WNDPROC,
(LONG_PTR)wpOrigRebarProc);
wpOrigRebarProc = NULL;
}
if (hOrigStartWnd)
{
ShowWindow(hOrigStartWnd, SW_SHOW);
hOrigStartWnd = NULL;
}
if (wpOrigTrayShowDesktopProc)
{
SetWindowLongPtr(hTrayShowDesktopWnd, GWLP_WNDPROC,
(LONG_PTR)wpOrigTrayShowDesktopProc);
wpOrigTrayShowDesktopProc = NULL;
InvalidateRect(hTrayShowDesktopWnd, NULL, TRUE);
}
OnTaskbarShowEdgeui(TRUE);
PostMessage(hTaskbarWnd, WM_SIZE, 0, 0);
PostMessage(hTaskbarWnd, WM_TIMER, 24, 0); //explorer release unuse dll
}
//
// Start
//
static LRESULT CALLBACK StartProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_PAINT:
OnStartPaint();
break;
case WM_THEMECHANGED:
InvalidateRect(hWnd, NULL, TRUE);
break;
case WM_ENABLE:
fStartEnabled = (BOOL)wParam;
InvalidateRect(hWnd, NULL, TRUE);
break;
case WM_MOUSELEAVE:
fMouseLeftWnd = TRUE;
InvalidateRect(hWnd, NULL, TRUE);
break;
case WM_MOUSEMOVE:
OnStartMouseMove();
break;
case WM_LBUTTONDOWN:
ShowPane();
break;
case WM_RBUTTONUP:
OnStartRButtonUp();
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
}
void OnStartPaint()
{
HDC hdc;
PAINTSTRUCT ps;
RECT rc;
HDC hbufdc;
HPAINTBUFFER hbufpt;
int x, y, w;
HICON hicon;
hdc = BeginPaint(hStartWnd, &ps);
if (hdc)
{
GetClientRect(hStartWnd, &rc);
hbufpt = BeginBufferedPaint(hdc, &rc, BPBF_TOPDOWNDIB, NULL, &hbufdc);
if (hbufpt)
{
DrawThemeParentBackground(hStartWnd, hbufdc, &rc);
if (!fStartEnabled)
BufferedPaintSetAlpha(hbufpt, &rc, 96);
else if (!fMouseLeftWnd)
BufferedPaintSetAlpha(hbufpt, &rc, 0);
w = rc.bottom < 32 ? 16 : 32;
x = (rc.right - w) / 2;
y = (rc.bottom - w) / 2;
hicon = rc.bottom < 32 ? hStartIcon16 : hStartIcon32;
DrawIconEx(hbufdc, x, y, hicon, w, w, 0, NULL, DI_NORMAL);
EndBufferedPaint(hbufpt, TRUE);
}
EndPaint(hStartWnd, &ps);
}
}
void OnStartMouseMove()
{
TRACKMOUSEEVENT tme;
if (fMouseLeftWnd)
{
fMouseLeftWnd = FALSE;
InvalidateRect(hStartWnd, NULL, TRUE);
tme.cbSize = sizeof(TRACKMOUSEEVENT);
tme.dwFlags = TME_LEAVE;
tme.dwHoverTime = 10;
tme.hwndTrack = hStartWnd;
TrackMouseEvent(&tme);
}
}
void OnStartRButtonUp()
{
UINT umsg;
HWND hwnd;
umsg = RegisterWindowMessage(TEXT("SHELLHOOK"));
if (!umsg)
return;
hwnd = FindWindowEx(hRebarWnd, NULL, TEXT("MSTaskSwWClass"), NULL);
if (!hwnd)
return;
PostMessage(hwnd, umsg, HSHELL_TASKMAN, 0); //show start screen or start menu
}
//
// Rebar
//
static LRESULT CALLBACK RebarProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_WINDOWPOSCHANGING:
OnRebarWindowPosChanging(lParam);
break;
case WM_WINDOWPOSCHANGED:
OnRebarWindowPosChanged(lParam);
break;
default:
break;
}
return CallWindowProc(wpOrigRebarProc, hWnd, uMsg, wParam, lParam);
}
void OnRebarWindowPosChanging(LPARAM lParam)
{
WINDOWPOS *p;
p = (WINDOWPOS *)lParam;
if (p->x == 0)
{
p->cy += p->y;
p->y = 48;
p->cy -= p->y;
}
else
{
p->cx += p->x;
p->x = 48;
if (p->cy < 40)
p->x = 36;
p->cx -= p->x;
}
}
void OnRebarWindowPosChanged(LPARAM lParam)
{
WINDOWPOS *p;
int w, h;
p = (WINDOWPOS *)lParam;
if (p->x == 0)
{
w = p->cx;
h = p->y;
}
else
{
w = p->x;
h = p->cy;
}
MoveWindow(hStartWnd, 0, 0, w, h, TRUE);
}
//
// Taskbar
//
static LRESULT CALLBACK TaskbarProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case 0x0565: //win8.1 explorer launch will receive this
fPreShowDesktop = FALSE;
break;
case 0x0574:
if (lParam == 0x10000) //desktop has show will receive this
case 0x0550: //this band launch will receive this
case 0x0590: //win8.0 and 8.1 explorer launch will receive this
OnTaskbarSetWindowProc();
break;
case 0x05b3: //win8.0 explorer launch will receive this
fEnterDesktop = !fDisableMetro;
break;
case 0x0579: //switch to start screen will receive this
OnTaskbarEnterDesktop();
break;
case 0x05ba: //show or hide pc settings will receive this
case 0x05bb: //show or hide start screen will receive this
OnTaskbarShowEdgeui((BOOL)wParam);
break;
default:
break;
}
return CallWindowProc(wpOrigTaskbarProc, hWnd, uMsg, wParam, lParam);
}
void OnTaskbarEnterDesktop()
{
if (fEnterDesktop)
{
fEnterDesktop = FALSE;
SetForegroundWindow(hTaskbarWnd);
}
}
void OnTaskbarSetWindowProc()
{
HWND hwnd;
if (!wpOrigProgmanProc)
{
hProgmanWnd = GetShellWindow();
if (!hProgmanWnd)
return;
wpOrigProgmanProc = (WNDPROC)SetWindowLongPtr(hProgmanWnd,
GWLP_WNDPROC, (LONG_PTR)ProgmanProc);
hwnd = FindWindowEx(hProgmanWnd, NULL, TEXT("SHELLDLL_DefView"), NULL);
if (hwnd)
hSyslistWnd = FindWindowEx(hwnd, NULL, TEXT("SysListView32"), NULL);
if (fPreShowDesktop)
PostMessage(hProgmanWnd, 0x045c, 3, 7); //win8.0 pre-show desktop
if (fDisableMetro)
{
PostMessage(hTaskbarWnd, 0x0574, 2, 0); //show taskbar and desktop
PostMessage(hTaskbarWnd, 0x05ba, 0, 0); //enable show desktop and open windows
}
}
if (fDisableMetro && !wpOrigNetworkProc)
{
hNetworkWnd = FindWindowEx(NULL, NULL, NULL, TEXT("Network Flyout"));
if (!hNetworkWnd)
return;
wpOrigNetworkProc = (WNDPROC)SetWindowLongPtr(hNetworkWnd,
GWLP_WNDPROC, (LONG_PTR)NetworkProc);
}
OnTaskbarShowEdgeui(FALSE);
}
void OnTaskbarShowEdgeui(BOOL fShow)
{
HWND hwnd;
HWND hpar;
TCHAR *psz;
LONG_PTR l;
if (!hProgmanWnd)
return;
hwnd = NULL;
hpar = hProgmanWnd;
psz = TEXT("WorkerW");
for (;;)
{
hwnd = FindWindowEx(hpar, hwnd, psz, NULL);
if (!hwnd)
break;
l = GetWindowLongPtr(hwnd, GWL_EXSTYLE);
if (l)
{
if (fShow)
l ^= WS_EX_TRANSPARENT;
else
l |= WS_EX_TRANSPARENT;
SetWindowLongPtr(hwnd, GWL_EXSTYLE, l);
}
if (hpar == hProgmanWnd)
{
hwnd = NULL;
hpar = NULL;
psz = TEXT("EdgeUiInputWndClass");
}
}
}
//
// Progman
//
static LRESULT CALLBACK ProgmanProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_SYSCOMMAND && wParam == SC_TASKLIST) //press win key
{
ShowPane();
return 0;
}
return CallWindowProc(wpOrigProgmanProc, hWnd, uMsg, wParam, lParam);
}
//
// Network
//
static LRESULT CALLBACK NetworkProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
DWORD dw;
static TCHAR *psz = NULL;
dw = LOWORD(lParam);
if (dw == WM_LBUTTONDOWN)
{
psz = TEXT("shell:::{7007ACC7-3202-11D1-AAD2-00805FC1270E}");
return 0;
}
if (dw == WM_LBUTTONUP)
{
if (psz)
{
ShellExecute(NULL, NULL, psz, NULL, NULL, SW_SHOW);
psz = NULL;
}
return 0;
}
return CallWindowProc(wpOrigNetworkProc, hWnd, uMsg, wParam, lParam);
}
//
// TrayShowDesktop
//
static LRESULT CALLBACK TrayShowDesktopProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
HWND htray;
if (uMsg == WM_PAINT && fHideTrayShowDesktop)
{
hdc = BeginPaint(hWnd, &ps);
htray = GetParent(hWnd);
SendMessage(htray, WM_ERASEBKGND, (WPARAM)hdc, 0);
SendMessage(htray, WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT);
EndPaint(hWnd, &ps);
return 0;
}
return CallWindowProc(wpOrigTrayShowDesktopProc, hWnd, uMsg, wParam, lParam);
}