-
Notifications
You must be signed in to change notification settings - Fork 168
/
metapath.c
3702 lines (3107 loc) · 101 KB
/
metapath.c
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
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************
*
*
* metapath - The universal Explorer-like Plugin
*
* metapath.c
* Main application window functionality
*
* See Readme.txt for more information about this source code.
* Please send me your comments to this work.
*
* See License.txt for details about distribution and modification.
*
* (c) Florian Balmer 1996-2011
* florian.balmer@gmail.com
* http://www.flos-freeware.ch
*
*
******************************************************************************/
#include <windows.h>
#include <shlwapi.h>
#include <commctrl.h>
#include <shlobj.h>
#include <shellapi.h>
#include <commdlg.h>
#include <stdio.h>
#include "Helpers.h"
#include "Dlapi.h"
#include "Dialogs.h"
#include "metapath.h"
#include "resource.h"
/******************************************************************************
*
* Local Variables for metapath.c
*
*/
HWND hwndStatus;
HWND hwndToolbar;
HWND hwndReBar;
#define NUMTOOLBITMAPS 15
#define NUMINITIALTOOLS 6
#define TBFILTERBMP 13
TBBUTTON tbbMainWnd[] = {
{0, IDT_HISTORY_BACK, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{1, IDT_HISTORY_FORWARD, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{2, IDT_UPDIR, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{3, IDT_ROOT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{4, IDT_VIEW_FAVORITES, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{5, IDT_FILE_PREV, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{6, IDT_FILE_NEXT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{7, IDT_FILE_RUN, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{8, IDT_FILE_QUICKVIEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{9, IDT_FILE_SAVEAS, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{10, IDT_FILE_COPYMOVE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{11, IDT_FILE_DELETE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{12, IDT_FILE_DELETE2, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{13, IDT_VIEW_FILTER, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{0, 0, 0, TBSTYLE_SEP, 0, 0}
};
HWND hwndDriveBox;
HWND hwndDirList;
HWND hwndMain;
HANDLE hChangeHandle = NULL;
HISTORY mHistory;
WCHAR szIniFile[MAX_PATH] = L"";
WCHAR szIniFile2[MAX_PATH] = L"";
BOOL bSaveSettings;
WCHAR szQuickview[MAX_PATH];
WCHAR szQuickviewParams[MAX_PATH];
WCHAR tchFavoritesDir[MAX_PATH];
WCHAR tchOpenWithDir[MAX_PATH];
WCHAR tchToolbarButtons[512];
WCHAR tchToolbarBitmap[MAX_PATH];
WCHAR tchToolbarBitmapHot[MAX_PATH];
WCHAR tchToolbarBitmapDisabled[MAX_PATH];
BOOL bClearReadOnly;
BOOL bRenameOnCollision;
BOOL bSingleClick;
BOOL bTrackSelect;
BOOL bFullRowSelect;
int iStartupDir;
int iEscFunction;
BOOL bFocusEdit;
BOOL bAlwaysOnTop;
BOOL bTransparentMode;
BOOL bMinimizeToTray;
BOOL fUseRecycleBin;
BOOL fNoConfirmDelete;
BOOL bShowToolbar;
BOOL bShowStatusbar;
BOOL bShowDriveBox;
int cxGotoDlg;
int cxOpenWithDlg;
int cyOpenWithDlg;
int cxCopyMoveDlg;
WCHAR tchFilter[DL_FILTER_BUFSIZE];
BOOL bNegFilter;
BOOL bDefCrNoFilt;
BOOL bDefCrFilter;
COLORREF crNoFilt;
COLORREF crFilter;
COLORREF crCustom[16];
typedef struct _wi {
int x;
int y;
int cx;
int cy;
} WININFO;
WININFO wi;
int cyReBar;
int cyReBarFrame;
int cyDriveBoxFrame;
int nIdFocus = IDC_DIRLIST;
WCHAR szCurDir[MAX_PATH + 40];
DWORD dwFillMask;
int nSortFlags;
BOOL fSortRev;
LPWSTR lpPathArg = NULL;
LPWSTR lpFilterArg = NULL;
UINT wFuncCopyMove = FO_COPY;
UINT msgTaskbarCreated = 0;
int iUseTargetApplication = 4;
int iTargetApplicationMode = 0;
WCHAR szTargetApplication[MAX_PATH] = L"";
WCHAR szTargetApplicationParams[MAX_PATH] = L"";
WCHAR szTargetApplicationWndClass[MAX_PATH] = L"";
WCHAR szDDEMsg[256] = L"";
WCHAR szDDEApp[256] = L"";
WCHAR szDDETopic[256] = L"";
HINSTANCE g_hInstance;
UINT16 g_uWinVer;
//=============================================================================
//
// Flags
//
int flagNoReuseWindow = 0;
int flagStartAsTrayIcon = 0;
int flagPortableMyDocs = 0;
int flagGotoFavorites = 0;
int flagNoFadeHidden = 0;
int flagToolbarLook = 0;
int flagPosParam = 0;
//=============================================================================
//
// WinMain()
//
//
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow) {
MSG msg;
HWND hwnd;
HACCEL hAcc;
INITCOMMONCONTROLSEX icex;
// Set global variable g_hInstance
g_hInstance = hInstance;
// Set the Windows version global variable
g_uWinVer = LOWORD(GetVersion());
g_uWinVer = MAKEWORD(HIBYTE(g_uWinVer), LOBYTE(g_uWinVer));
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
// Command Line, Ini File and Flags
ParseCommandLine();
FindIniFile();
TestIniFile();
CreateIniFile();
LoadFlags();
// Try to activate another window
if (ActivatePrevInst()) {
return 0;
}
// Init OLE and Common Controls
OleInitialize(NULL);
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_WIN95_CLASSES | ICC_COOL_CLASSES | ICC_BAR_CLASSES | ICC_USEREX_CLASSES;
InitCommonControlsEx(&icex);
msgTaskbarCreated = RegisterWindowMessage(L"TaskbarCreated");
// Load Settings
LoadSettings();
if (!InitApplication(hInstance)) {
return FALSE;
}
if ((hwnd = InitInstance(hInstance, lpCmdLine, nCmdShow)) == NULL) {
return FALSE;
}
hAcc = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_MAINWND));
while (GetMessage(&msg, NULL, 0, 0)) {
if (!TranslateAccelerator(hwnd, hAcc, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
OleUninitialize();
return (int)(msg.wParam);
}
//=============================================================================
//
// InitApplication()
//
//
BOOL InitApplication(HINSTANCE hInstance) {
WNDCLASS wc;
wc.style = CS_BYTEALIGNWINDOW;
wc.lpfnWndProc = (WNDPROC)MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDR_MAINWND));
wc.hCursor = LoadCursor(hInstance, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = WC_METAPATH;
return RegisterClass(&wc);
}
//=============================================================================
//
// InitInstance()
//
//
HWND InitInstance(HINSTANCE hInstance, LPSTR pszCmdLine, int nCmdShow) {
RECT rc = { wi.x, wi.y, wi.x + wi.cx, wi.y + wi.cy };
RECT rc2;
MONITORINFO mi;
HMONITOR hMonitor = MonitorFromRect(&rc, MONITOR_DEFAULTTONEAREST);
mi.cbSize = sizeof(mi);
GetMonitorInfo(hMonitor, &mi);
if (wi.x == CW_USEDEFAULT || wi.y == CW_USEDEFAULT || wi.cx == CW_USEDEFAULT || wi.cy == CW_USEDEFAULT) {
// default window position
SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0);
wi.x = rc.left + 16;
wi.y = rc.top + 16;
wi.cx = 272;
wi.cy = 640;
} else {
// fit window into working area of current monitor
wi.x += (mi.rcWork.left - mi.rcMonitor.left);
wi.y += (mi.rcWork.top - mi.rcMonitor.top);
if (wi.x < mi.rcWork.left) {
wi.x = mi.rcWork.left;
}
if (wi.y < mi.rcWork.top) {
wi.y = mi.rcWork.top;
}
if (wi.x + wi.cx > mi.rcWork.right) {
wi.x -= (wi.x + wi.cx - mi.rcWork.right);
if (wi.x < mi.rcWork.left) {
wi.x = mi.rcWork.left;
}
if (wi.x + wi.cx > mi.rcWork.right) {
wi.cx = mi.rcWork.right - wi.x;
}
}
if (wi.y + wi.cy > mi.rcWork.bottom) {
wi.y -= (wi.y + wi.cy - mi.rcWork.bottom);
if (wi.y < mi.rcWork.top) {
wi.y = mi.rcWork.top;
}
if (wi.y + wi.cy > mi.rcWork.bottom) {
wi.cy = mi.rcWork.bottom - wi.y;
}
}
SetRect(&rc, wi.x, wi.y, wi.x + wi.cx, wi.y + wi.cy);
if (!IntersectRect(&rc2, &rc, &mi.rcWork)) {
wi.y = mi.rcWork.top + 16;
wi.cy = mi.rcWork.bottom - mi.rcWork.top - 32;
wi.cx = min_i(mi.rcWork.right - mi.rcWork.left - 32, wi.cy);
wi.x = mi.rcWork.right - wi.cx - 16;
}
}
hwndMain = CreateWindowEx(
0,
WC_METAPATH,
L"metapath",
WS_METAPATH,
wi.x,
wi.y,
wi.cx,
wi.cy,
NULL,
NULL,
hInstance,
NULL);
if (bAlwaysOnTop) {
SetWindowPos(hwndMain, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
if (bTransparentMode) {
SetWindowTransparentMode(hwndMain, TRUE);
}
if (!flagStartAsTrayIcon) {
ShowWindow(hwndMain, nCmdShow);
UpdateWindow(hwndMain);
} else {
ShowWindow(hwndMain, SW_HIDE); // trick ShowWindow()
ShowNotifyIcon(hwndMain, TRUE);
}
// Pathname parameter
if (lpPathArg) {
DisplayPath(lpPathArg, IDS_ERR_CMDLINE);
GlobalFree(lpPathArg);
} else if (iStartupDir) {
// Use a startup directory
if (iStartupDir == 1) {
WCHAR tch[MAX_PATH];
if (!IniGetString(L"Settings", L"MRUDirectory", L"", tch, COUNTOF(tch))) {
GetModuleFileName(NULL, tch, COUNTOF(tch));
PathRemoveFileSpec(tch);
}
DisplayPath(tch, IDS_ERR_STARTUPDIR);
} else {
DisplayPath(tchFavoritesDir, IDS_ERR_STARTUPDIR);
}
} else if (flagGotoFavorites) {
// Favorites
DisplayPath(tchFavoritesDir, IDS_ERR_FAVORITES);
}
// Update Dirlist
if (!ListView_GetItemCount(hwndDirList)) {
PostMessage(hwndMain, WM_COMMAND, MAKELONG(IDM_VIEW_UPDATE, 1), 0);
}
return hwndMain;
}
//=============================================================================
//
// MainWndProc()
//
// Messages are distributed to the MsgXXX-handlers
//
//
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) {
static BOOL bShutdownOK;
switch (umsg) {
case WM_CREATE: {
// Init directory watching
// iAutoRefreshRate is in 1/10 sec
int iAutoRefreshRate = IniGetInt(L"Settings2", L"AutoRefreshRate", 30);
if (iAutoRefreshRate) {
SetTimer(hwnd, ID_TIMER, (iAutoRefreshRate * 100), NULL);
}
return MsgCreate(hwnd, wParam, lParam);
}
case WM_DESTROY:
case WM_ENDSESSION:
if (!bShutdownOK) {
WINDOWPLACEMENT wndpl;
// Terminate directory watching
KillTimer(hwnd, ID_TIMER);
FindCloseChangeNotification(hChangeHandle);
// GetWindowPlacement
wndpl.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(hwnd, &wndpl);
wi.x = wndpl.rcNormalPosition.left;
wi.y = wndpl.rcNormalPosition.top;
wi.cx = wndpl.rcNormalPosition.right - wndpl.rcNormalPosition.left;
wi.cy = wndpl.rcNormalPosition.bottom - wndpl.rcNormalPosition.top;
DirList_Destroy(hwndDirList);
DragAcceptFiles(hwnd, FALSE);
History_Uninit(&mHistory);
SaveSettings(FALSE);
bShutdownOK = TRUE;
}
if (umsg == WM_DESTROY) {
PostQuitMessage(0);
}
break;
// Reinitialize theme-dependent values and resize windows
case WM_THEMECHANGED:
MsgThemeChanged(hwnd, wParam, lParam);
break;
// update colors of DirList manually
case WM_SYSCOLORCHANGE: {
LRESULT lret = DefWindowProc(hwnd, umsg, wParam, lParam);
if (lstrcmp(tchFilter, L"*.*") || bNegFilter) {
ListView_SetTextColor(hwndDirList, (bDefCrFilter) ? GetSysColor(COLOR_WINDOWTEXT) : crFilter);
ListView_RedrawItems(hwndDirList, 0, ListView_GetItemCount(hwndDirList) - 1);
} else {
ListView_SetTextColor(hwndDirList, (bDefCrNoFilt) ? GetSysColor(COLOR_WINDOWTEXT) : crNoFilt);
ListView_RedrawItems(hwndDirList, 0, ListView_GetItemCount(hwndDirList) - 1);
}
return lret;
}
case WM_NCLBUTTONDOWN:
case WM_NCMOUSEMOVE:
case WM_NCLBUTTONUP:
case WM_NCRBUTTONDOWN:
case WM_NCMBUTTONDOWN:
case WM_NCRBUTTONUP:
case WM_NCMBUTTONUP: {
MSG msg;
HWND hwndTT = (HWND)SendMessage(hwndToolbar, TB_GETTOOLTIPS, 0, 0);
if (wParam != HTCAPTION) {
SendMessage(hwndTT, TTM_POP, 0, 0);
return DefWindowProc(hwnd, umsg, wParam, lParam);
}
msg.hwnd = hwnd;
msg.message = umsg;
msg.wParam = wParam;
msg.lParam = lParam;
msg.time = GetMessageTime();
msg.pt.x = HIWORD(GetMessagePos());
msg.pt.y = LOWORD(GetMessagePos());
SendMessage(hwndTT, TTM_RELAYEVENT, 0, (LPARAM)&msg);
}
return DefWindowProc(hwnd, umsg, wParam, lParam);
case WM_TIMER:
// Check Change Notification Handle
if (WAIT_OBJECT_0 == WaitForSingleObject(hChangeHandle, 0)) {
// Store information about currently selected item
DLITEM dli;
dli.mask = DLI_ALL;
dli.ntype = DLE_NONE;
DirList_GetItem(hwndDirList, -1, &dli);
FindNextChangeNotification(hChangeHandle);
SendMessage(hwnd, WM_COMMAND, MAKELONG(IDM_VIEW_UPDATE, 1), 0);
// must use SendMessage() !!
if (dli.ntype != DLE_NONE) {
DirList_SelectItem(hwndDirList, dli.szDisplayName, dli.szFileName);
}
}
break;
case WM_SIZE:
MsgSize(hwnd, wParam, lParam);
break;
case WM_SETFOCUS:
SetFocus(GetDlgItem(hwnd, nIdFocus));
break;
case WM_DROPFILES: {
WCHAR szBuf[MAX_PATH + 40];
HDROP hDrop = (HDROP)wParam;
if (IsIconic(hwnd)) {
ShowWindow(hwnd, SW_RESTORE);
}
//SetForegroundWindow(hwnd);
DragQueryFile(hDrop, 0, szBuf, COUNTOF(szBuf));
DisplayPath(szBuf, IDS_ERR_DROP1);
if (DragQueryFile(hDrop, (UINT)(-1), NULL, 0) > 1) {
ErrorMessage(1, IDS_ERR_DROP2);
}
DragFinish(hDrop);
}
break;
case WM_COPYDATA: {
PCOPYDATASTRUCT pcds = (PCOPYDATASTRUCT)lParam;
if (pcds->dwData == DATA_METAPATH_PATHARG) {
LPWSTR lpsz = LocalAlloc(LPTR, pcds->cbData);
CopyMemory(lpsz, pcds->lpData, pcds->cbData);
DisplayPath(lpsz, IDS_ERR_CMDLINE);
LocalFree(lpsz);
}
}
return TRUE;
case WM_CONTEXTMENU: {
HMENU hmenu;
int imenu = 0;
DWORD dwpts;
int nID = GetDlgCtrlID((HWND)wParam);
if (nID != IDC_DIRLIST && nID != IDC_DRIVEBOX &&
nID != IDC_TOOLBAR && nID != IDC_STATUSBAR &&
nID != IDC_REBAR) {
return DefWindowProc(hwnd, umsg, wParam, lParam);
}
hmenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_MAINWND));
SetMenuDefaultItem(GetSubMenu(hmenu, 0), IDM_FILE_OPEN, FALSE);
switch (nID) {
case IDC_DIRLIST:
if (ListView_GetSelectedCount(hwndDirList)) {
imenu = 0;
} else {
imenu = 1;
}
break;
case IDC_DRIVEBOX:
imenu = 2;
break;
case IDC_TOOLBAR:
case IDC_STATUSBAR:
case IDC_REBAR:
imenu = 3;
break;
}
dwpts = GetMessagePos();
TrackPopupMenuEx(GetSubMenu(hmenu, imenu),
TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
(int)(short)LOWORD(dwpts) + 1, (int)(short)HIWORD(dwpts) + 1, hwnd, NULL);
DestroyMenu(hmenu);
}
break;
case WM_INITMENU:
MsgInitMenu(hwnd, wParam, lParam);
break;
case WM_NOTIFY:
return MsgNotify(hwnd, wParam, lParam);
case WM_COMMAND:
return MsgCommand(hwnd, wParam, lParam);
case WM_SYSCOMMAND:
switch (wParam) {
case SC_MINIMIZE:
case SC_MINIMIZE | 0x02:
ShowOwnedPopups(hwnd, FALSE);
if (!bMinimizeToTray) {
return DefWindowProc(hwnd, umsg, wParam, lParam);
} else {
MinimizeWndToTray(hwnd);
ShowNotifyIcon(hwnd, TRUE);
}
break;
case SC_RESTORE: {
LRESULT lrv = DefWindowProc(hwnd, umsg, wParam, lParam);
ShowOwnedPopups(hwnd, TRUE);
return (lrv);
}
case SC_ALWAYSONTOP:
if (bAlwaysOnTop) {
bAlwaysOnTop = 0;
SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
} else {
bAlwaysOnTop = 1;
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
break;
case SC_ABOUT:
ThemedDialogBox(g_hInstance, MAKEINTRESOURCE(IDD_ABOUT),
hwnd, AboutDlgProc);
break;
default:
return DefWindowProc(hwnd, umsg, wParam, lParam);
}
break;
case WM_TRAYMESSAGE:
switch (lParam) {
case WM_RBUTTONUP: {
HMENU hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_MAINWND));
HMENU hMenuPopup = GetSubMenu(hMenu, 4);
POINT pt;
int iCmd;
SetForegroundWindow(hwnd);
GetCursorPos(&pt);
SetMenuDefaultItem(hMenuPopup, IDM_TRAY_RESTORE, FALSE);
iCmd = TrackPopupMenu(hMenuPopup,
TPM_NONOTIFY | TPM_RETURNCMD | TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
pt.x, pt.y, 0, hwnd, NULL);
PostMessage(hwnd, WM_NULL, 0, 0);
DestroyMenu(hMenu);
if (iCmd == IDM_TRAY_RESTORE) {
ShowNotifyIcon(hwnd, FALSE);
RestoreWndFromTray(hwnd);
ShowOwnedPopups(hwnd, TRUE);
} else if (iCmd == IDM_TRAY_EXIT) {
ShowNotifyIcon(hwnd, FALSE);
SendMessage(hwnd, WM_CLOSE, 0, 0);
}
}
return TRUE;
case WM_LBUTTONUP:
ShowNotifyIcon(hwnd, FALSE);
RestoreWndFromTray(hwnd);
ShowOwnedPopups(hwnd, TRUE);
return TRUE;
}
break;
case APPM_CENTER_MESSAGE_BOX: {
HWND box = FindWindow(L"#32770", NULL);
HWND parent = GetParent(box);
// MessageBox belongs to us.
if (parent == (HWND)wParam || parent == hwndMain) {
CenterDlgInParentEx(box, parent);
SnapToDefaultButton(box);
}
}
break;
default:
if (umsg == msgTaskbarCreated) {
if (!IsWindowVisible(hwnd)) {
ShowNotifyIcon(hwnd, TRUE);
}
return 0;
}
return DefWindowProc(hwnd, umsg, wParam, lParam);
}
return 0;
}
//=============================================================================
//
// MsgCreate() - Handles WM_CREATE
//
//
LRESULT MsgCreate(HWND hwnd, WPARAM wParam, LPARAM lParam) {
HWND hwndTT;
TOOLINFO ti;
LVCOLUMN lvc = { LVCF_FMT | LVCF_TEXT, LVCFMT_LEFT, 0, L"", -1, 0, 0, 0 };
HMENU hmenu;
WCHAR tch[64];
MENUITEMINFO mii;
HINSTANCE hInstance = ((LPCREATESTRUCT)lParam)->hInstance;
DWORD dwDriveBoxStyle = WS_DRIVEBOX;
hwndDirList = CreateWindowEx(
WS_EX_CLIENTEDGE,
WC_LISTVIEW,
NULL,
WS_DIRLIST,
0, 0, 0, 0,
hwnd,
(HMENU)IDC_DIRLIST,
hInstance,
NULL);
if (IsVistaAndAbove() && PrivateIsAppThemed()) {
SetWindowLongPtr(hwndDirList, GWL_EXSTYLE, GetWindowLongPtr(hwndDirList, GWL_EXSTYLE) & ~WS_EX_CLIENTEDGE);
SetWindowPos(hwndDirList, NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
}
if (bShowDriveBox) {
dwDriveBoxStyle |= WS_VISIBLE;
}
hwndDriveBox = CreateWindowEx(
0,
WC_COMBOBOXEX,
NULL,
dwDriveBoxStyle,
0, 0, 0, GetSystemMetrics(SM_CYFULLSCREEN),
hwnd,
(HMENU)IDC_DRIVEBOX,
hInstance,
NULL);
// Create Toolbar and Statusbar
CreateBars(hwnd, hInstance);
// Window Initialization
// DriveBox
DriveBox_Init(hwndDriveBox);
SendMessage(hwndDriveBox, CB_SETEXTENDEDUI, TRUE, 0);
// DirList
ListView_SetExtendedListViewStyle(hwndDirList, LVS_EX_DOUBLEBUFFER | LVS_EX_LABELTIP);
ListView_InsertColumn(hwndDirList, 0, &lvc);
DirList_Init(hwndDirList, NULL);
if (bTrackSelect) {
ListView_SetExtendedListViewStyleEx(hwndDirList,
LVS_EX_TRACKSELECT | LVS_EX_ONECLICKACTIVATE,
LVS_EX_TRACKSELECT | LVS_EX_ONECLICKACTIVATE);
}
if (bFullRowSelect) {
ListView_SetExtendedListViewStyleEx(hwndDirList,
LVS_EX_FULLROWSELECT,
LVS_EX_FULLROWSELECT);
if (IsVistaAndAbove()) {
SetTheme(hwndDirList, L"Explorer");
}
}
ListView_SetHoverTime(hwndDirList, 10);
// Drag & Drop
DragAcceptFiles(hwnd, TRUE);
// History
History_Init(&mHistory);
History_UpdateToolbar(&mHistory, hwndToolbar, IDT_HISTORY_BACK, IDT_HISTORY_FORWARD);
// ToolTip with Current Directory
ZeroMemory(&ti, sizeof(TOOLINFO));
ti.cbSize = sizeof(TOOLINFO);
ti.uFlags = TTF_IDISHWND;
ti.hwnd = hwnd;
ti.uId = (UINT_PTR)hwnd;
ti.lpszText = LPSTR_TEXTCALLBACK;
hwndTT = (HWND)SendMessage(hwndToolbar, TB_GETTOOLTIPS, 0, 0);
SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM)&ti);
// System Menu
hmenu = GetSystemMenu(hwnd, FALSE);
// Remove unwanted items
DeleteMenu(hmenu, SC_RESTORE, MF_BYCOMMAND);
DeleteMenu(hmenu, SC_MAXIMIZE, MF_BYCOMMAND);
// Mofify the L"Minimize" item
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_ID;
GetMenuItemInfo(hmenu, SC_MINIMIZE, FALSE, &mii);
mii.wID = SC_MINIMIZE | 0x02;
SetMenuItemInfo(hmenu, SC_MINIMIZE, FALSE, &mii);
// Add specific items
GetString(SC_ALWAYSONTOP, tch, COUNTOF(tch));
InsertMenu(hmenu, SC_MOVE, MF_BYCOMMAND | MF_STRING | MF_ENABLED, SC_ALWAYSONTOP, tch);
GetString(SC_ABOUT, tch, COUNTOF(tch));
InsertMenu(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_STRING | MF_ENABLED, SC_ABOUT, tch);
InsertMenu(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_SEPARATOR, 0, NULL);
return 0;
}
//=============================================================================
//
// CreateBars() - Create Toolbar and Statusbar
//
//
void CreateBars(HWND hwnd, HINSTANCE hInstance) {
REBARINFO rbi;
REBARBANDINFO rbBand;
RECT rc;
BITMAP bmp;
HBITMAP hbmp, hbmpCopy = NULL;
HIMAGELIST himl;
WCHAR szTmp[MAX_PATH];
BOOL bExternalBitmap = FALSE;
DWORD dwToolbarStyle = WS_TOOLBAR | TBSTYLE_FLAT | CCS_ADJUSTABLE;
DWORD dwStatusbarStyle = WS_CHILD | WS_CLIPSIBLINGS;
DWORD dwReBarStyle = WS_REBAR;
BOOL bIsAppThemed = PrivateIsAppThemed();
WCHAR tchDesc[256];
WCHAR tchIndex[256];
WCHAR *pIniSection = NULL;
int cbIniSection = 0;
if (bShowToolbar) {
dwReBarStyle |= WS_VISIBLE;
}
hwndToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, dwToolbarStyle,
0, 0, 0, 0, hwnd, (HMENU)IDC_TOOLBAR, hInstance, NULL);
SendMessage(hwndToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
// Add normal Toolbar Bitmap
hbmp = NULL;
if (lstrlen(tchToolbarBitmap)) {
if (!SearchPath(NULL, tchToolbarBitmap, NULL, COUNTOF(szTmp), szTmp, NULL)) {
lstrcpy(szTmp, tchToolbarBitmap);
}
hbmp = LoadImage(NULL, szTmp, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE);
}
if (hbmp) {
bExternalBitmap = TRUE;
} else {
hbmp = LoadImage(hInstance, MAKEINTRESOURCE(IDR_MAINWND), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
hbmpCopy = CopyImage(hbmp, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
}
GetObject(hbmp, sizeof(BITMAP), &bmp);
if (!IsWinXPAndAbove()) {
BitmapMergeAlpha(hbmp, GetSysColor(COLOR_3DFACE));
}
himl = ImageList_Create(bmp.bmWidth / NUMTOOLBITMAPS, bmp.bmHeight, ILC_COLOR32 | ILC_MASK, 0, 0);
ImageList_AddMasked(himl, hbmp, CLR_DEFAULT);
DeleteObject(hbmp);
SendMessage(hwndToolbar, TB_SETIMAGELIST, 0, (LPARAM)himl);
// Optionally add hot Toolbar Bitmap
hbmp = NULL;
if (lstrlen(tchToolbarBitmapHot)) {
if (!SearchPath(NULL, tchToolbarBitmapHot, NULL, COUNTOF(szTmp), szTmp, NULL)) {
lstrcpy(szTmp, tchToolbarBitmapHot);
}
if ((hbmp = LoadImage(NULL, szTmp, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE)) != NULL) {
GetObject(hbmp, sizeof(BITMAP), &bmp);
himl = ImageList_Create(bmp.bmWidth / NUMTOOLBITMAPS, bmp.bmHeight, ILC_COLOR32 | ILC_MASK, 0, 0);
ImageList_AddMasked(himl, hbmp, CLR_DEFAULT);
DeleteObject(hbmp);
SendMessage(hwndToolbar, TB_SETHOTIMAGELIST, 0, (LPARAM)himl);
}
}
// Optionally add disabled Toolbar Bitmap
hbmp = NULL;
if (lstrlen(tchToolbarBitmapDisabled)) {
if (!SearchPath(NULL, tchToolbarBitmapDisabled, NULL, COUNTOF(szTmp), szTmp, NULL)) {
lstrcpy(szTmp, tchToolbarBitmapDisabled);
}
if ((hbmp = LoadImage(NULL, szTmp, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE)) != NULL) {
GetObject(hbmp, sizeof(BITMAP), &bmp);
himl = ImageList_Create(bmp.bmWidth / NUMTOOLBITMAPS, bmp.bmHeight, ILC_COLOR32 | ILC_MASK, 0, 0);
ImageList_AddMasked(himl, hbmp, CLR_DEFAULT);
DeleteObject(hbmp);
SendMessage(hwndToolbar, TB_SETDISABLEDIMAGELIST, 0, (LPARAM)himl);
bExternalBitmap = TRUE;
}
}
if (!bExternalBitmap) {
BOOL fProcessed = FALSE;
if (flagToolbarLook == 1) {
fProcessed = BitmapAlphaBlend(hbmpCopy, GetSysColor(COLOR_3DFACE), 0x60);
} else if (flagToolbarLook == 2 || (!IsWinXPAndAbove() && flagToolbarLook == 0)) {
fProcessed = BitmapGrayScale(hbmpCopy);
}
if (fProcessed && !IsWinXPAndAbove()) {
BitmapMergeAlpha(hbmpCopy, GetSysColor(COLOR_3DFACE));
}
if (fProcessed) {
himl = ImageList_Create(bmp.bmWidth / NUMTOOLBITMAPS, bmp.bmHeight, ILC_COLOR32 | ILC_MASK, 0, 0);
ImageList_AddMasked(himl, hbmpCopy, CLR_DEFAULT);
SendMessage(hwndToolbar, TB_SETDISABLEDIMAGELIST, 0, (LPARAM)himl);
}
}
if (hbmpCopy) {
DeleteObject(hbmpCopy);
}
// Load toolbar labels
pIniSection = LocalAlloc(LPTR, sizeof(WCHAR) * 32 * 1024);
cbIniSection = (int)LocalSize(pIniSection) / sizeof(WCHAR);
LoadIniSection(L"Toolbar Labels", pIniSection, cbIniSection);
for (unsigned i = 0, n = 1; i < COUNTOF(tbbMainWnd); i++) {
if (tbbMainWnd[i].fsStyle == TBSTYLE_SEP) {
continue;
}
wsprintf(tchIndex, L"%02u", n++);
if (IniSectionGetString(pIniSection, tchIndex, L"", tchDesc, COUNTOF(tchDesc)) && lstrcmpi(tchDesc, L"(none)") != 0) {
tbbMainWnd[i].iString = SendMessage(hwndToolbar, TB_ADDSTRING, 0, (LPARAM)tchDesc);
tbbMainWnd[i].fsStyle |= BTNS_AUTOSIZE | BTNS_SHOWTEXT;
} else if ((n == 5 || n == 8) && lstrcmpi(tchDesc, L"(none)") != 0) {
GetString(42000 + n, tchDesc, COUNTOF(tchDesc));
tbbMainWnd[i].iString = SendMessage(hwndToolbar, TB_ADDSTRING, 0, (LPARAM)tchDesc);
tbbMainWnd[i].fsStyle |= BTNS_AUTOSIZE | BTNS_SHOWTEXT;
} else {
tbbMainWnd[i].fsStyle &= ~(BTNS_AUTOSIZE | BTNS_SHOWTEXT);
}
}
LocalFree(pIniSection);
SendMessage(hwndToolbar, TB_SETEXTENDEDSTYLE, 0,
SendMessage(hwndToolbar, TB_GETEXTENDEDSTYLE, 0, 0) | TBSTYLE_EX_MIXEDBUTTONS);
SendMessage(hwndToolbar, TB_ADDBUTTONS, NUMINITIALTOOLS, (LPARAM)tbbMainWnd);
//SendMessage(hwndToolbar, TB_SAVERESTORE, FALSE, (LPARAM)lptbsp);
if (Toolbar_SetButtons(hwndToolbar, IDT_HISTORY_BACK, tchToolbarButtons, tbbMainWnd, COUNTOF(tbbMainWnd)) == 0) {
SendMessage(hwndToolbar, TB_ADDBUTTONS, NUMINITIALTOOLS, (LPARAM)tbbMainWnd);
}
SendMessage(hwndToolbar, TB_GETITEMRECT, 0, (LPARAM)&rc);
//SendMessage(hwndToolbar, TB_SETINDENT, 2, 0);
if (bShowStatusbar) {
dwStatusbarStyle |= WS_VISIBLE;
}
hwndStatus = CreateStatusWindow(dwStatusbarStyle, NULL, hwnd, IDC_STATUSBAR);
// Create ReBar and add Toolbar
hwndReBar = CreateWindowEx(WS_EX_TOOLWINDOW, REBARCLASSNAME, NULL, dwReBarStyle,
0, 0, 0, 0, hwnd, (HMENU)IDC_REBAR, hInstance, NULL);
rbi.cbSize = sizeof(REBARINFO);
rbi.fMask = 0;
rbi.himl = (HIMAGELIST)NULL;
SendMessage(hwndReBar, RB_SETBARINFO, 0, (LPARAM)&rbi);
rbBand.cbSize = sizeof(REBARBANDINFO);
rbBand.fMask = /*RBBIM_COLORS | RBBIM_TEXT | RBBIM_BACKGROUND | */
RBBIM_STYLE | RBBIM_CHILD | RBBIM_CHILDSIZE /*| RBBIM_SIZE*/;
rbBand.fStyle = /*RBBS_CHILDEDGE | *//*RBBS_BREAK |*/ RBBS_FIXEDSIZE /*| RBBS_GRIPPERALWAYS*/;
if (bIsAppThemed) {
rbBand.fStyle |= RBBS_CHILDEDGE;
}
rbBand.hbmBack = NULL;
rbBand.lpText = L"Toolbar";
rbBand.hwndChild = hwndToolbar;
rbBand.cxMinChild = (rc.right - rc.left) * COUNTOF(tbbMainWnd);
rbBand.cyMinChild = (rc.bottom - rc.top) + 2 * rc.top;
rbBand.cx = 0;
SendMessage(hwndReBar, RB_INSERTBAND, (WPARAM) - 1, (LPARAM)&rbBand);
SetWindowPos(hwndReBar, NULL, 0, 0, 0, 0, SWP_NOZORDER);
GetWindowRect(hwndReBar, &rc);
cyReBar = rc.bottom - rc.top;
cyReBarFrame = bIsAppThemed ? 0 : 2;
cyDriveBoxFrame = (bIsAppThemed && IsVistaAndAbove()) ? 0 : 2;
}
//=============================================================================
//
// MsgThemeChanged() - Handles WM_THEMECHANGED
//
//
void MsgThemeChanged(HWND hwnd, WPARAM wParam, LPARAM lParam) {
RECT rc;
WCHAR chStatus[255];
HINSTANCE hInstance = (HINSTANCE)(INT_PTR)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
BOOL bIsAppThemed = PrivateIsAppThemed();