If you want a user to be able to select multiple files from Windows, create a new form and from the VFP menu :-
Tools > Component Gallery > Foundation Classes > Dialogs > Common Dialog (then right click) > Add to Form
Rename the class to [color blue].cusCommonDialog[/color].
As you will discover, there are numerous properties and methods for this class. It combines [color blue]GETFILE()[/color], [color blue]PUTFILE()[/color] and presents a modern interface to the user.
The following example sets the relevant properties to enable multiple file selection, shows the dialog and displays the path\filename.ext of the selected files in a cursor.
[color blue]
CREA CURS FILENAMES (filename C(254))
WITH THISFORM.cusCommonDialog
[tab].ClearFilters() [/color][color green]&& Clear filters in case in loop[/color][color blue]
[tab].lAllowMultiSelect = .T. [/color][color green]&& Enable multiple file selection[/color][color blue]
[tab].cFileName = [] [/color][color green]&& Do not set an initial file name[/color][color blue]
[tab].cInitialDirectory = [C:\My Documents] [/color][color green]&& Start folder[/color][color blue]
[tab].cTitlebarText = [Select multiple files] [/color][color green]&& Dialog titlebar text[/color][color blue]
[tab].aFilterList[1,1] = [Image Files (bmp,gif,jpg)] [/color][color green]&& First half of filter list[/color][color blue]
[tab].aFilterList[1,2] = [*.bmp;*.gif;*.jpg;*.jpeg] [/color][color green]&& Second half of filter list[/color][color blue]
[tab][/color][color green]* Should you want additional filters you can add them with :-
[tab][/color][color blue].AddFilter([MS Office (doc,ppt,rtf,txt,wri,xls)],[*.doc;*.ppt;*.rtf;*.txt;*.wri;*.xls])
[tab].nFileCount = 0 [/color][color green]&& Reset file count value in case dialog in DO WHILE... loop[/color][color blue]
[tab].ShowDialog() [/color][color green]&& Show dialog[/color][color blue]
[tab]IF .nFileCount > 0 [/color][color green]&& File(s) selected[/color][color blue]
[tab][tab]FOR i = 1 TO ALEN(.aFileNames,1)[/color][color green] && Loop through array created[/color][color blue]
[tab][tab][tab]INSERT INTO FILENAMES (filename) VALUES ( ;
[tab][tab][tab][tab]ADDBS(.cFilepath) ;
[tab][tab][tab][tab]+ LOWER(.aFileNames[1,i]))[/color][color green] && Insert path\filename.ext in cursor[/color][color blue]
[tab][tab]ENDF
[tab][tab]BROW LAST
[tab]ELSE
[tab][tab]MESSAGEBOX([You have not made a selection],16,[No files],2000)
[tab]ENDI
ENDW[/color][color black]
If you have OLE drag 'n drop enabled on a form control, you can also drag and drop multiple files from the Windows Common dialog onto your VFP control.
You then need to ensure that you release the Windows Common dialog in the [/color][color blue].OLEDragDrop()[/color] event of the VFP control to avoid a recursive call to the Windows Common dialog.
Put the following code into the [color blue].OLEDragDrop()[/color] event:-
[color blue]
DECLARE INTEGER FindWindow IN WIN32API ;
[tab]STRING cNull,;
[tab]STRING cWinName
DECLARE LONG PostMessage IN WIN32API ;
[tab]LONG hWnd ,;
[tab]LONG wMsg ,;
[tab]LONG wParam ,;
[tab]LONG lParam
lcWindowTitle = ALLTRIM(THISFORM.cusCommonDialog.cTitleBarText)
IF lcWindowTitle = [Select multiple files][/color][color green]
[tab]** If the file was 'dropped' by the Windows Common Dialog box, close that dialog.[/color][color blue]
[tab]lnHWnd = FindWindow(NULL,lcWindowTitle)
[tab]IF lnHWnd # 0
[tab][tab]PostMessage(lnHWnd,WM_CLOSE,0,0)
[tab]ENDIF
ENDIF[/color][color black]
There is far more depth to this class than can be demonstrated in a single FAQ - get coding and have fun!
Chris R. Chamberlain
[link http://www.pdfcommander.net]PDFcommander[sup]tm[/sup].net[/link]
[link http://www.pdfcommander.co.uk]PDFcommander[sup]tm[/sup].co.uk[/link]
[/color]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.