Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

fill the listbox

Posted on 1999-10-09
16
Medium Priority
?
344 Views
Last Modified: 2013-12-03
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

 
0
Comment
Question by:Babyworship
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
16 Comments
 
LVL 3

Expert Comment

by:BudVVeezer
ID: 2113754
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
0
 
LVL 3

Expert Comment

by:BudVVeezer
ID: 2113755
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.
0
 

Author Comment

by:Babyworship
ID: 2113764
if client click the a static directories,Should I call dlgdirlist() again to fill the listbox?
Thanks...
 
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 3

Expert Comment

by:BudVVeezer
ID: 2113766
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
0
 

Author Comment

by:Babyworship
ID: 2115364
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...
0
 
LVL 3

Accepted Solution

by:
BudVVeezer earned 240 total points
ID: 2116817
Well, color and font in listboxes is not something I'm very well familiar with(AT ALL).. BUT.  Here's the thoughts I can give you on it.  Process the WM_CTLCOLORLISTBOX message...  set the text color and the font in there.

The WM_CTLCOLORLISTBOX message is sent to the parent window of a list box before Windows draws the list box. By responding to this message, the parent window can set the text and background colors of the list box by using the given display device context handle.

WM_CTLCOLORLISTBOX
hdcLB = (HDC) wParam;   // handle of list box display context
hwndLB = (HWND) lParam; // handle of list box
 
Parameters
hdcLB

Value of wParam. Identifies the device context for the list box.

hwndLB

Value of lParam. Identifies the list box.

Return Values
If an application processes this message, it must return the handle of a brush. Windows uses the brush to paint the background of the list box.

Default Action
The DefWindowProc function selects the default system colors for the list box.

Remarks
The WM_CTLCOLORLISTBOX message is never sent between threads. It is sent only within one thread.

If you have any more questions on the colors in list boxes, I would post it as another question.  You can drop this one back down to 50 if you would like.  Sorry I can't be of more help!

~Aaron
0
 

Author Comment

by:Babyworship
ID: 2118795
Bye,good luck.
0
 

Author Comment

by:Babyworship
ID: 2118798
Sorry,soryy ,orinigally,I wanna value it,but I mispunch the reject button,please reanwer it and I will mark it,sorry:(
0
 

Author Comment

by:Babyworship
ID: 2118809
To ~Aaron the above,sorry.
0
 
LVL 3

Expert Comment

by:BudVVeezer
ID: 2119719
::grins::that's ok.  Caught me by suprise for a second though.  =P  Lemme know if you get fonts and colors working.

~Aaron
0
 

Author Comment

by:Babyworship
ID: 2128675
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...
0
 
LVL 3

Expert Comment

by:BudVVeezer
ID: 2128767
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
0
 

Author Comment

by:Babyworship
ID: 2128840
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
0
 

Author Comment

by:Babyworship
ID: 2128842
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
0
 

Author Comment

by:Babyworship
ID: 2128850
I know GetOpenFilename,but it's too crude and I wanna only list two kinds of file,.myextension and .scr.....
0
 
LVL 3

Expert Comment

by:BudVVeezer
ID: 2130114
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
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

664 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question