Results 1 to 3 of 3

Thread: DDE File Associations (open multiple files with a single memory-copy of your program)

  1. #1

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,852

    DDE File Associations (open multiple files with a single memory-copy of your program)

    I wound up pulling this project together for another thread, and it wound up being fairly nice, so I thought I'd post it here.

    Basically, it's for the situation where you want a single-running-copy of your program to process multiple data-files (possibly opened at different times). You may process these data-files with the MDI forms mechanism, or some other way. That's entirely up to you.

    The idea/concept I'm giving you just illustrates how to make sure these data-files are all opened with one-memory-copy of your program (and not opened with a separate copy for each data-file, which is more typical of VB6 programs).

    For purposes of this demonstration, I'm going to assume we're talking about a .zzz data-file type.

    There are several ways that multiple data-files might be specified for opening with your program:
    1. double-click a single .zzz, but then find another and double-click it, and then again and again.
    2. select multiple .zzz files, right-click, and click "open".
    3. open a copy of your program, and then drag a .zzz file onto it, and possibly do this over and over.
    4. select multiple .zzz files, and then drag them onto an opened copy of your program.
    5. drag single .zzz files onto the program's executable in Windows explorer, and do this over and over.
    6. select multiple .zzz files, and then drag them onto the program's executable in Windows explorer.


    There's one other way a .zzz data-file might be opened. You might have a Menu/File/Open... option on your program's menu. This is the one way I didn't cover. I figured you could work this one out on your own. It's all these other ways that can cause problems, possibly opening several copies of your program, rather than opening all the data-files in a single copy in memory.

    Let me address the mechanisms to the file-open methods listed above (1-thru-6). For #1 & #2 to work, there has to be a file association in Windows. Furthermore, for all double-clicked files (of your type, say .zzz) to be opened in one copy of your program, the Windows registry has to be set up for this. There are several approaches, but I've chosen the DDE File Association approach. This is all rather thoroughly discussed in this thread, or you can just "think through" the mnuCheckRegistry_Click procedure in the provided source code.

    Mechanisms #3 & #4 just take advantage of the OleDropMode ability of VB6 forms and controls.

    Mechanisms #5 & #6 circumvent the DDE file association, and attempt to directly open the data-file with a fresh copy of the program. To inhibit this behavior, the App.PrevInstance property is used, sending the correct DDE command to the copy of the program that's already running.

    That's about it. Please see the sFileTypeExtension and possibly the sFileDescription constants at the top of the Form1 code. You'll probably want to alter those for your specific needs. Also, the DoSomethingWithFiles procedure is where you'd actually do something with your files, such as maybe open each of them in a MDI child form.

    Enjoy,
    Elroy
    Attached Files Attached Files
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  2. #2
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    673

    Re: DDE File Associations (open multiple files with a single memory-copy of your prog

    thanks!can you give me a video about the exe to work?i want to konw how to used your code for me !

  3. #3

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,852

    Re: DDE File Associations (open multiple files with a single memory-copy of your prog

    WHAT?!?!?! Sorry, no videos today.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

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