News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Add files to a treeview

Started by JayPee, March 24, 2009, 10:03:53 AM

Previous topic - Next topic

JayPee

Hi

I have coded a directory tree using treeview. I would like it to also display *.mp3 files in the view but not certain on how to go about it. Any help would be appreciated

Thanks
John
Greetings From New Zealand
(Land of the Long White Cloud)

donkey

;Add root to TreeViev
invoke TrvAddNode,[hTreeView],0,OFFSET TargetFolder,IMG_DRIVE
;Fill TreeView with dir info
invoke TreeViewDir,[hTreeView],eax,OFFSET TargetFolder

TrvAddNode FRAME hTrv,hPar,lpPth,nImg
LOCAL tvins :TV_INSERTSTRUCT

/* ¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤

From TreeViewDir
Copyright © 2003 Ketil Olsen

Released to the public domain

¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤ */

mov eax,[hPar]
mov [tvins.hParent],eax
;Saving hPar simplifies building path
;when user selects an item

mov [tvins.itemex.lParam],eax

mov D[tvins.hInsertAfter],0
mov D[tvins.itemex.imask],TVIF_TEXT + TVIF_PARAM + TVIF_IMAGE + TVIF_SELECTEDIMAGE
mov eax,[lpPth]
mov [tvins.itemex.pszText],eax
mov eax,[nImg]
mov [tvins.itemex.iImage],eax
mov [tvins.itemex.iSelectedImage],eax
invoke SendMessage,[hTrv],TVM_INSERTITEM,0,addr tvins

    ret

ENDF

TreeViewDir FRAME hTrv,hPar,lpPth
LOCAL hwfd :D
LOCAL hpar :D

/* ¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤

From TreeViewDir
Copyright © 2003 Ketil Olsen

Released to the public domain

¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤=÷=¤ */

;Make the path local
invoke cpystr,addr szBuffer,[lpPth]
;Check if path ends with '\'. If not add.
invoke StrLen,addr szBuffer
dec eax
cmp B[szBuffer+eax],"\"
je >
invoke szCatStr,addr szBuffer,addr szBS
:
;Add '*.*'
invoke szCatStr,addr szBuffer,addr szAPA
;Find first match, if any
invoke FindFirstFile,addr szBuffer,addr wfd
cmp eax,INVALID_HANDLE_VALUE
je >>.EXIT
;Save returned handle
mov [hwfd],eax
  .Next
;Check if found is a dir
mov eax,[wfd.dwFileAttributes]
and eax,FILE_ATTRIBUTE_DIRECTORY
or eax,eax
jz >C1
;Do not include '.' and '..'
mov al,[wfd.cFileName]
cmp al,"."
je >C3
invoke TrvAddNode,[hTrv],[hPar],addr wfd.cFileName,IMG_FOLDER
mov [hpar],eax
invoke StrLen,addr szBuffer
mov edx,eax
push edx
sub edx,3
;Do not remove the '\'
cmp B[szBuffer+edx],"\"
jne >
inc edx
:
;Add new dir to path
mov eax,OFFSET szBuffer
add eax,edx
invoke cpystr,eax,addr wfd.cFileName
;Call myself again
invoke TreeViewDir,[hTrv],[hpar],addr szBuffer
pop edx
;Remove what was added
mov B[szBuffer+edx],0
C3:
jmp >C2
C1:
;Add file
;Some file filtering could be done here
push ebx
invoke StrLen,addr wfd.cFileName
sub eax,4
mov ebx,eax
invoke TrvAddNode,[hTrv],[hPar],addr wfd.cFileName,IMG_FILE
pop ebx
C2:
;Any more matches?
invoke FindNextFile,[hwfd],addr wfd
or eax,eax
jne <.Next
;No more matches, close handle
invoke FindClose,[hwfd]

.EXIT
;Sort the children
invoke SendMessage,[hTreeView],TVM_SORTCHILDREN,0,[hPar]
;Expand the tree
; invoke SendMessage,hFileList,TVM_EXPAND,TVE_EXPAND,hPar
ret

ENDF
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

JayPee

Hi Edger

Thanks very much.
Is there any chance you can supply me with the full code

Kind regards
John
Greetings From New Zealand
(Land of the Long White Cloud)

donkey

"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

JayPee

Hi Edger

Thanks very much, did the trick nicely

Have a great day

regards
John
Greetings From New Zealand
(Land of the Long White Cloud)

xandaz

   No sure if i'm reviving an old thread but i made this treeview control with drive c's folders. The only thing new about this is i think that like windows explorer only checks for two levels of folders to enforce the cChildren member  of TV_ITEM. If we choose to make a complete build of the directory structure it sometimes takes too long depending on the number of files/directories in the drive. So here it goes and i hope you enjoy. bye and thanks