2

Background: I want to add my application to the windows context menu, I have done this by adding a new key to the windows registry:

HKEY_CLASSES_ROOT\*\shell\myapp
HKEY_CLASSES_ROOT\*\shell\myapp\command

And assigning the default value of the "command" key to the location of my exe, plus an extra argument:

value = "c:\users\john\myapp\myappexe.exe" "%1" arg1

It works, i can 'right click' any file and run my application with that file. The problem comes when I try to select multiple files, it opens as many windows of my app as files selected, I want to be able to handle all the inputs with one instance of my program.

I'm aware that this may be solved by creating shell extensions as posted here, here, here or here. Creating a full functional shell extension is out of the scope of my (small) project, and I haven't found tutorials which I can understand.

Problem: I'm looking a way around it, and I found that a program called from the "send to" folder in windows is able to handle multiple files, for example, if i put the execulable of this code (c++) in the C:\Users\john\AppData\Roaming\Microsoft\Windows\SendTo folder,

#include <iostream>
using namespace std;

int main(int argc, char* argv[]){
    for(int i=0;i<=argc;i++){
        cout << argv[i] << endl;
    }
    return 0;
}

...select a bunch of flies, and drag them into the executable, I'll get in one window the path of all the selected files (send to tutorial). How does this work? Can I use this behavior and apply it to my app?

Community
  • 1
  • 1
user3787097
  • 181
  • 3
  • 14

1 Answers1

0

One approach is to design your application so that any newly launched instance checks for a pre-existing instance (you could use a mutex to do this) and then forwards the command-line parameters to that one, encapsulated in a message of some kind. The original instance can then take the appropriate action.

equin0x80
  • 303
  • 1
  • 9