Thread: Getting FULL filename from listbox

  1. #1
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584

    Getting FULL filename from listbox

    I made a listbox (standard with the LBS_STANDARD flag) and I sent the listbox the LB_DIR message (with params to put all files and directories in the listbox). Well, I got the listbox to have the filename strings in the listbox, but I need the listbox so when the user dblclicks the item, I get the filename. I would get the index of the click, and then get the string at the index, but that would only be the filename (e.g. "test.txt"). I want the path and file (e.g. "C:\folder\test.txt"). How would I do this with the listbox? Thanks...

    Garfield
    1978 Silver Anniversary Corvette

  2. #2
    Registered User The15th's Avatar
    Join Date
    Aug 2001
    Posts
    125
    hello;

    The problem is that your using LB_DIR, because it sets the files with the old dos style. If i were you i would change the way you set your list box. I would either use the FindFirstFile, FindNextFile functions, or i would get whatever directory the user is setting the files from, and then append the file name on the end of that, then i would output the whole file name and location to the list control. Actually the way i would do it is i would just store the current directory location in a buffer and then call that when the user dbl clicks, so they dont see the full directory name just the file name, but when you call on gettext it will get the full directory and file name, so you can shell..() it or whatever you want.

    hope this makes some scence.
    arrh, i got nothing good to say.
    http://www.praxis1.vic.edu.au/home/dcola/

  3. #3
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Yes, I was thinking about appending the filename (from the listbox) onto the full pathname, but how would I get the directory of the view of the listbox at the point in which the user dblclicks? Thanks...

    Garfield
    1978 Silver Anniversary Corvette

  4. #4
    Registered User The15th's Avatar
    Join Date
    Aug 2001
    Posts
    125
    I need a little bit more background information before i can help you any further. Are all the files in the same directory? Are you setting the files with a OpenFile dlg box? Is the user able to set any file on the directory from any location?

    After just reading your first post, it sounds like your just setting one directory, which in that case you could just store that location when it is first set, and call upon it on the dblclk message.

    Anyway just let me know how your setting your location.
    arrh, i got nothing good to say.
    http://www.praxis1.vic.edu.au/home/dcola/

  5. #5
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Well, I want to use all of the directories possible. The list box should display the files and the "[..]" to go up and down through the directories. And then at the right directory, the user clicks the file, but I also want to get the full filename including the path. How can I do this?

    Garfield
    1978 Silver Anniversary Corvette

  6. #6
    Registered User The15th's Avatar
    Join Date
    Aug 2001
    Posts
    125
    quite easily;

    If you have already enabled the user to navigate through their directories that means your using GetCurrentDirectory() and SetCurrentDirectory(). When you store this information you can just call back on it later. Have you already setup your proc to navigate through the directories? All you need to do is call GetCurrentDirectory (MAX_PATH + 1, DirectoryBuf) ; and hold that information untill the user moves to a new location, then any file name inside the list control will be in the location held in DirectoryBuf.

    I hope im helping you, if you would like some code just ask me and ill write some for you, but try and write your own, its more fun that way!
    arrh, i got nothing good to say.
    http://www.praxis1.vic.edu.au/home/dcola/

  7. #7
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Okay, I know where to go from here. Thanks!
    1978 Silver Anniversary Corvette

  8. #8
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    Well, I got the listbox to have the filename strings in the listbox...
    Can you please tell me how becuase the stuff on msdn is confusing me...

  9. #9
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Originally posted by face_master

    Can you please tell me how becuase the stuff on msdn is confusing me...
    What you have to do is create the child window listbox. And then send the message:

    SendMessage(hwndList, LB_DIR, DIRATTR, TEXT("*.*"));

    to fill the list box with the filename strings. DIRATTR is a whole list of constants for displaying what type of files, directories. Simply as that. And then you can program to move through the directories with testing the string of the listbox.

    Garfield
    1978 Silver Anniversary Corvette

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-11-2009, 01:49 AM
  2. Pass Filename to another function
    By awesmesk8er in forum C Programming
    Replies: 9
    Last Post: 10-24-2008, 01:43 PM
  3. How to cast a ListBox item to an int for a switch statment?
    By Swaine777 in forum C++ Programming
    Replies: 8
    Last Post: 09-26-2004, 08:52 PM
  4. hashing help
    By alokin in forum C Programming
    Replies: 17
    Last Post: 10-28-2002, 06:33 PM
  5. Viewing full filename in ListBox?
    By SyntaxBubble in forum Windows Programming
    Replies: 4
    Last Post: 12-09-2001, 10:21 PM