tags:

views:

38

answers:

3

I cannot find how I'm supposed to handle file opening in my program. For example if the user does Open With ... myprogram.exe then how do I handle that and do something with it. which WM_Message is sent? Thanks

*no I mean if you have sometext.txt and openwith Notepad.exe, it magically displays the text, so how can I know if someone used Open With.

+1  A: 

I think, I'd better post here some code from my notepad

  // Menu commands
  case WM_COMMAND: 
  {
      switch(LOWORD(wParam)) {

      // (...)

      case ID_FILE_OPEN:
        {
          OPENFILENAME  of = {0};
          CHAR          filename[max_filename_size] = "";

          // Init OPENFILENAME structure

          of.lStructSize       = sizeof(OPENFILENAME);
          of.hwndOwner         = hwnd;
          of.hInstance         = GetModuleHandle(NULL);
          of.lpstrFilter       = "All files (*.*)\0*.*\0";
          of.lpstrCustomFilter = NULL;
          of.nFilterIndex      = 1L;
          of.lpstrFile         = filename;
          of.nMaxFile          = MAX_PATH;
          of.Flags             = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;

          // Invoke open file dialog
          if (GetOpenFileName(&of)) 
          {
            // My own routine, change to something yours that acts
            // with "filename"
            OpenExistingFile(handler, reader, filename);
          }
          break;
        }

// (...)
Kotti
I'm looking to handle when the user uses Open With, not how to actually do File -> Load... I have this already
Milo
Sorry, misunderstood you. I don't quiet understand what do you want to do in this case. `Open With` seeks up the registry for appropriate command to invoke, like `myprogram.exe %1" (if this command is binded) and then launches it. So the effect is the same as if you called your program from `cmd.exe` like `myprogram.exe filename.txt` (ofc, you have to have command line parsing routine)
Kotti
The other situation that I think is possible is general hooking of this 'Open With' action (so you want to know if ANY open-with actions are done on your machine), but this would require placing your own hook and I think it's not what you want from your application.
Kotti
A: 

http://msdn.microsoft.com/en-us/library/ms646960%28VS.85%29.aspx

GetOpenFileName & GetSaveFileName

evilpie
+1  A: 

There is no message sent, you will probably get it on the commandline, use argc/argv or GetCommandLine()

The shell first checks for a NoOpenWith value in KCR\Applications\myprogram.exe if it is not there, your app is listed in the open with dialog. If the user chooses your app, the shell will use the command listed under HKCR\Applications\myprogram.exe\shell\open\Command if it exists (You could then assign DDE or Droptarget properties if that is how you want to handle the "incoming files")

If you really want to know if openwith was used, I guess you could register a command under the shell key that executes your app with a command line like myprogram.exe /openwith "%1"

Anders