Event With Open With Processing (WinApi)

I cannot find how I should handle opening a file in my program. For example, if a user runs Open With ... myprogram.exe, then how do I handle this and do something with it. which is sent to WM_Message? Thanks

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

+3
source share
3 answers

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

NoOpenWith KCR\Applications\myprogram.exe, , . , , HKCR\Applications\myprogram.exe\shell\open\Command, ( DDE Droptarget, " " )

, openwith , , , , myprogram.exe/openwith "% 1"

+2

, -

  // 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;
        }

// (...)
0

Source: https://habr.com/ru/post/1742623/


All Articles