Link to home
Start Free TrialLog in
Avatar of Babyworship
Babyworship

asked on

fill the listbox

Dear experts:
I wanna fill my listbox with directories and files like a file-choosing box(like GetOpenFileName() which lets the user specify the drive, directory, and the name of a file or set of files to open.)
I know I can use dlgdirlist to fill it with files of specified path,but how can I fill it not only files but also directories of that specified path and let user to choose a file in whatever driver?
Thanks

 
Avatar of BudVVeezer
BudVVeezer

DlgDirList(hWnd, "*.mid", LISTMIDI, PATH, DDL_DIRECTORY | DDL_DRIVES);

This would list all .mid files to the ListBox named LISTMIDI with the static path being PATH.  It will also list the directories and drives.  If you have questions, just ask! =o)

~Aaron
The DlgDirList function fills the specified list box with the names of all files matching the specified path or filename.

int DlgDirList( HWND hDlg,
 // handle to dialog box with list box
 
LPTSTR lpPathSpec,
 // pointer to path or filename string
 
int nIDListBox,
 // identifier of list box
 
int nIDStaticPath,
 // identifier of static control
 
UINT uFileType
 // file attributes to display
 
);
 


Parameters
hDlg

Identifies the dialog box that contains the list box.

lpPathSpec

Points to a null-terminated string that contains the path or filename. DlgDirList modifies this string, which should be long enough to contain the modifications. For more information about this parameter, see the Remarks section.

nIDListBox

Specifies the identifier of a list box. If this parameter is zero, DlgDirList assumes that no list box exists and does not attempt to fill one.

nIDStaticPath

Specifies the identifier of the static control used for displaying the current drive and directory. If this parameter is zero, DlgDirList assumes that no such control is present.

uFileType

Specifies attributes of the filenames to be displayed. This parameter must be one or more of the following values: Value
 Description
 
DDL_ARCHIVE
 Includes archived files.
 
DDL_DIRECTORY
 Includes subdirectories. Subdirectory names are enclosed in square brackets ([ ]).
 
DDL_DRIVES
 Includes drives. Drives are listed in the form [-x-], where x is the drive letter.
 
DDL_EXCLUSIVE
 Includes only files with the specified attributes. By default, read-write files are listed even if DDL_READWRITE is not specified.
 
DDL_HIDDEN
 Includes hidden files.
 
DDL_READONLY
 Includes read-only files.
 
DDL_READWRITE
 Includes read-write files with no additional attributes.
 
DDL_SYSTEM
 Includes system files.
 
DDL_POSTMSGS
 Posts messages to the application’s message queue. By default, DlgDirList sends messages directly to the dialog box procedure.
 


Return Values
If a listing is made ¾ even an empty listing ¾ the return value is nonzero. If the input string does not contain a valid search path, the return value is zero.

Remarks
If you specify a zero-length string for the lpPathSpec parameter or if you specify only a directory name with no filename, the string will be changed to *.*

The lpPathSpec parameter has the following form:

[drive:] [[\u]directory[\idirectory]\u] [filename]

In this example, drive is a drive letter, directory is a valid directory name, and filename is a valid filename that must contain at least one wildcard (? or *).

If lpPathSpec includes a drive or directory name, or both, the current drive and directory are changed to the specified drive and directory before the list box is filled. The static control identified by the nIDStaticPath parameter is also updated with the new drive or directory name, or both.

After the list box is filled, DlgDirList updates lpPathSpec by removing the drive or directory portion, or both, of the path and filename.

DlgDirList sends the LB_RESETCONTENT and LB_DIR messages to the list box.
Avatar of Babyworship

ASKER

if client click the a static directories,Should I call dlgdirlist() again to fill the listbox?
Thanks...
 
this is what I have it do.  In WM_COMMAND, have it check when someone selects something from your list box(in my case, they hit the button IDC_PLAY)

short TheRet;

TheRet = DlgDirSelectEx(hWnd, TheFile, MAX_PATH, LISTMIDI);

if(TheRet != 0)
{
      SetCurrentDirectory(TheFile);
      DlgDirList(hWnd, "*.mid", LISTMIDI, PATH, DDL_DIRECTORY | DDL_DRIVES);
}

Basically, have it check to see what the current selection is.  If the ret is NOT zero, that means it's a directory, and you can just set the directory..then repopulate the list box by DlgDirList again.

~Aaron
Thank you ,I raise my points a litter 'coz this problem:
Do you know how to change the font and color in the listbox?
Thanks...
ASKER CERTIFIED SOLUTION
Avatar of BudVVeezer
BudVVeezer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Bye,good luck.
Sorry,soryy ,orinigally,I wanna value it,but I mispunch the reject button,please reanwer it and I will mark it,sorry:(
To ~Aaron the above,sorry.
::grins::that's ok.  Caught me by suprise for a second though.  =P  Lemme know if you get fonts and colors working.

~Aaron
Sorry,I wanna ask you a question,Can I make the listcontrol fill with two kinds of file? e.g: .exe and .dll?
I can't increase the points now ,but I dont want to fire anther,if you oblige me,thanks...
not a problem.  I'm not sure if you can fill it with two.  I'll do some checking on it.  Are you using this to open a file, or just because you need to list it?  If you're going to open the file, or just need a file name, I would suggest using GetOpenFileName...it's really easy to use, I can show you how...

~Aaron
I'd let the user to choose a file from the machine,then I will retrieve the info and use it to execute that file by createprocess().
~Aaron,you are really harm-hearted,thank you.
I'm writing a screen-saver system(not a screensaver file) to substitute the window's,so I need to disable the window system'm screensaver in case collision.
Thank you very much...
Babyworship
I'd let the user to choose a file from the machine,then I will retrieve the info and use it to execute that file by createprocess().
~Aaron,you are really warm-hearted,thank you.
I'm writing a screen-saver system(not a screensaver file) to substitute the window's,so I need to disable the window system'm screensaver in case collision.And I add a file extension as my screensaver file but I must be compatible with .scr,so I need to list .myfileextension and .scr both in a list box...
Thank you very much...
Babyworship
I know GetOpenFilename,but it's too crude and I wanna only list two kinds of file,.myextension and .scr.....
Thank you.  =)  As far as I can tell, putting them both in the DlgDirList...not able to do it.  =(  In all honesty, I would use the GetOpenFilename API...it may be crude(sometimes frustrating), but it works slick.  And if you only need the user to grab one file, it works even better.  =)  Instead of doing a DlgDirList box, if you are REALLY wanting to have them in a list box, what you could do is make a list box, and to populate it, use the FindFirtFile and FindNextFile APIs to find the .scr and .myextension and fill the list box that way.  Then just get the one the user highlighted and so on and so forth.

~Aaron