I am having trouble getting my MDI app to only run a single instance when opening associated files from explorer.
I found some code which explains how to do it but something is wrong. This is the web page that I got the code from.
Problem is that when you select multiple files from explorer and press Enter, Command$ isn't a string of delimited filenames as the example suggests.
Also..the LongFileName routine splits the filename into segments delimited by "\".
I've fiddled around with it and the attached document works ok if you try to open a second file.
But not if you select more than one file.
Might need to look at the original code in the link. My small modifications may have confused the matter.
There is a .iss file to create the association with .ddef filetypes.
Anyone have any idea on what is wrong with it and how to get it going?
Last edited by sgrya1; Nov 15th, 2008 at 02:11 AM.
You are correct, you do not get multi-file, delimited, command line. If you selected 4 files and hit enter, you get 4 instances of your app. I think the problem may be something along this line:
1. Each file is opening new instance of your app
2. By the time you initialize & execute DDE, one of the other instances may be the one that is activated via AppActivate Cap. Changing Caption to "" immediately and removing DoEvents, prevented the errors, however, it didn't make it work either.
Personally, I don't prefer DDE in this case, I prefer some other innovative hacks. Besides App.PrevInstance can fail in specific cases.
>Where it can fail is when the EXE is executed from another folder/drive or the same EXE is executed but under another name. The App.PrevInstance fails. Most ppl don't install or copy EXEs multiple times across different drives/folders. However, there are times when that is done or can be commonplace (i.e., mapped/network drives). Also ppl don't normally copy and rename the same EXE, then execute both of them at same time -- but who knows<
Here is an alternate solution. Read the remarks. 95% remarks, 5% code in the attached.
Edited: P.S. Here is where you'll get a delimited list of filenames. User drags multiple files onto your exe or onto a shortcut to your exe.
Last edited by LaVolpe; Nov 15th, 2008 at 11:11 AM.
Insomnia is just a byproduct of, "It can't be done"
When using that kind of a method, I'd use some unique class id on some API created window and then simply check if it exists. If it does, use a SendMessage with a custom registered message containing a StrPtr of a string that contains the results of Command$. Otherwise create the window.
You may also be interested of Command function in http://kontu.selfip.info/vb6/project...nteraction.bas - it enables Unicode filenames for you. You could also change the way the function works so that it won't be as impractical as native Command$ (take the Replace out to prevent a convert from null char separated list to space separated).
Ooo. Way out of my depth there Merri.
Took me ages to work out that the DDE method didn't work. Not easy debugging a compiled program with messageboxes. There an easier way?
Not yet tested your one LaVolpe. Think it's simple enough for me to be able to implement.
I've set everything up already using DDE. I have associated the files using **********. Would that file association method be any different in the way it generates a command$? I think I need the all the files in a delimited string so that I can cycle through them and open them one by one.
The page says: "To retrieve the name of the file(s) used as the start-up parameter, use the Command$() function in VB."
file (s)