News:

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

Directory Listing Help

Started by Cyrus, November 08, 2007, 04:05:57 PM

Previous topic - Next topic

Cyrus

Hey all. I am attempting to use RadASM with masm backbone.

I'm sure this will be an easy one for you all. I have a dialog with a listbox. It is List1 equ 1001.

What I want to do is list all .mp3 files in D:\Music in this listbox.

I have tried the DlgDirList and the LB_DIR but either get an empty list box or the program crashes. I have tried several variations of these to no success. I have even debugged in olly but not gotten very far.

I do NOT want to prompt for a folder, it will be hard coded. I dont really care which method is used so long as I can finally have my files in the list.

If you could please, show me some code on how to do this.

Thanks in advance.

ragdog

hi

use a listview


invoke AddItem, ADDR Result.cFileName,addr hDir,0

AddItem PROC _Item1:DWORD,_Item2:DWORD,_Item3:DWORD
LOCAL Item :LV_ITEM
    mov Item.imask,LVIF_TEXT
    mov ebx,_Item1
    mov Item.pszText,ebx
    mov Item.iSubItem,0
    invoke SendMessage,hList,LVM_INSERTITEM,0,addr Item
    mov Item.iItem,eax
    inc Item.iSubItem
    mov ebx,_Item2
    mov Item.pszText,ebx
    invoke SendMessage,hList,LVM_SETITEM,0,addr Item
    inc Item.iSubItem
    mov ebx,_Item3
    mov Item.pszText,ebx
    invoke SendMessage,hList,LVM_SETITEM,0,addr Item
    inc Item.iSubItem
    inc Item.iItem
ret     
AddItem ENDP


greets
ragdog

Cyrus

Thanks for your reply ragdog! Umm I have to say that that is quite a bit to understand there...

Is it not possible to use the DlgDirList or LB_DIR? If so, I'd like to use it as its much smaller and more simple. Problem is I just dont know how to use them properly and google wont give me an example. :(

If DlgDirList or LB_DIR message will not work for what I'm wanting to do, I'll use your code as best I can. Thank you so much for your reply.

ragdog

hmm
for lisbox try this



invoke SendMessage, hList, LB_GETCURSEL, 0, 0
     inc eax
invoke SendMessage, hList, LB_INSERTSTRING, eax, offset FileN
invoke SendMessage, hList, LB_SETCURSEL, eax, 0

post your souce i hope i can help you!

ragdog

[attachment deleted by admin]

Cyrus

Sure.

In my .inc:
List1 equ 1001

cMusicDir      db 'D:\Music\',0
cFilter         db 'D:\Music\*.mp3',0

In my .asm:

      lea edi,cMusicDir
      invoke SetCurrentDirectory,edi
      lea edi,cFilter
      invoke DlgDirList,hWin,edi,List1,0,DDL_READWRITE

I'm not sure if the SetCurrentDirectory is needed or not. And again, I have tried this several different ways. I doubt my source will help much. I've tried things like cFilter *.mp3 without the D:\Music and even *.* and I have removed the SetCurrentDirectory.

I suppose that my literal question is how do I use DlgDirList or LB_DIR? Just a small example would be fine. I've seen it in other source but its very complicated.


ragdog

it is simply with findfiles api and more Flexibility

here is my source find mp3 files on a drive my source uses a listview

http://www.mediafire.com/?3xolkbb1bk1

Cyrus

I appreciate your replies, but could I please get an answer to my question?

I'm aware there are other methods that will work. And as far as that source, its pretty large and it would take me forever to sort all of that code. Am not very experienced with ASM at all.

ragdog

sry

i hav this found

DlgDirList(_T("C:\\*.*"), IDC_LIST1, 0, 0);

i hope that help you or see by msdn http://msdn2.microsoft.com/en-us/library/bb761366.aspx

Cyrus

Ya I saw that MSDN. I also have a copy of the win32.hlp file. I know the syntax and again I have debugged with olly but I cannot seem to understand why it doesnt work.

If you (or anyone for that matter) are able to throw together a working example that would be awesome.

Honestly I know ASM is hard but this is just amazingly difficult. I mean all I am looking to do is just get the contents of D:\Music and display it in a listbox. Filtered by *.mp3 would be nice.

