Results 1 to 5 of 5

Thread: Command$ MDI Single Instance.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Command$ MDI Single Instance.

    Hi all.

    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?
    Attached Files Attached Files
    Last edited by sgrya1; Nov 15th, 2008 at 02:11 AM.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Command$ MDI Single Instance.

    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.
    Attached Files Attached Files
    Last edited by LaVolpe; Nov 15th, 2008 at 11:11 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Command$ MDI Single Instance.

    Have a look at File Association, it could somehow apply in your case.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  4. #4
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Command$ MDI Single Instance.

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

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: Command$ MDI Single Instance.

    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)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width