Select multiple files in VFP
Select multiple files in VFP
(OP)
Hi,
I’m looking for a (dll based) form or control for selecting multiple files, for example to zip them one by one into a zipfile.
I’ve been using Common Dialog (COMDLG32) so far, but this is giving an error when I select more than approx. 50 files. I don’t know how to make this reliable when selecting more files.
So I’m wondering what others use to select multiple (or a lot of) files for further action. I need a control that allows changing directories, drives, etc..
Regards,
Gerrit
PS: I need something that doesn’t change the selected filenames to lowercase.
I’m looking for a (dll based) form or control for selecting multiple files, for example to zip them one by one into a zipfile.
I’ve been using Common Dialog (COMDLG32) so far, but this is giving an error when I select more than approx. 50 files. I don’t know how to make this reliable when selecting more files.
So I’m wondering what others use to select multiple (or a lot of) files for further action. I need a control that allows changing directories, drives, etc..
Regards,
Gerrit
PS: I need something that doesn’t change the selected filenames to lowercase.
RE: Select multiple files in VFP
That said, I don't know how well it would support selecting a large number of files (more than 50?),and it wouldn't allow you to navigate between directories. To do that, you could use a list box with the RowSourceType set to 7, which would approximately mimic a standard File Open dialogue, but that's really a hangover from Foxpro 2.x and looks terrible under VFP.
In any case, expecting the user to select 50 files by holding down Ctr or Shift while clicking with the mouse doesn't sound like a good interface. Have you considered using a grid with checkboxes, so that the user ticks the files they want?
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro articles, tips and downloads
RE: Select multiple files in VFP
Anyway, that's just an aside, I'm not saying this is the only way to do it.
If you select too many files the OLE error you get is telling to increase MaxFileSize. Tha maximum for it is 0x7fff and that will be sufficient for a lot more than 50 files. A real world example I have is about 400 files using about 8k bytes, so 32k can go up to something in the magnitude of 1000-1500 files.
CODE
The first array element of laFiles will always be the directory from which the files were selected, followed by filenames in further array elements.
If that's still not enough for you I can only recommend limiting this feature to only accept a directory to archive and then use ADIR (that can get file names with capitalization as it is on disk).
Chriss
RE: Select multiple files in VFP
Your code runs fine as prg. So far so good (what a relief...).
However I have to call the common dialog control from a form's "File Select" button. If I put the code there, it's not working.
I copied the procedure to my start.prg file, where I store more procedures.
I added the line to the form's init:
CODE --> foxpro
Where should I put certain elements of your sample code to get it running from my main form's button?
Regard, Gerrit
RE: Select multiple files in VFP
So you don't add that object to your form, you keep both the PROCEDURE CommonDialogFileOpen and the DEFINE CLASS as is in your start.prg and just call CommonDialogFileOpen as the code does, in your form's button.
You start a dialog, that's its own new form, not your form.
You said you used the common dialog yourself, well, you could of course continue to do it your way, all you need to take over from my code sample is the setting of MaxFileSize and the usage of the flags. And since you say you already can select multiple files, all that hinders you to select more is not setting MaxFileSize to a higher value, that's the main point in all of this.
Chriss
RE: Select multiple files in VFP
I've got it working now with my form.
I guess you have more knowledge than me regarding this CommonDialog form, and I still have a few issues.
a. How do I open the form for a specific (default) directory? I tried this according to my original code, but this gives error 1426: "OLE error code 0x80020006: Unknown name."
CODE --> foxpro
b. Can I specify specific file types (for example only pdf or jpg). In my version of CommonDialog I have a selection option for various extensions or for all. This does not work with your sample code.
CODE --> foxpro
c. If I click CANCEL in the CommonDialog form I get error 1426: "OLE error code 0x80020006: Unknown name." This is caused by the following line:
CODE --> foxpro
I solved this by adding
CODE --> foxpro
I wonder where I can find information about all valid CommonDialog options. I checked the reference in the sample code, but I couldn’t find the “part2” that is mentioned there.
Regards, Gerrit
RE: Select multiple files in VFP
I found a way to offer filter options to the commonDialog:
CODE --> foxpro
I cannot get this filter working with multiple extensions, like "Images (*.jpg, *.png)|*.jpg,*.png". If I set a filter this way, no files are shown.
At least I'm coming closer to what I need.
Regards, Gerrit
RE: Select multiple files in VFP
I tried this CommonDialog on a Windows 7 PC, but I get error 1426 on this line:
CODE --> foxpro
This is the error: "OLE error code 0x80040112: Class is not licensed" (translated from Dutch).
I do have an alternative (older) CommonDialog that is working form Windows 7 (and not for Windows 10) so I can check the OS version and use the appropriate code.
A better solution would be to use the same CommonDialog for all Windows versions.
I have no idea if this is possible. Any comments?
Regards, Gerrit
RE: Select multiple files in VFP
You do get the license to redistribute several ole controls, Common Dialogs are among them, but this license doesn't go to clients automatically, if you just distribute the EXE.
The way the code I posted acts is using the MSComDlg.CommonDialog on a form, that's a condition you also find for the winsock socket control, it only work when put on a form, not when used standalone. Therefore the define of a form with an added olecontrol object.
If you still use your own usage of common controls you might need to change that for exactly these license issues.
Chriss
RE: Select multiple files in VFP
But looking at HOME()+"\redist.txt" I see merge modules listed that will install the license to use the control.
MSCOMCT2.MSM
MSCOMCTL.MSM
MSCOMM32.MSM
It is in one or all of these merge modules. If you don't use an installer or use one that can't install merge modules I don't know how to get the license you need to clients, but InstallShield Express comes with VFP and does install merge modules.
Chriss
RE: Select multiple files in VFP
The Windows 7 issue is not bothering me, as I have a perfectly working code for that.
That I cannot set the initial directory is a bigger problem. I tried CHDIR and SET DEFAULT TO to set an initial directory before running the CommonDialog form.
Nothing seems to work. I also tried adding the OFN_NOCHANGEDIR flag to lnFlags, but this doesn't work either.
The CommonDialog form seems to "rembember" where it was left the previous time it was called.
How can I set the initial directory?
Regards, Gerrit
EDIT: I just found the solution (Google is my friend):
CODE --> foxpro
RE: Select multiple files in VFP
Sorry, tek-tips doesn't seem to like screen sized images, it looks a bit blurry.
Chriss
RE: Select multiple files in VFP
Thanks again for all your help. I think it’s working OK now (time and more testing will tell).
Regards, Gerrit
RE: Select multiple files in VFP
As I wrote before the common dialog (using the code you presented the 28th of October) works fine with all 64-bit Windows 10 systems I tested with.
However there are still people using Windows 10 32-bit (because they still have to use DOS software).
On these pc's I get OLE error code 0x80040112: Class is not licensed
I have the code calling the common dialog in a prg file, so I use DO CommonDialog.prg from my main form to call this.
This is the exact code I use:
CODE --> foxpro
#Define OFN_ALLOWMULTISELECT 0x200 && Allows multiple file selections; use only with Open. OFN_EXPLORER must also be set. #Define OFN_EXPLORER 0x80000 && Uses Explorer-style dialog boxes. Is automatically set, but must specifically be set if OFN_ALLOWMULTISELECT is used. #Define OFN_LONGNAMES 0x200000 && Explorer-style dialog boxes ignore this flag and always display long file names. #DEFINE OFN_NOCHANGEDIR 0x8 && Restores the current directory to its original value if the user changed the directory while searching for files. #DEFINE OFN_HIDEREADONLY 0x4 && Hides the read-only box. Should be set for Save As lnFlags = OFN_EXPLORER+OFN_ALLOWMULTISELECT+OFN_LONGNAMES+OFN_NOCHANGEDIR+OFN_HIDEREADONLY PUBLIC Array laFiles[1] && original was LOCAL CommonDialogFileOpen(lnFlags,@laFiles) && <== OLE error code 0x80040112 on 32-bit Windows PROCEDURE CommonDialogFileOpen(lnFlags As Integer, taFiles) Local loForm As oForm, lcStrFiles As String loForm = Createobject("MultiSelectForm") loForm.commonDialog.Flags = lnFlags loForm.commonDialog.MaxFileSize = 0x7fff loForm.commonDialog.FileName = "" loForm.commonDialog.InitDir = (cDir) && Default folder loForm.commonDialog.FilterIndex = 0 && no idea what this is doing loForm.commonDialog.DialogTitle = "WinVIS.DigiDossier - Select one or more files..." loForm.commonDialog.Filter = "All files (*.*)|*.*|PDF documents (*.pdf)|*.pdf|JPG images (*.jpg)|*.jpg|PNG images (*.png)|*.png|E-mail (*.msg)|*.msg" loForm.commonDialog.ShowOpen IF LEN(ALLTRIM(loForm.commonDialog.FileName)) > 0 lcStrFiles = loForm.commonDialog.FileName Alines(taFiles,Chrtran(lcStrFiles,Chr(0),','),1,',') ELSE WAIT WINDOW "No files selected..." timeout(1) ENDIF ENDPROC DEFINE CLASS multiselectForm As Form ADD OBJECT commonDialog As OleControl With OleClass="MSComDlg.CommonDialog" && adding .1 makes no difference ENDDEFINE
The problematic Windows 10 32-bit pc has version 22H2, Build 19045.2251.
It's hard to believe that there is an actual licensing problem on 32-bit Windows and not on 64-bit Windows.
What can cause this OLE error? What can I try?
Regards, Gerrit
RE: Select multiple files in VFP
you have to make an installer for the right one or simply all of these merge modules.
The more known license issue you can have is with winsock, for which you also have redistribution rights with VFP9, but, well, you have to distribute it and copying files is not sufficient, these licenses are installed on clients by installing merge modules.
Chriss
RE: Select multiple files in VFP
I see these files in "C:\Program Files (x86)\Common Files\Merge Modules" on my development pc.
I use InnoSetup to install my application.
It's not clear to me what to do exactly. Do I have to distribute these files using the installer? I have never had to do this before for these files, but of course I can do that.
If I have to "merge modules" I don't have a clue how to install "merge modules" with InnoSetup (and given the complexity of my InnoSetup configuration I don't switch to another installer program).
What should I do?
Regards, Gerrit
RE: Select multiple files in VFP
VFP9 comees with installshield express, that can install those merge modules.
Before you do a setup with installshield make sure you update the merge modules, too. The latest version change came with the SP2 of VFP9, not sure if the hotfixes later also included yet newer merge modules, but we're talking about the merge modules for the common controls/dialogs and not C/C++ or VFP, so that might be unimportant.
You should be able to make a silent MSI setup that installs the merge module(s) and call that from your inno setup, so it remains all in one.
Chriss
RE: Select multiple files in VFP
I understand very well what you say and I'm sure this could work.
However I've never used InstallShield Express and I have no idea how to make a MSI setup.
Of course I will google for suggestions, but this is becoming way too complicated having to use an installer inside an installer...
Regards, Gerrit
RE: Select multiple files in VFP
https://vfphelp.com/vfp9/_5wn12pbga.htm
The section "Selecting Objects and Merge Modules" is for you.
And inno has I think a presetup and postsetup where you can specify a command which enables to start another setup.exe or msiexec.exe /i "C:\Example.msi"
Chriss
RE: Select multiple files in VFP
Have you seen the more recent thread about common dialogs? thread184-1819419: CommonDialog Issue
Chriss
RE: Select multiple files in VFP
Just installed InstallShield Express. I was able to add the MSM files, but I'm sure my config is not right. It compiles to an .exe file. Could I run the setup.exe "silent"? I don't want it to be visible. I left out the vfp runtime files and the MSXML 4.0 files that are mandatory according to the manual. I don't want to install these runtimes again and again, and my InnoSetup already takes care of this. Is this OK?
Where should I add the "merge modules" on the client's system? In the \program files\myapplication directory? In common files? How do I make a difference between 32-bit and 64-bit OS, as they have different file locations, using a single setup.exe file? Is InstallShield Express 5.0 aware of these differences?
I got stuck once again...
Regards, Grrit
RE: Select multiple files in VFP
That there is a system folder for merge modules only plays a role as it is a repository of which you can pick from in installshield projects.
How to build an MSI? Mybe this will help:
https://community.flexera.com/t5/InstallShield-For...
Chriss
RE: Select multiple files in VFP
I will not be able to do a lot in the coming days or next week, as I will be in the UK for a few days, but I will try to get this working when I have the time to do so.
Your latest link refers to later versions of InstallShield, where I only have version 5 from the old dark ages.
I will post back here when I have (no) results.
Regards, Gerrit
RE: Select multiple files in VFP
I've created an InstallShield Express installation for the MSM files as mentioned above.
I ran the installer on the 32-bit Windows 10 PC. According to the installer the installation was successful.
Nevertheless I still get the nasty 1426 error (OLE error code 0x80040112: Class is not licensed).
I'm out of options. I cannot release my new version and I definitely don't want to have two installation processes to maintain for my application. That is a no go area.
However I cannot keep my customers waiting too long for the awaited update (it should be finished at or around the 1st of December).
What are my options to get common dialogs running on a Windows 10 32-bit machine?
Regards, Gerrit
RE: Select multiple files in VFP
Did yout try the solution using direct API calls from https://github.com/VFPX/Win32API/blob/master/sampl...
As mentioned in thread184-1819419: CommonDialog Issue
Chriss
RE: Select multiple files in VFP
On the PC you tried your ISE install, can you search the registry for Computer\HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{F9043C85-F6F2-101A-A3C9-08002B2F49FB}?
This is the key export (edited to not violate copyrights):
CODE
On your dev PC you should have all this, as VFP installs it to enable development with the redistributable controls.
Chriss
RE: Select multiple files in VFP
COMDLG32.MSM should be the most relevant from that registry inspection.
By the way, as I mentioned the list of MSCOMCT2.MSM,MSCOMCTL.MSM, and MSCOMM32.MSM, I was pretty sure one of them had commdialogs and anotherone had something COM Port relevant.
Now (11/28 21:57 UTC) I'm pretty sure it's COMDLG32.MSM, but the API call is doable, though it means a lot more API declarations and making sure you allocate and deallocate memory without causing a leak, besides the harder way to get the informations into a struct. But all of that is in the sample code, fortunately.
Anyway, to stay with the easier OCX properties perhaps also give it a try to modify your ISE project to install that COMDLG32.MSM, instead of all the others. And another idea would be to install all merge modules mentioned by redist.txt, to have the setup for all redistributable controls, including Rich Text, Slider, Treeview and some more... If you'd provide it, I guess a lot of VFP programmers, who're also not happy to create ISE setup projects would take it to get that part off their shoulders, as long as it's only about those MS controls.
There are of course a bunch of OCX providers also specialized on documenting for VFP and their OCXes usually come with redistributable setups instead of merge modules.
Chriss
RE: Select multiple files in VFP
Chriss
RE: Select multiple files in VFP
I will check on all this tomorrow, when I have access to the W10 32-bit pc.
Regards, Gerrit
P.S. The Github link doesn’t work for me: “The 'VFPX/Win32API' repository doesn't contain the 'sampl' path in 'master'.”
RE: Select multiple files in VFP
Chriss
RE: Select multiple files in VFP
Chriss