Click here to Skip to main content
15,918,808 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Directory selection Pin
Ryan Binns6-Aug-03 3:26
Ryan Binns6-Aug-03 3:26 
GeneralRe: Directory selection Pin
jhwurmbach6-Aug-03 2:32
jhwurmbach6-Aug-03 2:32 
QuestionXP Problem with service ? Pin
Andreas@luk6-Aug-03 1:26
Andreas@luk6-Aug-03 1:26 
AnswerRe: XP Problem with service ? Pin
Vitali Halershtein6-Aug-03 3:42
Vitali Halershtein6-Aug-03 3:42 
GeneralLoad order of implicitly linked DLLs Pin
Wolfram Steinke6-Aug-03 1:26
Wolfram Steinke6-Aug-03 1:26 
GeneralRe: Load order of implicitly linked DLLs Pin
Chris Meech6-Aug-03 3:15
Chris Meech6-Aug-03 3:15 
GeneralRe: Load order of implicitly linked DLLs Pin
JT Anderson6-Aug-03 11:26
JT Anderson6-Aug-03 11:26 
GeneralMultiple file selection in Windows API Pin
Kayembi6-Aug-03 1:24
Kayembi6-Aug-03 1:24 
Hi,

I am writing a small program with some zip archiving functionality (using the ZipArchive library from www.artpol-software.com). I would like to add a list box to one of the dialog boxes and a browse button for multiple file selection, but am not sure how to go about multiple file selection at all. I would like it so that the user can click on the Browse... button and select any number of files. Upon clicking "open", the list of files will then appear in the list box above the browse button (and the list must be stored so that when the user clicks on "Zip", all of those files will get zipped up). I would also like to make it so that the user can select all of the files in the list box, or select and remove individual files... However, I am getting ahead of myself with that. First, I need to find out how to create a multiple selection procedure. (I am of course using the Windows API and *no* MFC.)

The following code opens a Browse box which allows users to select multiple files (using OFN_EXPLORER and OFN_ALLOWMULTISELECT):

[code]
BOOL OpenMultipleFiles(CHAR *filename, int len, HWND hWnd)
{
OPENFILENAME files;

ZeroMemory(&files, sizeof(OPENFILENAME));
files.lStructSize = sizeof(OPENFILENAME);
files.hwndOwner = hWnd;
files.lpstrFilter = "All Files (*.*)\0*.*\0\0";
files.lpstrFile = filename;
files.nMaxFile = len;
files.lpstrTitle = "Select Files";
files.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_EXPLORER | OFN_ALLOWMULTISELECT;
return GetOpenFileName(&files);
}
[/code]

This allows multiple section, though I am not sure what to do with the returned string, nor whether I am doing it right, as I have just modified the above code from code designed for opening a single file.

I managed to find the following code, designed to get the information returned from a multipe file selection box, from http://www.angelfire.com/biz/rhaminisys/tricks.html:

[code]
if ( ofn.nFileOffset < lstrlen(Buffer) )
AddToFileList( Buffer );
else
{
strcpy( FilePath, Buffer );
FilePath[ofn.nFileOffset] = 0;
while ( Buffer[ofn.nFileOffset] != 0 )
{
strcpy( Message, FilePath );
strcat( Message, "\\" );
strcat( Message, Buffer+ofn.nFileOffset );
AddToFileList( Message );
ofn.nFileOffset += (strlen(Buffer+ofn.nFileOffset) + 1);
}
}
[/code]

Unfortunately, I have no idea of how to put all this code and information together! For a start, "Buffer" in the above code is a buffer designed to hold all of the file names. But I have no idea how to define buffer. EG:

char Buffer[MAX_PATH];

doesn't work, because MAX_PATH is not big enough to hold the names of, say, 50 odd files plus a filepath.

If anyone could tell me how I could create a multiple file selection function that allows my users to select a number of files for inclusion in their .zip file, and a function that then allows me to access the returned information (ie. getting the names of all the files individually), I would be really, really grateful. (One thing that occurs to me is that wouldn't using ofn.nFileOffset only work when first selecting the files, and not later when I need to get all the file names for zipping?)

Oh, and I am a novice at this stuff, btw, so if you can see I'm heading down the wrong path completely, please tell me, and feel free to overexplain as though I were an idiot.

Many thanks,
KB
GeneralRe: Multiple file selection in Windows API Pin
David Crow6-Aug-03 3:09
David Crow6-Aug-03 3:09 
GeneralRe: Multiple file selection in Windows API Pin
Kayembi6-Aug-03 4:01
Kayembi6-Aug-03 4:01 
GeneralRe: Multiple file selection in Windows API Pin
David Crow6-Aug-03 4:23
David Crow6-Aug-03 4:23 
GeneralRe: Multiple file selection in Windows API Pin
Kayembi6-Aug-03 5:01
Kayembi6-Aug-03 5:01 
GeneralSaving/creating and Loading files Pin
Kayembi6-Aug-03 1:06
Kayembi6-Aug-03 1:06 
GeneralRe: Saving/creating and Loading files Pin
Dangleberry6-Aug-03 1:16
sussDangleberry6-Aug-03 1:16 
GeneralRe: Saving/creating and Loading files Pin
lawrence20006-Aug-03 3:13
lawrence20006-Aug-03 3:13 
GeneralRe: Saving/creating and Loading files Pin
David Crow6-Aug-03 3:19
David Crow6-Aug-03 3:19 
GeneralRe: Saving/creating and Loading files Pin
Kayembi6-Aug-03 4:06
Kayembi6-Aug-03 4:06 
GeneralRe: Saving/creating and Loading files Pin
David Crow6-Aug-03 4:18
David Crow6-Aug-03 4:18 
GeneralRe: Saving/creating and Loading files Pin
Kayembi6-Aug-03 4:45
Kayembi6-Aug-03 4:45 
GeneralRe: Saving/creating and Loading files Pin
David Crow6-Aug-03 4:57
David Crow6-Aug-03 4:57 
GeneralRe: Saving/creating and Loading files Pin
Kayembi6-Aug-03 5:27
Kayembi6-Aug-03 5:27 
GeneralTimer Callback Pin
LittleYellowBird6-Aug-03 0:31
LittleYellowBird6-Aug-03 0:31 
GeneralRe: Timer Callback Pin
Member 4242596-Aug-03 0:41
Member 4242596-Aug-03 0:41 
GeneralRe: Timer Callback Pin
Member 4242596-Aug-03 0:42
Member 4242596-Aug-03 0:42 
GeneralRe: Timer Callback Pin
LittleYellowBird6-Aug-03 1:12
LittleYellowBird6-Aug-03 1:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.