×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Select multiple files in VFP

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.

RE: Select multiple files in VFP

You can do this with the native VFP listbox control. You would use ADIR() to get the filenames into an array (set the nFlag parameter to 1 to retain the original case setting), and then use the array to populate the listbox. Set the listbox's MultiSelect to .T. to enable multiple selections.

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

Even not using VFP I usually only zip folders, the simplest way to pick one thing that contains all I want to zip. Zipping a bunch of files always poses the risk for someone to unzip a bulkload of files somewhere instead of unzipping them in a folder. That said it's annoying to me, on the other side, that Windows default unzip option is to create a folder of the zip name and unzip into that.

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

* Taken from https://microsoft.public.fox.programmer.exchange.narkive.com/CZNSkocv/sample-code-using-common-dialog-to-select-multiple-files
* and adjusted

#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.

lnFlags = OFN_EXPLORER+OFN_ALLOWMULTISELECT+OFN_LONGNAMES
Local Array laFiles[1]
CommonDialogFileOpen(lnFlags,@laFiles)

Clear
For Each lcFile In laFiles
   ? lcFile
Next

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.ShowOpen
   lcStrFiles = loForm.commonDialog.FileName
   Alines(taFiles,Chrtran(lcStrFiles,Chr(0),','),1,',')
Endproc

Define Class multiselectForm As Form
   Add Object commonDialog As OleControl With OleClass="MSComDlg.CommonDialog"
Enddefine 

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

(OP)
Hi Chriss,

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

Add Object commonDialog As OleControl With OleClass="MSComDlg.CommonDialog" 
However I cannot get this working.

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

Well, the way this uses the OleClass="MSComDlg.CommonDialog" is with a form, an empty form.

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

(OP)
Hi Chris,

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

loForm.commonDialog.cInitialDirectory = cDir      && [C:\...\My Documents] 

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

loForm.commonDialog.AddFilter([PDF-files (*.pdf)],[*.pdf]) 

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

lcStrFiles = loForm.commonDialog.FileName 

I solved this by adding

CODE --> foxpro

IF LEN(ALLTRIM(loForm.commonDialog.FileName)) > 0 

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

(OP)
Hi all,

I found a way to offer filter options to the commonDialog:

CODE --> foxpro

loForm.commonDialog.Filter = "All files (*.*)|*.*|PDF documents (*.pdf)|*.pdf|JPG images (*.jpg)|*.jpg|PNG images (*.png)|*.png|E-mails (*.msg)|*.msg" 

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

(OP)
Hi all,

I tried this CommonDialog on a Windows 7 PC, but I get error 1426 on this line:

CODE --> foxpro

loForm = Createobject("MultiSelectForm") 

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

What did you install on that Windows 7? Only you exe, did you install the runtimes.

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

Oh, my mistke, the error you get points out you DO use the MultiSelectForm that uses the common dialog on a VFP form.

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

(OP)
Hi Chris,

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

loForm.commonDialog.InitDir = (cDir) && cDir is a variable with the default directory to use in the common dialog form 

RE: Select multiple files in VFP

Quote (Gerrit Broeckhuis)

I just found the solution (Google is my friend):
Also a breakpoint an intellisense in the command window or the locals window of the debugger are your friends:


Sorry, tek-tips doesn't seem to like screen sized images, it looks a bit blurry.

Chriss

RE: Select multiple files in VFP

(OP)
Hi Chriss,

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

(OP)
Hi Chriss and everyone else,

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

Quote (myself)

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

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

(OP)
Hi Chriss,

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

As far as I remember inno setup doesn't have the facility to install merge modules. But inno setup experts might help.
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

(OP)
Hi Chriss,

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

There's an easy to follow walkthrough about installshield, and you only need some steps about the merge modules.
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

Besides the possibility to activate the license. I'm not sure it's necessary for common dialogs themselves, just for the OLE helper class "MSComDlg.CommonDialog".

Have you seen the more recent thread about common dialogs? thread184-1819419: CommonDialog Issue

Chriss

RE: Select multiple files in VFP

(OP)
Hi Chriss,

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

Merge modules are prepared installations, they don't get copied to a client, they include things like DLLs and license keys that get somewhere, into the registry for example. That's why you don't get around making an installer that also installs - more like executes - the merge modules. Merge modules are not executables in themselves, though and just putting them anywhere doesn't do anything.

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

(OP)
Hi Chriss,

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

(OP)
Hi,

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

There's also a step in an ISE setup project to register OCXes. This might be necessary, though I thought the merge modules would not just put files into the right places, but also register them.

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

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{F9043C85-F6F2-101A-A3C9-08002B2F49FB}]
@="Microsoft Common Dialog Control, version 6.0 (SP6)"

[HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{F9043C85-F6F2-101A-A3C9-08002B2F49FB}\Control]

[HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{F9043C85-F6F2-101A-A3C9-08002B2F49FB}\Implemented Categories]

[HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{F9043C85-F6F2-101A-A3C9-08002B2F49FB}\Implemented Categories\{0DE...redacted...352}]

[HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{F9043C85-F6F2-101A-A3C9-08002B2F49FB}\Implemented Categories\{0DE...redacted...352}]

[HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{F9043C85-F6F2-101A-A3C9-08002B2F49FB}\Implemented Categories\{0DE...redacted...352}]

[HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{F9043C85-F6F2-101A-A3C9-08002B2F49FB}\Implemented Categories\{40F...redacted...502}]

[HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{F9043C85-F6F2-101A-A3C9-08002B2F49FB}\Implemented Categories\{40F...redacted...502}]

[HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{F9043C85-F6F2-101A-A3C9-08002B2F49FB}\Implemented Categories\{7DD...redacted...2C4}]

[HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{F9043C85-F6F2-101A-A3C9-08002B2F49FB}\InprocServer32]
@="C:\\WINDOWS\\SysWow64\\comdlg32.ocx"
"ThreadingModel"="Apartment"
"InprocServer32"=...redacted...

[HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{F9043C85-F6F2-101A-A3C9-08002B2F49FB}\MiscStatus]
@="0"

[HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{F9043C85-F6F2-101A-A3C9-08002B2F49FB}\MiscStatus\1]
@="...redacted..."

[HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{F9043C85-F6F2-101A-A3C9-08002B2F49FB}\ProgID]
@="MSComDlg.CommonDialog.1"

[HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{F9043C85-F6F2-101A-A3C9-08002B2F49FB}\Programmable]

[HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{F9043C85-F6F2-101A-A3C9-08002B2F49FB}\ToolboxBitmap32]
@="C:\\WINDOWS\\SysWow64\\comdlg32.ocx, 1"

[HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{F9043C85-F6F2-101A-A3C9-08002B2F49FB}\TypeLib]
@="{F9043C88-F6F2-101A-A3C9-08002B2F49FB}"

[HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{F9043C85-F6F2-101A-A3C9-08002B2F49FB}\Version]
@="1.2"

[HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{F9043C85-F6F2-101A-A3C9-08002B2F49FB}\VersionIndependentProgID]
@="MSComDlg.CommonDialog" 

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

As you can see it's about the comdlg32.ocx, what merge modules did you provide by your setup?
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

On a pure 32bit system the reg key name would differ about the WOW6432NODE, not sure how exactly, but searching for the CLSID GUID {F9043C85-F6F2-101A-A3C9-08002B2F49FB} should get you to all relevant places in the registry.

Chriss

RE: Select multiple files in VFP

(OP)
Hi Chriss,

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

Full link text to copy&paste into browser URL: https://github.com/VFPX/Win32API/blob/master/samples/sample_363.md

Chriss

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close