forked from Baron-von-Riedesel/ExplASM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCShellBrowser.asm
More file actions
2949 lines (2431 loc) · 70.6 KB
/
CShellBrowser.asm
File metadata and controls
2949 lines (2431 loc) · 70.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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
;--- CShellBrowser object
;--- that's a simple explorer
.386
.model flat, stdcall
option casemap:none
option proc:private
.nolist
.nocref
WIN32_LEAN_AND_MEAN equ 1
INCL_OLE2 equ 1
_WIN32_IE equ 500h
include windows.inc
include commctrl.inc
include dde.inc
include windowsx.inc
include wincrack.inc
include shellapi.inc
include objidl.inc
include olectl.inc
include shlguid.inc
include shlobj.inc
include shlwapi.inc
include shobjidl.inc
?AGGREGATION = 0 ;no aggregation
?EVENTSUPPORT = 0 ;no event support
include olecntrl.inc
include debugout.inc
include rsrc.inc
.list
.cref
include macros.inc
INSIDE_CShellBrowser equ 1
include CShellBrowser.inc
SFGAOF typedef DWORD
?IMAGELIST equ 1 ;use IExtractIcon and set icons in tree view
?RETURNCMD equ 1
WM_SHNOTIFY equ 401h ;window message for shell change notifications
WM_GETISHELLBROWSER equ 407h ;undocumented window message
;--- pointer to SHNOTIFYSTRUCT is in wParam of WM_SHNOTIFY
SHNOTIFYSTRUCT struct
dwItem1 DWORD ?
dwItem2 DWORD ?
SHNOTIFYSTRUCT ends
IDM_FIRST equ FCIDM_SHVIEWFIRST
IDM_LAST equ IDM_FIRST+100
WndProc PROTO :HWND, :DWORD, :WPARAM, :LPARAM
WndProc@CShellBrowser PROTO :ptr CShellBrowser, :DWORD, :WPARAM, :LPARAM
Destroy@CShellBrowser PROTO :ptr CShellBrowser
SetShellView@CShellBrowser PROTO :ptr CShellBrowser, :LPSHELLVIEW
;SHBindToParent PROTO :LPITEMIDLIST, :REFIID, :ptr LPUNKNOWN, :ptr LPITEMIDLIST
OnSize PROTO
InsertChildItems PROTO :HANDLE
GetFolder PROTO :HANDLE
GetDDEVariables PROTO
OnDDEExecute PROTO :LPSTR
TranslateAcceleratorSB PROTO :ptr CShellBrowser, lpmsg:ptr MSG, wID:WORD
.data
g_hAccel HACCEL NULL
g_hCursor HCURSOR NULL
g_hHalftoneBrush HBRUSH NULL
g_hWndFocus HWND NULL
g_dwCount DWORD 0
g_rect RECT {0,0,0,0}
g_himl HANDLE NULL
g_EditWndProc DWORD 0
if ?DRAGDROPHELPER
g_pDropTargetHelper LPDROPTARGETHELPER NULL
endif
g_szPath db MAX_PATH dup(9)
protoSHChangeNotifyRegister typedef proto :HWND, :DWORD, :DWORD, :DWORD, :DWORD, :ptr LPITEMIDLIST
protoSHChangeNotifyUnregister typedef proto :HANDLE
protoSHParseDisplayName typedef proto :ptr WORD, :DWORD, :ptr LPITEMIDLIST, :SFGAOF, :ptr SFGAOF
LPFNSHCHANGENOTIFYREGISTER typedef ptr protoSHChangeNotifyRegister
LPFNSHCHANGENOTIFYUNREGISTER typedef ptr protoSHChangeNotifyUnregister
LPFNSHPARSEDISPLAYNAME typedef ptr protoSHParseDisplayName
g_lpfnSHChangeNotifyRegister LPFNSHCHANGENOTIFYREGISTER NULL
g_lpfnSHChangeNotifyUnregister LPFNSHCHANGENOTIFYUNREGISTER NULL
g_lpfnSHParseDisplayName LPFNSHPARSEDISPLAYNAME NULL
g_bSort BOOLEAN TRUE
g_bRegistered BOOLEAN FALSE
g_bGetUIObjectOf BOOLEAN TRUE
g_bCreateView BOOLEAN FALSE
g_bCompMenus BOOLEAN TRUE
g_bStatusBar BOOLEAN TRUE
g_bDropTarget BOOLEAN TRUE
g_bTrackSelect BOOLEAN TRUE
g_bBrowseFiles BOOLEAN TRUE
.const
align 4
;IID_IShellBrowser sIID_IShellBrowser
;IID_IShellFolder sIID_IShellFolder
;IID_IShellView sIID_IShellView
;IID_IContextMenu sIID_IContextMenu
if ?DRAGDROPHELPER
;CLSID_DragDropHelper sCLSID_DragDropHelper
;IID_IDropTargetHelper sIID_IDropTargetHelper
endif
;--- vtable for interface IShellBrowser
CShellBrowserVtbl label dword
IUnknownVtbl {QueryInterface@CShellBrowser, AddRef@CShellBrowser, Release@CShellBrowser}
dd GetWindow_, ContextSensitiveHelp
dd InsertMenusSB, SetMenuSB, RemoveMenusSB
dd SetStatusTextSB, EnableModelessSB, TranslateAcceleratorSB
dd BrowseObject, GetViewStateStream, GetControlWindow
dd SendControlMsg, QueryActiveShellView, OnViewWindowActive, SetToolbarItems
if ?OLECOMMANDTARGET
@if1 textequ <, IOleCommandTarget>
else
@if1 textequ <>
endif
if ?SERVICEPROVIDER
@if2 textequ <, IServiceProvider>
else
@if2 textequ <>
endif
if ?DROPTARGET
@if3 textequ <, IDropTarget>
else
@if3 textequ <>
endif
if ?OLEINPLACEFRAME
@if4 textequ <, IOleWindow, IOleInPlaceUIWindow, IOleInPlaceFrame>
else
@if4 textequ <>
endif
% DEFINE_KNOWN_INTERFACES CShellBrowser, IShellBrowser @if1 @if2 @if3 @if4
szAppNameEx db " - "
szAppName db "ExplorerASM",0
ifdef _DEBUG
DEBUGPREFIX LPSTR CStr("ExplorerASM:")
endif
szShell32 db "Shell32.dll",0
.code
__this textequ <ebx>
_this textequ <[__this].CShellBrowser>
MEMBER _IShellBrowser, ObjRefCount
MEMBER hWnd, hWndTV, hWndView, hWndSB, hWndFocus
MEMBER pShellFolder, pShellView, pContextMenu2, pStream, pMalloc
MEMBER rect, dwSizeTV, hSHNotify
MEMBER bCreateView, bGetUIObjectOf, bCompMenus, bStatusBar
MEMBER bDropTarget, bDontRespond, bLabelEdit
if ?OLEINPLACEFRAME
MEMBER _IOleInPlaceFrame, pOleInPlaceActiveObject
endif
if ?WEBBROWSER
MEMBER pWebBrowser
endif
DEFINE_STD_COM_METHODS CShellBrowser
;--- InitApp: this proc is called only once
InitApp proc
local hShell32:HINSTANCE
local pShellIcon:LPSHELLICON
local wNullPidl:WORD
local iIndex:DWORD
local osvi:OSVERSIONINFO
local hIcon:HICON
local dwSize:DWORD
local dwType:DWORD
local szPath[MAX_PATH]:byte
mov osvi.dwOSVersionInfoSize, sizeof OSVERSIONINFO
invoke GetVersionEx, addr osvi
invoke LoadLibrary, addr szShell32
mov hShell32, eax
.if (eax > 32)
invoke GetProcAddress, hShell32, 2
mov g_lpfnSHChangeNotifyRegister, eax
invoke GetProcAddress, hShell32, 4
mov g_lpfnSHChangeNotifyUnregister, eax
invoke GetProcAddress, hShell32, CStr("SHParseDisplayName")
mov g_lpfnSHParseDisplayName, eax
.endif
invoke LoadCursor, g_hInstance, IDC_CURSOR1
mov g_hCursor, eax
invoke LoadAccelerators, g_hInstance, IDR_ACCELERATOR1
mov g_hAccel, eax
if ?IMAGELIST
if 0
invoke GetSystemMetrics, SM_CXSMICON ;returns 0014h ?????
else
mov eax, 0010h
endif
.if ((osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) && (osvi.dwMajorVersion >= 5))
invoke ImageList_Create, eax, eax, ILC_COLOR32 or ILC_MASK, 4, 4
.else
mov g_bBrowseFiles, FALSE
invoke ImageList_Create, eax, eax, ILC_COLORDDB or ILC_MASK, 4, 4
.endif
mov g_himl, eax
if 0
mov dwSize, sizeof szPath
invoke SHGetValue, HKEY_CLASSES_ROOT, CStr("Folder\DefaultIcon"),CStr(""),
addr dwType, addr szPath, addr dwSize
.if (eax == S_OK)
mov eax, ','
invoke StrChr, addr szPath, eax
.if (eax)
mov byte ptr [eax], 0
xor eax, eax
invoke ExtractIcon, g_hInstance, addr szPath, eax
push eax
invoke ImageList_AddIcon, g_himl, eax
pop eax
invoke DestroyIcon, eax
.endif
.endif
else
invoke ExtractIcon, g_hInstance, addr szShell32, 3
.if (eax)
push eax
invoke ImageList_AddIcon( g_himl, eax)
pop eax
invoke DestroyIcon, eax
.endif
invoke ExtractIcon, g_hInstance, addr szShell32, 4
.if (eax)
push eax
invoke ImageList_AddIcon( g_himl, eax)
pop eax
invoke DestroyIcon, eax
.endif
endif
if 0
mov iIndex, 34
invoke vf(m_pShellFolder, IUnknown, QueryInterface), addr IID_IShellIcon, addr pShellIcon
.if (eax == S_OK)
mov wNullPidl,0
invoke vf(pShellIcon, IShellIcon, GetIconOf), addr wNullPidl, GIL_FORSHELL, addr iIndex
invoke vf(pShellIcon, IUnknown, Release)
.endif
invoke ExtractIcon, g_hInstance, addr szShell32, iIndex
else
invoke ExtractIcon, g_hInstance, addr szShell32, 34
endif
.if (eax)
push eax
invoke ImageList_AddIcon( g_himl, eax)
pop eax
invoke DestroyIcon, eax
.endif
endif
invoke GetDDEVariables
if ?DRAGDROPHELPER
invoke CoCreateInstance, addr CLSID_DragDropHelper, NULL,
CLSCTX_INPROC_SERVER, addr IID_IDropTargetHelper, addr g_pDropTargetHelper
endif
invoke FreeLibrary, hShell32
ret
InitApp endp
;--- create a CShellBrowser object
Create@CShellBrowser proc public uses __this pUnknown:LPUNKNOWN
DebugOut "Create@CShellBrowser"
invoke LocalAlloc, LMEM_FIXED or LMEM_ZEROINIT,sizeof CShellBrowser
.if (eax == NULL)
ret
.endif
mov __this,eax
mov m__IShellBrowser.lpVtbl, offset CShellBrowserVtbl
if ?SERVICEPROVIDER
mov m__IServiceProvider.lpVtbl, offset CServiceProviderVtbl
endif
if ?OLECOMMANDTARGET
mov m__IOleCommandTarget.lpVtbl, offset COleCommandTargetVtbl
endif
if ?DROPTARGET
mov m__IDropTarget.lpVtbl, offset CDropTargetVtbl
endif
if ?OLEINPLACEFRAME
mov m__IOleInPlaceFrame.lpVtbl, offset COleInPlaceFrameVtbl
endif
STD_COM_CONSTRUCTOR CShellBrowser
invoke vf(pUnknown, IUnknown, QueryInterface), addr IID_IShellFolder, addr m_pShellFolder
.if (eax != S_OK)
invoke Destroy@CShellBrowser, __this
return 0
.endif
mov m_dwSizeTV, -1
invoke SHGetMalloc, addr m_pMalloc
.if (!g_dwCount)
invoke InitApp
.endif
inc g_dwCount
return __this
align 4
Create@CShellBrowser endp
;--- delete a CShellBrowser object
Destroy@CShellBrowser proc uses __this this_:ptr CShellBrowser
DebugOut "Destroy@CShellBrowser(%X)", this_
mov __this, this_
STD_COM_DESTRUCTOR CShellBrowser
if ?WEBBROWSER
.if (m_pWebBrowser)
invoke vf(m_pWebBrowser, IUnknown, Release)
.endif
endif
.if (m_pShellView)
invoke vf(m_pShellView, IUnknown, Release)
.endif
.if (m_pShellFolder)
invoke vf(m_pShellFolder, IUnknown, Release)
.endif
.if (m_pStream)
invoke vf(m_pStream, IUnknown, Release)
.endif
.if (m_pMalloc)
invoke vf(m_pMalloc, IUnknown, Release)
.endif
dec g_dwCount
.if (!g_dwCount)
if ?DRAGDROPHELPER
.if (g_pDropTargetHelper)
invoke vf(g_pDropTargetHelper, IUnknown, Release)
.endif
endif
if ?IMAGELIST
.if (g_himl)
invoke ImageList_Destroy, g_himl
.endif
endif
.if (g_aApplication)
invoke GlobalDeleteAtom, g_aApplication
.endif
.if (g_aTopic)
invoke GlobalDeleteAtom, g_aTopic
.endif
.endif
invoke LocalFree, this_
ret
align 4
Destroy@CShellBrowser endp
Show@CShellBrowser proc public uses __this this_:ptr CShellBrowser, hWnd:HWND
local wc:WNDCLASSEX
mov __this, this_
.if (hWnd)
invoke GetWindowRect, hWnd, addr m_rect
mov eax, m_rect.right
sub eax, m_rect.left
mov m_rect.right, eax
mov eax, m_rect.bottom
sub eax, m_rect.top
mov m_rect.bottom, eax
add m_rect.left, 16
add m_rect.top, 16
.endif
.if (!g_bRegistered)
invoke RtlZeroMemory, addr wc, sizeof WNDCLASSEX
mov wc.cbSize, sizeof WNDCLASSEX
mov wc.style, 0
mov wc.lpfnWndProc, WndProc
mov eax, g_hInstance
mov wc.hInstance, eax
invoke LoadIcon, g_hInstance, IDI_ICON1
mov wc.hIcon, eax
invoke LoadCursor, NULL, IDC_ARROW
mov wc.hCursor, eax
mov wc.hbrBackground, COLOR_BTNFACE + 1
mov wc.lpszMenuName, IDR_MENU1
mov wc.lpszClassName, offset szAppName
mov wc.hIconSm, NULL
invoke RegisterClassEx, addr wc
mov g_bRegistered, TRUE
.endif
invoke CreateWindowEx, 0, offset szAppName, CStr(""),
WS_OVERLAPPEDWINDOW or WS_VISIBLE, m_rect.left, m_rect.top, m_rect.right, m_rect.bottom,\
hWnd, NULL, g_hInstance, __this
ret
align 4
Show@CShellBrowser endp
;--- send key to view (but do NOT if treeview is in label edit mode)
TranslateAccelerator@CShellBrowser proc public uses __this this_:ptr CShellBrowser, lpmsg:ptr MSG
mov __this, this_
mov eax, S_FALSE
.if (!m_bLabelEdit)
mov eax, m_hWndFocus
.if (eax == m_hWndView)
invoke vf(m_pShellView, IShellView, TranslateAccelerator), lpmsg
.if (eax == S_FALSE)
invoke TranslateAcceleratorSB, __this, lpmsg, NULL
.endif
.else
invoke TranslateAcceleratorSB, __this, lpmsg, NULL
.if (eax == S_FALSE && m_pShellView)
invoke vf(m_pShellView, IShellView, TranslateAccelerator), lpmsg
.endif
.endif
.endif
ret
align 4
TranslateAccelerator@CShellBrowser endp
;----------------------------------------------------------------
if 0
;--- this function is not available in win9x and winnt systems
SHBindToParent proc uses esi edi pidl:LPITEMIDLIST, riid:REFIID, ppUnknown:ptr LPUNKNOWN, ppidl:ptr LPITEMIDLIST
local pShellFolder:LPSHELLFOLDER
local hr:DWORD
xor ecx, ecx
mov eax, ppidl
.if (eax)
mov [eax],ecx
.endif
mov eax, ppUnknown
mov [eax], ecx
mov edx, pidl
.while (edx)
movzx eax,[edx].SHITEMID.cb
.break .if (!eax)
mov esi, ecx
add ecx, eax
lea edx, [eax][edx]
.endw
add esi, sizeof WORD
invoke vf(m_pMalloc, IMalloc, Alloc), esi
.if (eax)
mov ecx, esi
mov esi, pidl
mov edi, eax
rep movsb
mov [edi-2],cx
mov edi, eax
invoke vf(m_pShellFolder, IShellFolder, BindToObject), edi, NULL,\
riid, addr pShellFolder
mov hr, eax
.if (eax == S_OK)
.if (ppidl)
mov ecx, ppidl
mov [ecx],edi
.else
invoke vf(m_pMalloc, IMalloc, Free), edi
.endif
mov ecx, ppUnknown
mov eax, pShellFolder
mov [ecx], eax
.else
invoke vf(m_pMalloc, IMalloc, Free), edi
.endif
mov eax, hr
.else
mov eax, E_OUTOFMEMORY
.endif
ret
align 4
SHBindToParent endp
endif
;----------------------------------------------------------------
;--- release IShellView
ReleaseShellView proc uses esi
.if (m_pShellView)
invoke vf(m_pShellView, IShellView, UIActivate), SVUIA_DEACTIVATE
.if (m_hWndView)
mov eax, m_hWndFocus
.if (eax == m_hWndView)
mov m_hWndFocus, NULL
.endif
invoke vf(m_pShellView, IShellView, DestroyViewWindow)
mov m_hWndView, NULL
.endif
invoke vf(m_pShellView, IUnknown, Release)
mov m_pShellView, NULL
.endif
ret
align 4
ReleaseShellView endp
;--- update menu items
UpdateMenu proc
local hMenu:HMENU
invoke GetMenu, m_hWnd
mov hMenu, eax
.if (m_bStatusBar)
mov ecx, MF_CHECKED
.else
mov ecx, MF_UNCHECKED
.endif
invoke CheckMenuItem, hMenu, IDM_STATUSLINE, ecx
.if (m_bCreateView)
mov ecx, MF_CHECKED
.else
mov ecx, MF_UNCHECKED
.endif
invoke CheckMenuItem, hMenu, IDM_CREATEVIEWOBJECT, ecx
.if (m_bGetUIObjectOf)
mov ecx, MF_CHECKED
.else
mov ecx, MF_UNCHECKED
.endif
invoke CheckMenuItem, hMenu, IDM_GETUIOBJECTOF, ecx
.if (m_bCompMenus)
mov ecx, MF_CHECKED
.else
mov ecx, MF_UNCHECKED
.endif
invoke CheckMenuItem, hMenu, IDM_COMPMENUS, ecx
.if (m_bDropTarget)
mov ecx, MF_CHECKED
.else
mov ecx, MF_UNCHECKED
.endif
invoke CheckMenuItem, hMenu, IDM_DROPTARGET, ecx
.if (g_bTrackSelect)
mov ecx, MF_CHECKED
.else
mov ecx, MF_UNCHECKED
.endif
invoke CheckMenuItem, hMenu, IDM_TRACKSELECT, ecx
.if (!m_bDontRespond)
mov ecx, MF_CHECKED
.else
mov ecx, MF_UNCHECKED
.endif
invoke CheckMenuItem, hMenu, IDM_DDERESPOND, ecx
.if (g_bBrowseFiles)
mov ecx, MF_CHECKED
.else
mov ecx, MF_UNCHECKED
.endif
invoke CheckMenuItem, hMenu, IDM_BROWSEFILES, ecx
ret
align 4
UpdateMenu endp
;--- get attributes of an item
GetAttributes proc hItem:HANDLE, pdwAttributes:ptr DWORD
local pShellFolder:LPSHELLFOLDER
local pItemIDList:LPITEMIDLIST
local tvi:TV_ITEM
mov eax, hItem
mov tvi.hItem, eax
mov tvi.mask_, TVIF_PARAM
invoke TreeView_GetItem( m_hWndTV, addr tvi)
mov eax, tvi.lParam
.if (!eax)
ret
.endif
mov pItemIDList, eax
invoke TreeView_GetParent( m_hWndTV, hItem)
invoke GetFolder, eax
.if (eax)
mov pShellFolder, eax
invoke vf(pShellFolder, IShellFolder, GetAttributesOf), 1, addr pItemIDList,
pdwAttributes
push eax
invoke vf(pShellFolder, IShellFolder, Release)
pop eax
.if (eax == S_OK)
mov eax, TRUE
.else
xor eax, eax
.endif
.endif
ret
align 4
GetAttributes endp
if 0
;--- check if a folder is on a removeable device
IsRemoveable proc hItem:HANDLE
local sfgaof:SFGAOF
mov sfgaof, SFGAO_REMOVABLE
invoke GetAttributes, hItem, addr sfgaof
.if ((eax) && (sfgaof & SFGAO_REMOVABLE))
mov eax, TRUE
.else
mov eax, FALSE
.endif
ret
align 4
IsRemoveable endp
endif
StrRet2String proc pItemIDList:LPITEMIDLIST, pstrret:ptr STRRET, pszText:LPSTR, dwMax:DWORD
mov ecx, pstrret
.if ([ecx].STRRET.uType == STRRET_WSTR)
invoke WideCharToMultiByte, CP_ACP, 0, [ecx].STRRET.pOleStr, -1, pszText, dwMax, 0, 0
mov ecx, pstrret
invoke vf(m_pMalloc, IMalloc, Free), [ecx].STRRET.pOleStr
mov eax, pszText
.elseif ([ecx].STRRET.uType == STRRET_CSTR)
lea eax, [ecx].STRRET.cStr
.else
mov eax, pItemIDList
add eax,[ecx].STRRET.uOffset
.endif
ret
align 4
StrRet2String endp
HRESULT_CODE macro
movsx eax, ax
endm
SortChildrenCB proc lParam1:LPARAM, lParam2:LPARAM, lParamSort:LPARAM
local pShellFolder:LPSHELLFOLDER
mov eax, lParamSort
mov pShellFolder, eax
invoke vf(pShellFolder, IShellFolder, CompareIDs), 0, lParam1, lParam2
HRESULT_CODE
ret
align 4
SortChildrenCB endp
?TESTMODE equ 0
if 1
InsertItem proc hItem:HANDLE, pShellFolder:LPSHELLFOLDER, pidl:LPITEMIDLIST, bValidate:BOOL
local dwRC:BOOL
local sfgaof:SFGAOF
local strret:STRRET
local tvi:TV_INSERTSTRUCT
local szText[MAX_PATH]:byte
mov eax, hItem
mov tvi.hParent, eax
.if (bValidate)
mov tvi.hInsertAfter, TVI_SORT
.else
mov tvi.hInsertAfter, TVI_LAST
.endif
lea eax, szText
mov tvi.item.pszText, eax
mov szText,0
mov dwRC, FALSE
mov strret.uType, STRRET_CSTR
invoke vf(pShellFolder, IShellFolder, GetDisplayNameOf), pidl,\
SHGDN_INFOLDER, addr strret
.if (eax == S_OK)
mov tvi.item.mask_, TVIF_TEXT or TVIF_PARAM or TVIF_CHILDREN
mov eax, pidl
mov tvi.item.lParam, eax
mov sfgaof, SFGAO_HASSUBFOLDER
.if (g_bBrowseFiles)
or sfgaof, SFGAO_BROWSABLE or SFGAO_FOLDER
.endif
if ?TESTMODE
or sfgaof, SFGAO_COMPRESSED or SFGAO_REMOVABLE
endif
invoke vf(pShellFolder, IShellFolder, GetAttributesOf), 1, addr pidl,\
addr sfgaof
.if ((eax == S_OK) && (sfgaof & SFGAO_HASSUBFOLDER))
mov tvi.item.cChildren, 1
.else
.if (g_bBrowseFiles)
mov tvi.item.cChildren, I_CHILDRENCALLBACK
.else
mov tvi.item.cChildren, 0
.endif
.endif
if ?IMAGELIST
or tvi.item.mask_, TVIF_IMAGE or TVIF_SELECTEDIMAGE
mov tvi.item.iSelectedImage, I_IMAGECALLBACK
mov tvi.item.iImage, I_IMAGECALLBACK
endif
.if ((!g_bBrowseFiles) || (sfgaof & (SFGAO_BROWSABLE or SFGAO_FOLDER)))
invoke StrRet2String, pidl, addr strret, tvi.item.pszText, MAX_PATH
mov tvi.item.pszText, eax
if ?TESTMODE
lea ecx, szText
.if (ecx != eax)
mov tvi.item.pszText, ecx
invoke wsprintf, addr szText, CStr("%s,%X"), eax, sfgaof
.else
invoke lstrlen, ecx
lea ecx, szText
add ecx, eax
invoke wsprintf, ecx, CStr(",%X"), sfgaof
.endif
endif
invoke TreeView_InsertItem( m_hWndTV, addr tvi)
mov dwRC, TRUE
.endif
.endif
return dwRC
InsertItem endp
;--- returns number of childs
InsertChildItems proc public hItem:HANDLE
local pShellFolder:LPSHELLFOLDER
local pEnumIDList:LPENUMIDLIST
local pidl:LPITEMIDLIST
local dwChildren:DWORD
local sortcb:TVSORTCB
local tvi:TV_ITEM
invoke GetFolder, hItem
.if (!eax)
return -1
.endif
mov pShellFolder, eax
mov dwChildren, 0
.if (g_bBrowseFiles)
mov ecx,SHCONTF_FOLDERS or SHCONTF_NONFOLDERS or SHCONTF_INCLUDEHIDDEN
.else
mov ecx,SHCONTF_FOLDERS or SHCONTF_INCLUDEHIDDEN
.endif
invoke vf(pShellFolder, IShellFolder, EnumObjects_), m_hWnd, ecx, addr pEnumIDList
.if (eax != S_OK)
invoke vf(pShellFolder, IShellFolder, Release)
return -1
.endif
;--------- now enumerate the objects of the folder and insert them
;--------- into the treeview
.while (1)
invoke vf(pEnumIDList, IEnumIDList, Next), 1, addr pidl, NULL
.break .if (eax != S_OK)
invoke InsertItem, hItem, pShellFolder, pidl, FALSE
.if (eax)
inc dwChildren
.endif
.endw
invoke vf(pEnumIDList, IUnknown, Release)
.if (g_bSort)
mov eax, hItem
mov sortcb.hParent, eax
mov sortcb.lpfnCompare, SortChildrenCB
mov eax, pShellFolder
mov sortcb.lParam, eax
invoke TreeView_SortChildrenCB( m_hWndTV, addr sortcb, 0)
.endif
invoke vf(pShellFolder, IShellFolder, Release)
exit:
mov eax, dwChildren
.if (eax)
mov eax, 1
.endif
mov tvi.cChildren, eax
mov eax, hItem
mov tvi.hItem, eax
mov tvi.mask_, TVIF_CHILDREN or TVIF_STATE
mov tvi.state, TVIS_EXPANDEDONCE
mov tvi.stateMask, TVIS_EXPANDEDONCE
invoke TreeView_SetItem( m_hWndTV, addr tvi)
return dwChildren
align 4
InsertChildItems endp
else
InsertChildItems proc public hItem:HANDLE
local pShellFolder:LPSHELLFOLDER
local pEnumIDList:LPENUMIDLIST
local pidl:LPITEMIDLIST
local sfgaof:SFGAOF
local dwChildren:DWORD
local strret:STRRET
local sortcb:TVSORTCB
local tvi:TV_INSERTSTRUCT
local szText[MAX_PATH]:byte
invoke GetFolder, hItem
.if (!eax)
return -1
.endif
mov pShellFolder, eax
mov eax, hItem
mov tvi.hParent, eax
mov tvi.hInsertAfter, TVI_LAST
mov dwChildren, 0
.if (g_bBrowseFiles)
mov ecx,SHCONTF_FOLDERS or SHCONTF_NONFOLDERS or SHCONTF_INCLUDEHIDDEN
.else
mov ecx,SHCONTF_FOLDERS or SHCONTF_INCLUDEHIDDEN
.endif
invoke vf(pShellFolder, IShellFolder, EnumObjects), m_hWnd, ecx, addr pEnumIDList
.if (eax != S_OK)
invoke vf(pShellFolder, IShellFolder, Release)
return -1
.endif
;--------- now enumerate the objects of the folder and insert them
;--------- into the treeview
.while (1)
invoke vf(pEnumIDList, IEnumIDList, Next), 1, addr pidl, NULL
.break .if (eax != S_OK)
mov strret.uType, STRRET_CSTR
invoke vf(pShellFolder, IShellFolder, GetDisplayNameOf), pidl,\
SHGDN_INFOLDER, addr strret
.if (eax == S_OK)
mov tvi.item.imask, TVIF_TEXT or TVIF_PARAM or TVIF_CHILDREN
mov eax, pidl
mov tvi.item.lParam, eax
mov sfgaof, SFGAO_HASSUBFOLDER
.if (g_bBrowseFiles)
or sfgaof, SFGAO_BROWSABLE or SFGAO_FOLDER
.endif
if ?TESTMODE
or sfgaof, SFGAO_COMPRESSED or SFGAO_REMOVABLE
endif
invoke vf(pShellFolder, IShellFolder, GetAttributesOf), 1, addr pidl,\
addr sfgaof
.if ((eax == S_OK) && (sfgaof & SFGAO_HASSUBFOLDER))
mov tvi.item.cChildren, 1
.else
.if (g_bBrowseFiles)
mov tvi.item.cChildren, I_CHILDRENCALLBACK
.else
mov tvi.item.cChildren, 0
.endif
.endif
if ?IMAGELIST
or tvi.item.imask, TVIF_IMAGE or TVIF_SELECTEDIMAGE
mov tvi.item.iSelectedImage, I_IMAGECALLBACK
mov tvi.item.iImage, I_IMAGECALLBACK
endif
.if ((!g_bBrowseFiles) || (sfgaof & (SFGAO_BROWSABLE or SFGAO_FOLDER)))
invoke StrRet2String, pidl, addr strret, addr szText, sizeof szText
if ?TESTMODE
sub esp, 256
mov edx,esp
invoke wsprintf, edx, CStr("%s,%X"), eax, sfgaof
mov eax,esp
endif
mov tvi.item.pszText, eax
invoke TreeView_InsertItem( m_hWndTV, addr tvi)
if ?TESTMODE
add esp,256
endif
inc dwChildren
.endif
.endif
.endw
invoke vf(pEnumIDList, IUnknown, Release)
.if (g_bSort)
mov eax, tvi.hParent
mov sortcb.hParent, eax
mov sortcb.lpfnCompare, SortChildrenCB
mov eax, pShellFolder
mov sortcb.lParam, eax
invoke TreeView_SortChildrenCB( m_hWndTV, addr sortcb, 0)
.endif
invoke vf(pShellFolder, IShellFolder, Release)
exit:
mov eax, dwChildren
.if (eax)
mov eax, 1
.endif
mov tvi.item.cChildren, eax
mov eax, hItem
mov tvi.item.hItem, eax
mov tvi.item.imask, TVIF_CHILDREN or TVIF_STATE
mov tvi.item.state, TVIS_EXPANDEDONCE
mov tvi.item.stateMask, TVIS_EXPANDEDONCE