ragdog, I really appreciate your help!

ragdog

try this "D:\\Music\\*.mp3"


DlgDirList hDlg, szTmp, IDC_LIST,IDC_DIRECTORY, DDL_DIRECTORY | DDL_DRIVES )

if it you does not help then sends complet your source for helps


greets
ragdog

hutch--

Cyrus,

Usually to get a directory listing you use two (2) API functions that normally work togetjher, FindFirstFile() and FindNextFile(). Once you have that working you display it whatever way you like.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Cyrus

Quote from: ragdog on November 08, 2007, 08:43:59 PM
try this "D:\\Music\\*.mp3"


DlgDirList hDlg, szTmp, IDC_LIST,IDC_DIRECTORY, DDL_DIRECTORY | DDL_DRIVES )

if it you does not help then sends complet your source for helps


greets
ragdog

Yes I've tried that in every possible variation I could think of. No luck. The FindFirstFile and FindNextFile I will be sure and look into. Thank you very much. Do I need to use these with the DlgDirList/Sendmessage LB_DIR or alone?

Cyrus

Here is the solution that worked for me:

handle    dd    0
wfd     WIN32_FIND_DATA <>
folder    db "D:\music\*.mp3",0

invoke  FindFirstFile,offset folder,offset wfd
mov     handle,eax
.While  eax != ERROR_BAD_PATHNAME && eax != NULL
    invoke  GetLastError
    invoke  SendDlgItemMessage, hWin, IDC_LST1, LB_ADDSTRING, handle, offset wfd.cFileName   
    invoke  FindNextFile, handle, offset wfd
.endw

ragdog

hi

here is my simply dirlist example

.data
TheExtention            db "*.mp3",0
Bksl                         db "\",0
Browse_Title            db "Mp3-MusicPlayer v1.1",0
Browse_Text             db "Browse for music",0

.data?
hInstance dd ?

MusicFile      db 256 dup(?)
hFiles          db 256 dup(?)
hMp3         dd ?
result          WIN32_FIND_DATA <?>
hDir            dd ?
pFName          dd ?

.code
..
..
invoke Scan_Folder,hWnd,addr TheExtention




Scan_Folder proc   hWnd:DWORD,filter :DWORD
LOCAL PathName[256]:byte  ;buffer to hold the current path
LOCAL buffer  [128]:BYTE 
LOCAL hFind   :DWORD     ;file pointer to the current file

      invoke BrowseForFolder,hWnd,ADDR buffer,addr Browse_Title,addr Browse_Text 
             
      invoke lstrcat,addr hDir,addr buffer
      invoke lstrcat,addr hDir,ADDR Bksl
     
      invoke lstrcat,addr buffer,ADDR Bksl
      invoke lstrcat,addr hFiles, ADDR buffer
      invoke lstrcat,addr buffer, filter
      invoke FindFirstFile, ADDR buffer, ADDR result
      mov hFind, eax
      invoke lstrcat,addr hFiles, ADDR result.cFileName
                 
      invoke SendDlgItemMessage,hWnd, IDC_LIST, LB_SETCURSEL, 0, 0
      invoke SendDlgItemMessage,hWnd, IDC_LIST, LB_GETCURSEL, 0, 0
      inc eax
      invoke SendDlgItemMessage,hWnd, IDC_LIST, LB_INSERTSTRING, eax, addr hFiles
      invoke SendDlgItemMessage,hWnd, IDC_LIST, LB_SETCURSEL, eax, 0
     
next_file:
      mov hFiles[0],0       
      invoke lstrcat,addr hFiles, ADDR hDir
      invoke FindNextFile, hFind, ADDR result
      cmp eax, 0
      je finish
           
      invoke lstrcat,addr hFiles, ADDR result.cFileName
      invoke SendDlgItemMessage, hWnd, IDC_LIST, LB_GETCURSEL, 0, 0
      inc eax
      invoke SendDlgItemMessage, hWnd, IDC_LIST, LB_INSERTSTRING, eax, addr hFiles
      invoke SendDlgItemMessage, hWnd, IDC_LIST, LB_SETCURSEL, eax, 0
      jmp next_file 
finish:
      invoke FindClose,hFind
          ret           
Scan_Folder endp


greets
ragdog