OPENFILENAME and multiple files.

This is a discussion on OPENFILENAME and multiple files. within the Windows Programming forums, part of the Platform Specific Boards category; Hey, I've set up my OPENFILENAME sturctures' flags to include the option OFN_ALLOWMULTISELECT but i'm having trouble. What i want ...

  1. #1
    Registered User -leech-'s Avatar
    Join Date
    Nov 2001
    Posts
    54

    Question OPENFILENAME and multiple files.

    Hey,

    I've set up my OPENFILENAME sturctures' flags to include the option OFN_ALLOWMULTISELECT but i'm having trouble. What i want to do is give the option for the user to select multiple files which will then be displayed in a listbox, however, when i select more than one file all that shows up in the listbox is the root directory.

    For example, if i choose two or more files from C:\ - for example foo.txt and bar.txt - and send the lpstrFile member to the listbox (using SendDlgItemMessage) the only think that will show up will be "C:\" instead of the two files. However, if i select them each seperately they both appear just fine, one after the other.

    I guess i'm probably missing something but i don't know what, so any help would be apprecited. Thanks.
    Not yet, have to think of one...

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    From memory (havent checked), the string returned from a multiselect operation is made up of each filepath, and each is seperated by a NULL....so displaying the string just gives the first element

    Do a little pointer arthmatic to tokenise the string

  3. #3
    Registered User -leech-'s Avatar
    Join Date
    Nov 2001
    Posts
    54
    Could you maybe give me an example, strings aren't exactly my forte

    Thanks.
    Not yet, have to think of one...

  4. #4
    Registered User johnnie2's Avatar
    Join Date
    Aug 2001
    Posts
    186
    Originally posted by Fordy
    From memory (havent checked), the string returned from a multiselect operation is made up of each filepath, and each is seperated by a NULL....so displaying the string just gives the first element
    Actually, the first string contains the current directory, but that was more than close enough for memory recall without checking.

    Code:
    char *aString;
    vector<char *> selectedStrings;
    OPENFILENAME ofn;
    
    ...allow the user to select multiple files...
    
    // on return, the strings are separated by NULL's; use strlen() and some pointer
    // trickery to get at each string.  The entire sequence is terminated by
    // two NULL characters.
    
    // get a pointer to the first string; ofn.lpstrFile without the offset
    // points to a string containing only the current directory
    aString = ofn.lpstrFile + ofn.nFileOffset;
    
    do {
       selectedStrings.push_back(aString);
       aString += strlen(aString) + 1;                        // reset pointer to just beyond the last NULL
    } while (*aString != '\0');                               // while no double-NULL detected
    "Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C

  5. #5
    Registered User -leech-'s Avatar
    Join Date
    Nov 2001
    Posts
    54
    Thanks a lot for the example, it really helped clear things up. But is there a way to do it in straight C without using the vector?

    edit: nevermind, i got it now, thanks
    Last edited by -leech-; 02-25-2003 at 12:43 PM.
    Not yet, have to think of one...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need an interface written
    By Thantos in forum Projects and Job Recruitment
    Replies: 10
    Last Post: 11-23-2005, 10:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21