FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ClassicShell/ClassicExplorer/ExplorerBHO.cpp at master · decodedbrain/ClassicShell · GitHub
decodedbrain
/
ClassicShell
Public
forked from
xielechuan/ClassicShell
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
ClassicShell
/
ClassicExplorer
/
ExplorerBHO.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
1290 lines (1192 loc) · 44 KB
Breadcrumbs
ClassicShell
/
ClassicExplorer
/
ExplorerBHO.cpp
Copy path
File metadata and controls
executable file
·
1290 lines (1192 loc) · 44 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
//
Classic Shell (c) 2009-2013, Ivo Beltchev
//
The sources for Classic Shell are distributed under the MIT open source license
//
ExplorerBHO.cpp : Implementation of CExplorerBHO
#
include
"
stdafx.h
"
#
include
"
ExplorerBHO.h
"
#
include
"
Settings.h
"
#
include
"
ResourceHelper.h
"
#
include
"
resource.h
"
#
include
"
SettingsUI.h
"
#
include
"
Translations.h
"
#
include
"
SettingsUIHelper.h
"
#
include
"
dllmain.h
"
#
include
<
uxtheme.h
>
#
include
<
dwmapi.h
>
#
include
<
Ntquery.h
>
#
include
<
algorithm
>
//
CExplorerBHO - a browser helper object that implements Alt+Enter for the folder tree
const
UINT_PTR
TIMER_NAVIGATE
=
'
CLSH
'
;
int
CExplorerBHO::s_AutoNavDelay;
static
PIDLIST_ABSOLUTE
GetTreeItemPidl
(
HTREEITEM
hItem,
HWND
hwndTree )
{
//
find the PIDL of the tree item (combine all child PIDLs from the current item and its parents)
PIDLIST_ABSOLUTE
pidl=
NULL
;
while
(hItem)
{
TVITEMEX
info={
TVIF_PARAM
,hItem};
TreeView_GetItem
(hwndTree,&info);
PIDLIST_RELATIVE
**pidl1=(
PIDLIST_RELATIVE
**)info.
lParam
;
if
(!pidl1 || !*pidl1 || !**pidl1)
{
if
(pidl)
ILFree
(pidl);
pidl=
NULL
;
break
;
}
PIDLIST_ABSOLUTE
pidl2=pidl?
ILCombine
((
PIDLIST_ABSOLUTE
)**pidl1,pidl):(
PIDLIST_ABSOLUTE
)
ILClone
(**pidl1);
if
(pidl)
ILFree
(pidl);
pidl=pidl2;
hItem=
TreeView_GetParent
(hwndTree,hItem);
}
return
pidl;
}
LRESULT
CALLBACK
CExplorerBHO::SubclassTreeParentProc
(
HWND
hWnd,
UINT
uMsg,
WPARAM
wParam,
LPARAM
lParam,
UINT_PTR
uIdSubclass,
DWORD_PTR
dwRefData )
{
//
when the tree selection changes start a timer to navigate to the new folder in 100ms
if
(uMsg==
WM_NOTIFY
&& ((
NMHDR
*)lParam)->
code
==
TVN_SELCHANGED
)
{
if
(
GetSettingInt
(
L"
AutoNavigate
"
)==
2
|| ((
NMTREEVIEW
*)lParam)->
action
==
TVC_BYKEYBOARD
)
SetTimer
(((
NMHDR
*)lParam)->
hwndFrom
,
TIMER_NAVIGATE
,s_AutoNavDelay,
NULL
);
}
return
DefSubclassProc
(hWnd,uMsg,wParam,lParam);
}
//
Subclass the tree control to:
//
- support Alt+Enter
//
- navigate to the new folder when you go up/down with the keyboard
//
- fix the random scrolling of the tree when a folder is expanded
//
- change the tree styles to achieve different looks
LRESULT
CALLBACK
CExplorerBHO::SubclassTreeProc
(
HWND
hWnd,
UINT
uMsg,
WPARAM
wParam,
LPARAM
lParam,
UINT_PTR
uIdSubclass,
DWORD_PTR
dwRefData )
{
if
(uMsg==
TVM_ENSUREVISIBLE
&& (dwRefData&
1
))
{
//
HACK! there is a bug in Win7 Explorer and when the selected folder is expanded for the first time it sends TVM_ENSUREVISIBLE for
//
the root tree item. This causes the navigation pane to scroll up. To work around the bug we ignore TVM_ENSUREVISIBLE if it tries
//
to show the root item and it is not selected
HTREEITEM
hItem=(
HTREEITEM
)lParam;
if
(!
TreeView_GetParent
(hWnd,hItem) && !(
TreeView_GetItemState
(hWnd,hItem,
TVIS_SELECTED
)&
TVIS_SELECTED
))
return
0
;
}
if
(uMsg==
WM_TIMER
&& wParam==
TIMER_NAVIGATE
)
{
//
time to navigate to the selected folder (only if different from the current folder)
KillTimer
(hWnd,
TIMER_NAVIGATE
);
if
(
GetFocus
()!=hWnd)
return
0
;
PIDLIST_ABSOLUTE
pidl=
GetTreeItemPidl
(
TreeView_GetSelection
(hWnd),hWnd);
if
(pidl)
{
bool
bSameFolder=
false
;
CExplorerBHO *pThis=
GetTlsData
()->
bho
;
CComPtr<IShellView> pView;
if
(pThis->
m_pBrowser
&&
SUCCEEDED
(pThis->
m_pBrowser
->
QueryActiveShellView
(&pView)))
{
CComQIPtr<IFolderView> pView2=pView;
CComPtr<IPersistFolder2> pFolder;
PIDLIST_ABSOLUTE
pidl2;
if
(pView2 &&
SUCCEEDED
(pView2->
GetFolder
(IID_IPersistFolder2,(
void
**)&pFolder)) &&
SUCCEEDED
(pFolder->
GetCurFolder
(&pidl2)) && pidl2)
{
if
(
ILIsEqual
(pidl,pidl2))
bSameFolder=
true
;
ILFree
(pidl2);
}
}
ILFree
(pidl);
if
(!bSameFolder)
SendMessage
(hWnd,
WM_KEYDOWN
,
VK_SPACE
,
0
);
}
return
0
;
}
//
ignore the Alt+Enter syscharacter (to stop the tree view from beeping)
if
(uMsg==
WM_SYSCHAR
&& wParam==
VK_RETURN
)
return
0
;
if
(uMsg==
WM_SYSKEYDOWN
&& wParam==
VK_RETURN
)
{
//
Alt+Enter is pressed
//
if this message was for the folder tree, show the properties of the selected item
if
(
GetSettingBool
(
L"
AltEnter
"
) &&
ShowTreeProperties
(hWnd))
return
0
;
}
if
((uMsg==
WM_LBUTTONDOWN
|| uMsg==
WM_LBUTTONDBLCLK
) && (wParam&
MK_CONTROL
))
{
TVHITTESTINFO
test;
test.
pt
.
x
=(
short
)
LOWORD
(lParam);
test.
pt
.
y
=(
short
)
HIWORD
(lParam);
HTREEITEM
hItem=
TreeView_HitTest
(hWnd,&test);
if
(test.
flags
&
TVHT_ONITEM
)
{
PIDLIST_ABSOLUTE
pidl=
GetTreeItemPidl
(hItem,hWnd);
if
(pidl)
{
CExplorerBHO *pThis=
GetTlsData
()->
bho
;
if
(pThis->
m_pBrowser
)
{
pThis->
m_pBrowser
->
BrowseObject
(pidl,
SBSP_NEWBROWSER
|
SBSP_ABSOLUTE
);
}
ILFree
(pidl);
}
}
return
0
;
}
if
(uMsg==
TVM_SETEXTENDEDSTYLE
&& wParam==(
TVS_EX_FADEINOUTEXPANDOS
|
TVS_EX_AUTOHSCROLL
|
0x80000000
) && lParam==
0
)
{
wParam&=
0x7FFFFFFF
;
if
(
GetSettingInt
(
L"
AutoNavigate
"
)>
0
)
SetWindowSubclass
(
GetParent
(hWnd),SubclassTreeParentProc,
'
CLSH
'
,
0
);
if
(!
GetSettingBool
(
L"
NoFadeButtons
"
))
wParam&=~
TVS_EX_FADEINOUTEXPANDOS
;
int
indent=-
1
;
if
(
GetSettingBool
(
L"
FullIndent
"
))
indent=
0
;
int
treeStyle=
GetSettingInt
(
L"
TreeStyle
"
);
DWORD
style=
GetWindowLong
(hWnd,
GWL_STYLE
);
if
(treeStyle!=
STYLE_VISTA
)
{
SetWindowTheme
(hWnd,
NULL
,
NULL
);
if
(treeStyle==
STYLE_SIMPLE
)
{
style|=
TVS_SINGLEEXPAND
|
TVS_TRACKSELECT
;
style&=~
TVS_HASLINES
;
}
else
{
style|=
TVS_HASLINES
;
style&=~(
TVS_SINGLEEXPAND
|
TVS_TRACKSELECT
);
wParam|=
TVS_EX_FADEINOUTEXPANDOS
;
HIMAGELIST
images=
TreeView_GetImageList
(hWnd,
TVSIL_NORMAL
);
int
cx, cy;
ImageList_GetIconSize
(images,&cx,&cy);
indent=cx+
3
;
}
}
int
scroll=
GetSettingInt
(
L"
HScrollbar
"
);
if
((scroll==
0
&& treeStyle==
STYLE_VISTA
) || scroll==
1
)
wParam&=~
TVS_EX_AUTOHSCROLL
;
if
((scroll==
0
&& treeStyle!=
STYLE_VISTA
) || scroll==
2
)
style&=~
TVS_NOHSCROLL
;
SetWindowLong
(hWnd,
GWL_STYLE
,style);
if
(indent>=
0
)
TreeView_SetIndent
(hWnd,indent);
int
d=
GetSettingInt
(
L"
TreeItemSpacing
"
);
if
(d)
TreeView_SetItemHeight
(hWnd,
TreeView_GetItemHeight
(hWnd)+d);
if
(wParam==
0
)
return
0
;
}
if
(uMsg==
WM_SETTINGCHANGE
)
{
LRESULT
res=
DefSubclassProc
(hWnd,uMsg,wParam,lParam);
int
indent=-
1
;
if
(
GetSettingBool
(
L"
FullIndent
"
))
indent=
0
;
if
(
GetSettingInt
(
L"
TreeStyle
"
)==
STYLE_CLASSIC
)
{
HIMAGELIST
images=
TreeView_GetImageList
(hWnd,
TVSIL_NORMAL
);
int
cx, cy;
ImageList_GetIconSize
(images,&cx,&cy);
indent=cx+
3
;
}
if
(indent>=
0
)
TreeView_SetIndent
(hWnd,indent);
int
d=
GetSettingInt
(
L"
TreeItemSpacing
"
);
if
(d)
TreeView_SetItemHeight
(hWnd,
TreeView_GetItemHeight
(hWnd)+d);
return
res;
}
return
DefSubclassProc
(hWnd,uMsg,wParam,lParam);
}
LRESULT
CALLBACK
CExplorerBHO::HookExplorer
(
int
nCode,
WPARAM
wParam,
LPARAM
lParam )
{
//
wait for the tree control to be created and subclass it
if
(nCode==
HCBT_CREATEWND
)
{
HWND
hWnd=(
HWND
)wParam;
CBT_CREATEWND
*pCreate=(
CBT_CREATEWND
*)lParam;
if
(pCreate->
lpcs
->
lpszClass
>(
LPTSTR
)
0xFFFF
&&
_wcsicmp
(pCreate->
lpcs
->
lpszClass
,
WC_TREEVIEW
)==
0
)
{
HWND
parent=
GetAncestor
(pCreate->
lpcs
->
hwndParent
,
GA_ROOT
);
wchar_t
name[
256
];
if
(
GetClassName
(parent,name,
_countof
(name)) &&
_wcsicmp
(name,
L"
CabinetWClass
"
)==
0
)
{
DWORD_PTR
settings=
0
;
if
(
GetWinVersion
()==
WIN_VER_WIN7
&&
GetSettingBool
(
L"
FixFolderScroll
"
))
settings|=
1
;
SetWindowSubclass
(hWnd,SubclassTreeProc,
'
CLSH
'
,settings);
PostMessage
(hWnd,
TVM_SETEXTENDEDSTYLE
,
TVS_EX_FADEINOUTEXPANDOS
|
TVS_EX_AUTOHSCROLL
|
0x80000000
,
0
);
if
(
GetWinVersion
()==
WIN_VER_VISTA
)
{
//
on Vista we can unhook right now. on Win7 we keep the hook because sometimes the tree control can get destroyed and recreated
TlsData *pTlsData=
GetTlsData
();
UnhookWindowsHookEx
(pTlsData->
bho
->
m_Hook
);
pTlsData->
bho
->
m_Hook
=
NULL
;
}
return
0
;
}
}
}
return
CallNextHookEx
(
NULL
,nCode,wParam,lParam);
}
LRESULT
CALLBACK
CExplorerBHO::HookKeyboard
(
int
nCode,
WPARAM
wParam,
LPARAM
lParam )
{
//
wait for the tree control to be created and subclass it
if
(nCode==
HC_ACTION
)
{
TlsData *pTlsData=
GetTlsData
();
if
(wParam==pTlsData->
bho
->
m_AltD
&& (lParam&
0x20000000
))
{
if
(lParam&
0x80000000
)
{
return
0
;
}
else
{
if
(
IsWindow
(pTlsData->
bho
->
m_Breadcrumbs
) &&
IsWindowVisible
(pTlsData->
bho
->
m_Breadcrumbs
))
{
SetFocus
(pTlsData->
bho
->
m_Breadcrumbs
);
SendMessage
(pTlsData->
bho
->
m_Breadcrumbs
,
WM_KEYDOWN
,
VK_SPACE
,
0
);
SendMessage
(pTlsData->
bho
->
m_Breadcrumbs
,
WM_KEYUP
,
VK_SPACE
,
0
);
return
0
;
}
}
}
if
(wParam==(pTlsData->
bho
->
m_UpHotkey
&
255
) && !(lParam&
0x80000000
))
{
//
Backspace goes to the parent folder, but only if no window has the caret
GUITHREADINFO
info={
sizeof
(info)};
if
(
GetGUIThreadInfo
(
GetCurrentThreadId
(),&info) && !info.
hwndCaret
)
{
bool
bShift1=(pTlsData->
bho
->
m_UpHotkey
&(
HOTKEYF_SHIFT
<<
8
))!=
0
;
bool
bCtrl1=(pTlsData->
bho
->
m_UpHotkey
&(
HOTKEYF_CONTROL
<<
8
))!=
0
;
bool
bAlt1=(pTlsData->
bho
->
m_UpHotkey
&(
HOTKEYF_ALT
<<
8
))!=
0
;
bool
bShift2=
GetKeyState
(
VK_SHIFT
)<
0
;
bool
bCtrl2=
GetKeyState
(
VK_CONTROL
)<
0
;
bool
bAlt2=
GetKeyState
(
VK_MENU
)<
0
;
if
(bShift1==bShift2 && bCtrl1==bCtrl2 && bAlt1==bAlt2)
{
pTlsData->
bho
->
m_pBrowser
->
BrowseObject
(
NULL
,
SBSP_SAMEBROWSER
|
SBSP_PARENT
);
return
1
;
}
}
}
}
return
CallNextHookEx
(
NULL
,nCode,wParam,lParam);
}
//
Subclass the statusbar to:
//
- show free disk space
//
- show the total size of the selected files
LRESULT
CALLBACK
CExplorerBHO::SubclassStatusProc
(
HWND
hWnd,
UINT
uMsg,
WPARAM
wParam,
LPARAM
lParam,
UINT_PTR
uIdSubclass,
DWORD_PTR
dwRefData )
{
wchar_t
buf[
1024
];
if
(uMsg==
WM_PAINT
&& ((CExplorerBHO*)uIdSubclass)->
m_bForceRefresh
)
{
//
sometimes Explorer doesn't fully initialize the status bar on Windows 7 and leaves it with 1 part
//
in such case force the view to refresh after the status bar is fully visible
((CExplorerBHO*)uIdSubclass)->
m_bForceRefresh
=
false
;
if
(
SendMessage
(hWnd,
SB_GETPARTS
,
0
,
0
)<=
1
)
PostMessage
(
GetParent
(hWnd),
WM_COMMAND
,
41504
,
0
);
//
Refresh command
}
if
(uMsg==
SB_SETTEXT
&&
LOWORD
(wParam)==
0
)
{
//
when the text of the first part is changing
//
recalculate the selection size on a timer. this way if the status text is changed frequently
//
the recalculation will not happen every time
SetTimer
(hWnd,uIdSubclass,
10
,
NULL
);
if
(dwRefData&
SPACE_WIN7
)
{
if
(((CExplorerBHO*)uIdSubclass)->
m_bResetStatus
&&
SendMessage
(hWnd,
SB_GETPARTS
,
0
,
0
)<=
1
)
{
//
HACK! there is a bug in Win7 and when the Explorer window is created it doesn't correctly
//
initialize the status bar to have 3 parts. as soon as the user resizes the window the
//
3 parts appear. so here we resize the parent of the status bar to create the 3 parts.
HWND
parent=
GetParent
(hWnd);
RECT
rc;
GetWindowRect
(parent,&rc);
SetWindowPos
(parent,
NULL
,
0
,
0
,rc.
right
-rc.
left
+
1
,rc.
bottom
-rc.
top
,
SWP_NOZORDER
|
SWP_NOMOVE
);
SetWindowPos
(parent,
NULL
,
0
,
0
,rc.
right
-rc.
left
,rc.
bottom
-rc.
top
,
SWP_NOZORDER
|
SWP_NOMOVE
);
//
the first time the status text is set it is too early. so we do this until we get at lest 2 parts
if
(
SendMessage
(hWnd,
SB_GETPARTS
,
0
,
0
)>
1
)
((CExplorerBHO*)uIdSubclass)->
m_bResetStatus
=
false
;
}
}
IShellBrowser *pBrowser=((CExplorerBHO*)uIdSubclass)->
m_pBrowser
;
CComPtr<IShellView> pView;
if
(pBrowser &&
SUCCEEDED
(pBrowser->
QueryActiveShellView
(&pView)))
{
CComQIPtr<IFolderView> pView2=pView;
CComPtr<IPersistFolder2> pFolder;
if
(pView2 &&
SUCCEEDED
(pView2->
GetFolder
(IID_IPersistFolder2,(
void
**)&pFolder)))
{
bool
bInfoTip=
false
;
int
count;
if
((dwRefData&
SPACE_INFOTIP
) &&
SUCCEEDED
(pView2->
ItemCount
(
SVGIO_SELECTION
,&count)) && count==
1
)
{
//
if only one item is selected, show its info in the status bar
CComPtr<IEnumIDList> pEnum;
PITEMID_CHILD
child;
if
(
SUCCEEDED
(pView2->
Items
(
SVGIO_SELECTION
,IID_IEnumIDList,(
void
**)&pEnum)) && pEnum && pEnum->
Next
(
1
,&child,
NULL
)==
S_OK
)
{
CComQIPtr<IShellFolder> pFolder2=pFolder;
if
(pFolder2)
{
CComPtr<IQueryInfo> pQueryInfo;
if
(
SUCCEEDED
(pFolder2->
GetUIObjectOf
(
NULL
,
1
,(
PCUITEMID_CHILD
*)&child,IID_IQueryInfo,
NULL
,(
void
**)&pQueryInfo)))
{
wchar_t
*tip;
if
(
SUCCEEDED
(pQueryInfo->
GetInfoTip
(
QITIPF_DEFAULT
|
QITIPF_SINGLELINE
,&tip)) && tip)
{
Strcpy
(buf,
_countof
(buf),tip);
for
(
wchar_t
*p=buf;*p;p++)
if
(*p==
'
\t
'
)
*p=
'
'
;
CoTaskMemFree
(tip);
bInfoTip=
true
;
lParam=(
LPARAM
)buf;
}
}
}
}
}
if
(!bInfoTip && (dwRefData&
SPACE_WIN7
))
{
//
show the free space of the drive containing the current folder
//
also works for network locations
PIDLIST_ABSOLUTE
pidl;
if
(
SUCCEEDED
(pFolder->
GetCurFolder
(&pidl)))
{
if
(
SHGetPathFromIDList
(pidl,buf))
{
ULARGE_INTEGER
size;
if
(
GetDiskFreeSpaceEx
(buf,
NULL
,
NULL
,&size))
{
const
wchar_t
*text=(
wchar_t
*)lParam;
wchar_t
str[
100
];
StrFormatByteSize64
(size.
QuadPart
,str,
_countof
(str));
Sprintf
(buf,
_countof
(buf),
FindTranslation
(
L"
Status.FreeSpace
"
,
L"
%s (Disk free space: %s)
"
),text,str);
lParam=(
LPARAM
)buf;
}
}
ILFree
(pidl);
}
}
}
}
}
if
(uMsg==
SB_SETTEXT
&&
LOWORD
(wParam)==
1
)
{
return
0
;
}
if
(uMsg==
WM_TIMER
&& wParam==uIdSubclass)
{
//
recalculate the total size of the selected files and show it in part 2 of the status bar
KillTimer
(hWnd,wParam);
IShellBrowser *pBrowser=((CExplorerBHO*)uIdSubclass)->
m_pBrowser
;
__int64 size=-
1
;
CComPtr<IShellView> pView;
if
(pBrowser &&
SUCCEEDED
(pBrowser->
QueryActiveShellView
(&pView)))
{
CComQIPtr<IFolderView> pView2=pView;
CComPtr<IPersistFolder2> pFolder;
PIDLIST_ABSOLUTE
pidl;
if
(pView2 &&
SUCCEEDED
(pView2->
GetFolder
(IID_IPersistFolder2,(
void
**)&pFolder)) &&
SUCCEEDED
(pFolder->
GetCurFolder
(&pidl)))
{
CComQIPtr<IShellFolder2> pFolder2=pFolder;
UINT
type=
SVGIO_SELECTION
;
int
count;
if
((
FAILED
(pView2->
ItemCount
(
SVGIO_SELECTION
,&count)) || count==
0
))
type=
SVGIO_ALLVIEW
;
CComPtr<IEnumIDList> pEnum;
if
(
SUCCEEDED
(pView2->
Items
(type,IID_IEnumIDList,(
void
**)&pEnum)) && pEnum)
{
PITEMID_CHILD
child;
SHCOLUMNID
column={
PSGUID_STORAGE
,
PID_STG_SIZE
};
while
(pEnum->
Next
(
1
,&child,
NULL
)==
S_OK
)
{
CComVariant var;
if
(
SUCCEEDED
(pFolder2->
GetDetailsEx
(child,&column,&var)) && var.
vt
==
VT_UI8
)
{
if
(size<
0
)
size=var.
ullVal
;
else
size+=var.
ullVal
;
}
ILFree
(child);
}
}
ILFree
(pidl);
}
}
if
(size>=
0
)
{
//
format the file size as KB, MB, etc
StrFormatByteSize64
(size,buf,
_countof
(buf));
}
else
buf[
0
]=
0
;
DefSubclassProc
(hWnd,
SB_SETTEXT
,
1
,(
LPARAM
)buf);
}
return
DefSubclassProc
(hWnd,uMsg,wParam,lParam);
}
//
Subclass the rebar in the title bar to handle the title bar Up button
LRESULT
CALLBACK
CExplorerBHO::SubclassRebarProc
(
HWND
hWnd,
UINT
uMsg,
WPARAM
wParam,
LPARAM
lParam,
UINT_PTR
uIdSubclass,
DWORD_PTR
dwRefData )
{
if
(uMsg==
WM_NOTIFY
&& ((
NMHDR
*)lParam)->
hwndFrom
==(
HWND
)dwRefData && ((
NMHDR
*)lParam)->
code
==
NM_CUSTOMDRAW
)
{
//
custom-draw the toolbar. just draw the correct icon and nothing else
NMTBCUSTOMDRAW
*pDraw=(
NMTBCUSTOMDRAW
*)lParam;
if
(pDraw->
nmcd
.
dwDrawStage
==
CDDS_PREPAINT
)
return
CDRF_NOTIFYITEMDRAW
;
if
(pDraw->
nmcd
.
dwDrawStage
==
CDDS_ITEMPREPAINT
)
{
CExplorerBHO *pThis=(CExplorerBHO*)uIdSubclass;
BOOL
comp;
if
(
SUCCEEDED
(
DwmIsCompositionEnabled
(&comp)) && comp)
FillRect
(pDraw->
nmcd
.
hdc
,&pDraw->
nmcd
.
rc
,(
HBRUSH
)
GetStockObject
(
BLACK_BRUSH
));
if
(pDraw->
nmcd
.
uItemState
&
CDIS_DISABLED
)
{
if
(pThis->
m_IconDisabled
)
DrawIconEx
(pDraw->
nmcd
.
hdc
,
0
,
0
,pThis->
m_IconDisabled
,
0
,
0
,
0
,
NULL
,
DI_NORMAL
|
DI_NOMIRROR
);
else
DrawIconEx
(pDraw->
nmcd
.
hdc
,
0
,
0
,pThis->
m_IconNormal
,
0
,
0
,
0
,
NULL
,
DI_NORMAL
|
DI_NOMIRROR
);
}
else
if
(pDraw->
nmcd
.
uItemState
&
CDIS_SELECTED
)
{
if
(pThis->
m_IconPressed
)
DrawIconEx
(pDraw->
nmcd
.
hdc
,
0
,
0
,pThis->
m_IconPressed
,
0
,
0
,
0
,
NULL
,
DI_NORMAL
|
DI_NOMIRROR
);
else
DrawIconEx
(pDraw->
nmcd
.
hdc
,
1
,
1
,pThis->
m_IconNormal
,
0
,
0
,
0
,
NULL
,
DI_NORMAL
|
DI_NOMIRROR
);
}
else
if
(pDraw->
nmcd
.
uItemState
&
CDIS_HOT
)
{
if
(pThis->
m_IconHot
)
DrawIconEx
(pDraw->
nmcd
.
hdc
,
0
,
0
,pThis->
m_IconHot
,
0
,
0
,
0
,
NULL
,
DI_NORMAL
|
DI_NOMIRROR
);
else
DrawIconEx
(pDraw->
nmcd
.
hdc
,
0
,
0
,pThis->
m_IconNormal
,
0
,
0
,
0
,
NULL
,
DI_NORMAL
|
DI_NOMIRROR
);
}
else
DrawIconEx
(pDraw->
nmcd
.
hdc
,
0
,
0
,pThis->
m_IconNormal
,
0
,
0
,
0
,
NULL
,
DI_NORMAL
|
DI_NOMIRROR
);
return
CDRF_SKIPDEFAULT
;
}
}
if
(uMsg==
WM_THEMECHANGED
)
{
//
the button size is reset when the theme changes. force the correct size again
HWND
toolbar=(
HWND
)dwRefData;
RECT
rc;
GetClientRect
(toolbar,&rc);
PostMessage
(toolbar,
TB_SETBUTTONSIZE
,
0
,
MAKELONG
(rc.
right
,rc.
bottom
));
}
if
(uMsg==
WM_NOTIFY
&& ((
NMHDR
*)lParam)->
hwndFrom
==(
HWND
)dwRefData && ((
NMHDR
*)lParam)->
code
==
TBN_GETINFOTIP
)
{
//
show the tip for the up button
NMTBGETINFOTIP
*pTip=(
NMTBGETINFOTIP
*)lParam;
Strcpy
(pTip->
pszText
,pTip->
cchTextMax
,
FindTranslation
(
L"
Toolbar.GoUp
"
,
L"
Up One Level
"
));
return
0
;
}
if
(uMsg==
WM_NOTIFY
&& ((
NMHDR
*)lParam)->
hwndFrom
==(
HWND
)dwRefData && ((
NMHDR
*)lParam)->
code
==
NM_RCLICK
)
{
NMMOUSE
*pInfo=(
NMMOUSE
*)lParam;
POINT
pt=pInfo->
pt
;
ClientToScreen
(pInfo->
hdr
.
hwndFrom
,&pt);
ShowSettingsMenu
(hWnd,pt.
x
,pt.
y
);
return
TRUE
;
}
if
(uMsg==
WM_COMMAND
&& wParam==
1
)
{
UINT
flags=(
GetKeyState
(
VK_CONTROL
)<
0
?
SBSP_NEWBROWSER
:
SBSP_SAMEBROWSER
);
((CExplorerBHO*)uIdSubclass)->
m_pBrowser
->
BrowseObject
(
NULL
,flags|
SBSP_PARENT
);
}
CExplorerBHO *pThis=(CExplorerBHO*)uIdSubclass;
if
(pThis->
m_bRemapBands
)
{
//
HACK! Explorer doesn't use RB_IDTOINDEX every time it needs to access a particular band. Since we insert the Up button in the second
//
position, the rest of the bands get offset and comedy ensues (the search box is not sized properly).
//
To fix the issue, we renumber the bands so that from the outside ours appears to be last.
static
int
remapNewOld[
2
][
4
]={{
3
,
0
,
1
,
2
},{
0
,
3
,
1
,
2
}};
static
int
remapOldNew[
2
][
4
]={{
1
,
2
,
3
,
0
},{
0
,
2
,
3
,
1
}};
if
(uMsg==
RB_IDTOINDEX
|| uMsg==
RB_HITTEST
)
{
//
remap the result from RB_IDTOINDEX and RB_HITTEST
LRESULT
res=
DefSubclassProc
(hWnd,uMsg,wParam,lParam);
if
(res<
0
|| res>
3
)
return
res;
res=remapNewOld[pThis->
m_UpButtonIndex
-
1
][res];
if
(lParam && uMsg==
RB_HITTEST
) ((
RBHITTESTINFO
*)lParam)->
iBand
=(
int
)res;
return
res;
}
if
(uMsg==
RB_GETBANDBORDERS
|| uMsg==
RB_GETBANDINFO
|| uMsg==
RB_GETRECT
|| uMsg==
RB_SETBANDINFO
|| uMsg==
RB_SETBANDWIDTH
)
{
//
remap wParam for all GET/SET messages
if
(wParam>=
0
&& wParam<=
3
)
wParam=remapOldNew[pThis->
m_UpButtonIndex
-
1
][wParam];
}
}
return
DefSubclassProc
(hWnd,uMsg,wParam,lParam);
}
//
Subclass the breadcrumbs to make them show the full path
LRESULT
CALLBACK
CExplorerBHO::SubclassBreadcrumbProc
(
HWND
hWnd,
UINT
uMsg,
WPARAM
wParam,
LPARAM
lParam,
UINT_PTR
uIdSubclass,
DWORD_PTR
dwRefData )
{
CExplorerBHO *pThis=(CExplorerBHO*)uIdSubclass;
if
(*pThis->
m_CurPath
)
{
if
(uMsg==
WM_SETFOCUS
)
{
if
(wParam)
{
//
see if the focus comes from the combo box. if so, most likely Escape was pressed, so just focus the main frame
HWND
from=(
HWND
)wParam;
HWND
combo=
FindChildWindow
(
GetParent
(
GetParent
(hWnd)),
WC_COMBOBOXEX
);
if
(combo && (combo==from ||
IsChild
(combo,from)))
{
SetFocus
(
GetAncestor
(hWnd,
GA_ROOT
));
return
0
;
}
}
//
when the breadcrumbs are focused, switch to the combobox by simulating a mouse click
RECT
rc;
GetClientRect
(hWnd,&rc);
LPARAM
pos=
MAKELONG
(rc.
right
-
1
,rc.
bottom
/
2
);
DefSubclassProc
(hWnd,
WM_LBUTTONDOWN
,
MK_LBUTTON
,pos);
DefSubclassProc
(hWnd,
WM_LBUTTONUP
,
0
,pos);
return
0
;
}
if
(uMsg==
WM_LBUTTONDOWN
|| uMsg==
WM_LBUTTONDBLCLK
|| uMsg==
WM_LBUTTONUP
)
{
//
unless the mouse is clicked on the icon, replace the mouse position with a point on the far right.
//
this will cause Explorer to switch to the combobox even when a breadcrumb is clicked
int
iconSize=
GetSystemMetrics
(
SM_CXSMICON
);
if
(!pThis->
m_CurIcon
|| (
short
)
LOWORD
(lParam)>iconSize+
3
)
{
RECT
rc;
GetClientRect
(hWnd,&rc);
lParam=
MAKELONG
(rc.
right
-
1
,rc.
bottom
/
2
);
}
}
if
(uMsg==
WM_PAINT
)
{
//
make the breadcrumbs control draw the full path like the XP address bar
RECT
rc;
GetClientRect
(hWnd,&rc);
PAINTSTRUCT
ps;
HDC
hdc=
BeginPaint
(hWnd,&ps);
//
we need to use buffered painting because DrawThemeTextEx with DTT_COMPOSITED requires it
//
on Vista DTT_COMPOSITED is required so that the black text doesn't get transparent. On Windows 7 regular DrawText seems to work fine
BP_PAINTPARAMS
paintParams={
sizeof
(paintParams)};
paintParams.
dwFlags
=
BPPF_ERASE
;
HDC
hdcPaint=
NULL
;
HPAINTBUFFER
hBufferedPaint=
BeginBufferedPaint
(hdc,&rc,
BPBF_TOPDOWNDIB
,&paintParams,&hdcPaint);
if
(hdcPaint)
{
rc.
top
++;
SendMessage
(
GetParent
(
GetParent
(hWnd)),
WM_PRINTCLIENT
,(
WPARAM
)hdcPaint,
PRF_CLIENT
);
//
draw icon
int
iconSize=
GetSystemMetrics
(
SM_CXSMICON
);
if
(pThis->
m_CurIcon
)
DrawIconEx
(hdcPaint,rc.
left
+
3
,(rc.
top
+rc.
bottom
-iconSize)/
2
,pThis->
m_CurIcon
,iconSize,iconSize,
0
,
NULL
,
DI_NORMAL
);
rc.
left
+=iconSize+
8
;
//
Not a good idea to hard-code number of pixels, but seems to work fine for different DPI settings
//
draw path
HFONT
font=(
HFONT
)
SendMessage
(hWnd,
WM_GETFONT
,
0
,
0
);
HFONT
font0=(
HFONT
)
SelectObject
(hdcPaint,font);
SetBkMode
(hdcPaint,
TRANSPARENT
);
SetTextColor
(hdcPaint,
GetSysColor
(
COLOR_WINDOWTEXT
));
HTHEME
theme=
GetWindowTheme
(hWnd);
BOOL
dwm;
if
(theme &&
SUCCEEDED
(
DwmIsCompositionEnabled
(&dwm)) && dwm)
{
DTTOPTS
opts={
sizeof
(opts),
DTT_COMPOSITED
|
DTT_TEXTCOLOR
};
opts.
crText
=
GetSysColor
(
COLOR_WINDOWTEXT
);
DrawThemeTextEx
(theme,hdcPaint,
0
,
0
,pThis->
m_CurPath
,-
1
,
DT_NOPREFIX
|
DT_VCENTER
|
DT_SINGLELINE
,&rc,&opts);
}
else
{
DrawText
(hdcPaint,pThis->
m_CurPath
,-
1
,&rc,
DT_NOPREFIX
|
DT_VCENTER
|
DT_SINGLELINE
);
}
SelectObject
(hdcPaint,font0);
EndBufferedPaint
(hBufferedPaint,
TRUE
);
}
EndPaint
(hWnd,&ps);
return
0
;
}
}
return
DefSubclassProc
(hWnd,uMsg,wParam,lParam);
}
//
Subclass the progress bar behind the address bar to remove the history and replace it with a list of parent folders
LRESULT
CALLBACK
CExplorerBHO::SubclassProgressProc
(
HWND
hWnd,
UINT
uMsg,
WPARAM
wParam,
LPARAM
lParam,
UINT_PTR
uIdSubclass,
DWORD_PTR
dwRefData )
{
CExplorerBHO *pThis=(CExplorerBHO*)uIdSubclass;
if
(uMsg==
WM_PARENTNOTIFY
&&
LOWORD
(wParam)==
WM_CREATE
&& !pThis->
m_ComboBox
.
m_hWnd
)
{
//
on Windows 7 the combobox is not created at startup. so listen for child windows being created and update pThis->m_ComboBox
HWND
combo=(
HWND
)lParam;
wchar_t
className[
256
];
GetClassName
(combo,className,
_countof
(className));
if
(
_wcsicmp
(className,
WC_COMBOBOXEX
)==
0
)
pThis->
m_ComboBox
=combo;
}
if
(uMsg==
WM_COMMAND
&& (
HWND
)lParam==pThis->
m_ComboBox
.
m_hWnd
)
{
if
(
HIWORD
(wParam)==
CBN_DROPDOWN
)
{
//
on drop down refresh the list
pThis->
ClearComboItems
();
CComPtr<IShellFolder> pDesktop;
SHGetDesktopFolder
(&pDesktop);
{
//
add desktop
ITEMIDLIST
shEmpty={{
0
}};
wchar_t
*pName;
if
(
SUCCEEDED
(
SHGetNameFromIDList
((
PIDLIST_ABSOLUTE
)&shEmpty,
SIGDN_DESKTOPABSOLUTEEDITING
,&pName)))
{
ComboItem item={
ILCloneFull
((
PIDLIST_ABSOLUTE
)&shEmpty),
0
,
CString
(pName)};
pThis->
m_ComboItems
.
push_back
(item);
CoTaskMemFree
(pName);
}
}
if
(dwRefData==
2
)
{
//
enumerate all desktop items
CComPtr<IEnumIDList> pEnum;
if
(
SUCCEEDED
(pDesktop->
EnumObjects
(
NULL
,
SHCONTF_FOLDERS
,&pEnum)) && pEnum)
{
PITEMID_CHILD
child;
while
(pEnum->
Next
(
1
,&child,
NULL
)==
S_OK
)
{
STRRET
str;
if
(
SUCCEEDED
(pDesktop->
GetDisplayNameOf
(child,
SHGDN_INFOLDER
|
SHGDN_NORMAL
,&str)))
{
wchar_t
*pName;
StrRetToStr
(&str,child,&pName);
ComboItem item={(
PIDLIST_ABSOLUTE
)child,
1
,
CString
(pName)};
item.
sortName
=item.
name
;
pThis->
m_ComboItems
.
push_back
(item);
CoTaskMemFree
(pName);
}
else
ILFree
(child);
}
}
//
sort desktop items
std::sort
(pThis->
m_ComboItems
.
begin
()+
1
,pThis->
m_ComboItems
.
end
());
}
if
(dwRefData==
2
)
{
//
enumerate all computer items
PIDLIST_ABSOLUTE
pidlComp;
SHGetKnownFolderIDList
(FOLDERID_ComputerFolder,
0
,
NULL
,&pidlComp);
int
index=
1
;
for
(
int
i=
1
;i<(
int
)pThis->
m_ComboItems
.
size
();i++)
if
(
ILIsEqual
(pidlComp,pThis->
m_ComboItems
[i].
pidl
))
{
index=i+
1
;
break
;
}
int
index0=index;
CComPtr<IShellFolder> pComputer;
pDesktop->
BindToObject
(pidlComp,
NULL
,IID_IShellFolder,(
void
**)&pComputer);
CComPtr<IEnumIDList> pEnum;
if
(pComputer &&
SUCCEEDED
(pComputer->
EnumObjects
(
NULL
,
SHCONTF_FOLDERS
,&pEnum)) && pEnum)
{
PITEMID_CHILD
child;
while
(pEnum->
Next
(
1
,&child,
NULL
)==
S_OK
)
{
STRRET
str;
if
(
SUCCEEDED
(pComputer->
GetDisplayNameOf
(child,
SHGDN_INFOLDER
|
SHGDN_NORMAL
,&str)))
{
wchar_t
*pName;
StrRetToStr
(&str,child,&pName);
ComboItem item={
ILCombine
(pidlComp,child),
2
,
CString
(pName)};
pThis->
m_ComboItems
.
insert
(pThis->
m_ComboItems
.
begin
()+index,
1
,item);
CoTaskMemFree
(pName);
index++;
}
ILFree
(child);
}
}
ILFree
(pidlComp);
//
sort computer items
std::sort
(pThis->
m_ComboItems
.
begin
()+index0,pThis->
m_ComboItems
.
begin
()+index);
}
if
(pThis->
m_CurPidl
)
{
//
enumerate all parent items
PIDLIST_ABSOLUTE
pidl=
ILCloneFull
(pThis->
m_CurPidl
);
PIDLIST_ABSOLUTE
pidlStart=pidl;
int
index=
0
;
for
(
int
i=
0
;i<(
int
)pThis->
m_ComboItems
.
size
();i++)
{
PIDLIST_ABSOLUTE
p=(
PIDLIST_ABSOLUTE
)
ILFindChild
(pThis->
m_ComboItems
[i].
pidl
,pidl);
if
(p)
{
index=i;
pidlStart=p;
}
}
int
n=
0
;
for
(
PUIDLIST_RELATIVE
child=pidl;!
ILIsEmpty
(child);child=
ILGetNext
(child))
n++;
int
start=n;
for
(
PUIDLIST_RELATIVE
child=pidlStart;!
ILIsEmpty
(child);child=
ILGetNext
(child))
start--;
for
(
int
i=start;i<n;i++)
{
wchar_t
*pName=
NULL
;
CComPtr<IShellFolder> pFolder;
PCITEMID_CHILD
child;
if
(
SUCCEEDED
(
SHBindToParent
(pidl,IID_IShellFolder,(
void
**)&pFolder,&child)))
{
STRRET
str;
if
(
SUCCEEDED
(pFolder->
GetDisplayNameOf
(child,
SHGDN_INFOLDER
|
SHGDN_NORMAL
,&str)))
{
wchar_t
*pName;
StrRetToStr
(&str,child,&pName);
ComboItem item={
ILCloneFull
(pidl),n-(i-start),
CString
(pName)};
pThis->
m_ComboItems
.
insert
(pThis->
m_ComboItems
.
begin
()+index+
1
,
1
,item);
CoTaskMemFree
(pName);
}
}
ILRemoveLastID
(pidl);
}
ILFree
(pidl);
}
//
add all sorted items to the combobox
COMBOBOXEXITEM
item={
CBEIF_TEXT
|
CBEIF_IMAGE
|
CBEIF_SELECTEDIMAGE
|
CBEIF_INDENT
|
CBEIF_LPARAM
};
item.
iItem
=-
1
;
for
(std::vector<ComboItem>::const_iterator it=pThis->
m_ComboItems
.
begin
();it!=pThis->
m_ComboItems
.
end
();++it)
{
item.
iImage
=item.
iSelectedImage
=-
1
;
item.
pszText
=(
LPWSTR
)(
LPCWSTR
)it->
name
;
item.
iIndent
=it->
indent
;
item.
lParam
=(
LPARAM
)it->
pidl
;
SHFILEINFO
info;
if
(
SHGetFileInfo
((
LPCTSTR
)it->
pidl
,
0
,&info,
sizeof
(info),
SHGFI_PIDL
|
SHGFI_SYSICONINDEX
|
SHGFI_SMALLICON
))
item.
iImage
=item.
iSelectedImage
=info.
iIcon
;
int
idx=(
int
)pThis->
m_ComboBox
.
SendMessage
(
CBEM_INSERTITEM
,
'
CLSH
'
,(
LPARAM
)&item);
if
(pThis->
m_CurPidl
&&
ILIsEqual
(it->
pidl
,pThis->
m_CurPidl
))
pThis->
m_ComboBox
.
SendMessage
(
CB_SETCURSEL
,idx);
}
return
0
;
}
if
(
HIWORD
(wParam)==
CBN_CLOSEUP
||
HIWORD
(wParam)==
CBN_SELENDCANCEL
)
{
//
on close clear the list
if
(!pThis->
m_ComboItems
.
empty
())
{
pThis->
m_ComboBox
.
SetWindowText
(pThis->
m_CurPath
);
pThis->
ClearComboItems
();
}
if
(
HIWORD
(wParam)==
CBN_SELENDCANCEL
)
PostMessage
(hWnd,pThis->
m_NavigateMsg
,
1
,
0
);
return
0
;
}
if
(
HIWORD
(wParam)==
CBN_SELENDOK
)
{
//
when an item is selected, go to it and clear the list (selection with mouse)
int
index=(
int
)pThis->
m_ComboBox
.
SendMessage
(
CB_GETCURSEL
);
if
(index>=
0
)
{
COMBOBOXEXITEM
item={
CBEIF_LPARAM
,index};
pThis->
m_ComboBox
.
SendMessage
(
CBEM_GETITEM
,
0
,(
LPARAM
)&item);
pThis->
m_NavigatePidl
=
ILCloneFull
((
PIDLIST_ABSOLUTE
)item.
lParam
);
PostMessage
(hWnd,pThis->
m_NavigateMsg
,
0
,
0
);
}
pThis->
ClearComboItems
();
return
0
;
}
}
if
(uMsg==
WM_NOTIFY
&& ((
NMHDR
*)lParam)->
code
==
CBEN_BEGINEDIT
)
{
//
ignore this, so Explorer doesn't add its history to the list
return
0
;
}
if
(uMsg==
WM_NOTIFY
&& ((
NMHDR
*)lParam)->
code
==
CBEN_ENDEDIT
)
{
if
(pThis->
m_ComboBox
.
SendMessage
(
CB_GETDROPPEDSTATE
))
{
//
when an item is selected, go to it and clear the list (selection with keyboard)
NMCBEENDEDIT
*pEdit=(
NMCBEENDEDIT
*)lParam;
int
index=pEdit->
iNewSelection
;
if
(index>=
0
)
{
COMBOBOXEXITEM
item={
CBEIF_LPARAM
,index};
pThis->
m_ComboBox
.
SendMessage
(
CBEM_GETITEM
,
0
,(
LPARAM
)&item);
pThis->
m_NavigatePidl
=
ILCloneFull
((
PIDLIST_ABSOLUTE
)item.
lParam
);
pThis->
ClearComboItems
();
PostMessage
(hWnd,pThis->
m_NavigateMsg
,
0
,
0
);
pThis->
m_ComboBox
.
SendMessage
(
CB_SHOWDROPDOWN
,
FALSE
);
}
return
0
;
}
}
if
(uMsg==pThis->
m_NavigateMsg
)
{
//
navigate to the selected item
if
(wParam==
0
&& pThis->
m_NavigatePidl
&& !(pThis->
m_CurPidl
&&
ILIsEqual
(pThis->
m_NavigatePidl
,pThis->
m_CurPidl
)))
pThis->
m_pBrowser
->
BrowseObject
(pThis->
m_NavigatePidl
,
SBSP_SAMEBROWSER
|
SBSP_ABSOLUTE
);
else
SetFocus
(hWnd);
if
(pThis->
m_NavigatePidl
)
ILFree
(pThis->
m_NavigatePidl
);
pThis->
m_NavigatePidl
=
NULL
;
}
return
DefSubclassProc
(hWnd,uMsg,wParam,lParam);
}
static
void
NewVersionCallback
(
DWORD
newVersion, CString downloadUrl, CString news )
{
if
(newVersion>
GetVersionEx
(g_Instance))
{
wchar_t
path[_MAX_PATH];
GetModuleFileName
(g_Instance,path,
_countof
(path));
PathRemoveFileSpec
(path);
PathAppend
(path,
L"
ClassicShellUpdate.exe
"
);
wchar_t
cmdLine[
1024
];
Sprintf
(cmdLine,
_countof
(cmdLine),
L"
\"
%s
\"
-popup
"
,path);
STARTUPINFO
startupInfo={
sizeof
(startupInfo)};
PROCESS_INFORMATION
processInfo;
memset
(&processInfo,
0
,
sizeof
(processInfo));
if
(
CreateProcess
(path,cmdLine,
NULL
,
NULL
,
TRUE
,
0
,
NULL
,
NULL
,&startupInfo,&processInfo))
{
CloseHandle
(processInfo.
hThread
);
CloseHandle
(processInfo.
hProcess
);
}
}
}
HRESULT
STDMETHODCALLTYPE
CExplorerBHO::SetSite
( IUnknown *pUnkSite )
{
IObjectWithSiteImpl<CExplorerBHO>::
SetSite
(pUnkSite);
if
(pUnkSite)
{
//
hook
GetTlsData
()->
bho
=
this
;
if
(!m_Hook)
{
m_Hook=
SetWindowsHookEx
(
WH_CBT
,HookExplorer,
NULL
,
GetCurrentThreadId
());
}
CComQIPtr<IServiceProvider> pProvider=pUnkSite;
if
(pProvider)
{
pProvider->
QueryService
(SID_SShellBrowser,IID_IShellBrowser,(
void
**)&m_pBrowser);
//
listen for web browser notifications. we only care about DISPID_NAVIGATECOMPLETE2 and DISPID_ONQUIT
pProvider->
QueryService
(SID_SWebBrowserApp,IID_IWebBrowser2,(
void
**)&m_pWebBrowser);
if
(m_pWebBrowser)
{
if
(m_dwEventCookie==
0xFEFEFEFE
)
//
ATL's event cookie is 0xFEFEFEFE when the sink is not advised
DispEventAdvise
(m_pWebBrowser,&DIID_DWebBrowserEvents2);
CRegKey regKey;
if
(regKey.
Open
(
HKEY_CURRENT_USER
,
GetSettingsRegPath
())!=
ERROR_SUCCESS
)
regKey.
Create
(
HKEY_CURRENT_USER
,
GetSettingsRegPath
());
DWORD
val;
if
(regKey.
QueryDWORDValue
(
L"
ShowedToolbar
"
,val)!=
ERROR_SUCCESS
|| !val)
{
CComVariant
name
(
L"
{553891B7-A0D5-4526-BE18-D3CE461D6310}
"
);
CComVariant
show
(
true
);
if
(
SUCCEEDED
(m_pWebBrowser->
ShowBrowserBar
(&name,&show,
NULL
)))
regKey.
SetDWORDValue
(
L"
ShowedToolbar
"
,
1
);
}
}
HWND
status;
if
(m_pBrowser &&
SUCCEEDED
(m_pBrowser->
GetControlWindow
(
FCW_STATUS
,&status)))
{
m_TopWindow=
GetAncestor
(status,
GA_ROOT
);
if
(!
GetProp
(m_TopWindow,g_LoadedSettingsAtom))
{
SetProp
(m_TopWindow,g_LoadedSettingsAtom,(
HANDLE
)
1
);
LoadSettings
();
}
bool
bWin7=(
GetWinVersion
()==
WIN_VER_WIN7
);
bool
bWin8=(
GetWinVersion
()>=
WIN_VER_WIN8
);
m_UpButtonIndex=bWin8?
0
:
GetSettingInt
(
L"
ShowUpButton
"
);
bool
bShowCaption=!bWin8 &&
GetSettingBool
(
L"
ShowCaption
"
);
bool
bShowIcon=!bWin8 &&
GetSettingBool
(
L"
ShowIcon
"
);
if
(m_TopWindow && (bShowCaption || bShowIcon))
{
//
show the title and the icon for the main Explorer window
DWORD
flags=
WTNCA_NODRAWCAPTION
|
WTNCA_NODRAWICON
;
if
(bShowCaption) flags&=~
WTNCA_NODRAWCAPTION
;
if
(bShowIcon) flags&=~
WTNCA_NODRAWICON
;
SetWindowThemeNonClientAttributes
(m_TopWindow,
WTNCA_NODRAWCAPTION
|
WTNCA_NODRAWICON
,flags);
}
//
find the TravelBand and the rebar
HWND
band=
NULL
, rebar=
NULL
;
if
(m_TopWindow)
band=
FindChildWindow
(m_TopWindow,
L"
TravelBand
"
);
if
(band)
rebar=
GetParent
(band);
bool
bRedrawRebar=
false
;
m_Rebar=rebar;
m_AltD=
0
;
if
(rebar &&
GetSettingBool
(
L"
HideSearch
"
))
{
//
to remove the Search box, first find the band with ID=2 (or 4 for Win8). Then disable the child control and hide the band
int
idx=(
int
)
SendMessage
(rebar,
RB_IDTOINDEX
,bWin8?
4
:
2
,
0
);
if
(idx>=
0
)
{
REBARBANDINFO
info={
sizeof
(info),
RBBIM_CHILD
};
SendMessage
(rebar,
RB_GETBANDINFO
,idx,(
LPARAM
)&info);
if
(info.
hwndChild
)
EnableWindow
(info.
hwndChild
,
FALSE
);
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL