Community
    • Login

    NPPM_DOOPEN: wrong return value

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    3 Posts 2 Posters 1.7k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Vitaliy DovganV
      Vitaliy Dovgan
      last edited by

      The message NPPM_DOOPEN is declared as:

      #define NPPM_DOOPEN (NPPMSG + 77)
      // BOOL NPPM_DOOPEN(0, const TCHAR *fullPathName2Open)
      // fullPathName2Open indicates the full file path name to be opened.
      // The return value is TRUE (1) if the operation is successful, otherwise FALSE (0).
      

      The return value is correct when fullPathName2Open is a file (path)name.
      If, however, the fullPathName2Open is a folder, Notepad++ does open all the files from this folder, but NPPM_DOOPEN returns 0 !

      1 Reply Last reply Reply Quote 1
      • dailD
        dail
        last edited by

        I can at least confirm I am seeing the same behavior as you.

        As a side note: the “documentation” in that file has more than a few errors if you actually compare them to the code :)

        1 Reply Last reply Reply Quote 0
        • Vitaliy DovganV
          Vitaliy Dovgan
          last edited by Vitaliy Dovgan

          OK, I’ve found how to deal with it. At least, it’s one of possible solutions:

          int nFiles = (int) SendNppMsg(NPPM_GETNBOPENFILES, 0, 0);
          if ( !SendNppMsg(NPPM_DOOPEN, (WPARAM) 0, (LPARAM) params.c_str()) )
          {
              nCmdResult = CMDRESULT_FAILED;
              DWORD dwAttr = ::GetFileAttributes(params.c_str());
              if ( (dwAttr != INVALID_FILE_ATTRIBUTES) &&
                   ((dwAttr & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY) )
              {
                  // NPPM_DOOPEN unexpectedly returns 0 when a folder is specified
                  // as its argument, though in fact it does open all the files
                  // from that folder.
                  int nFilesNow = (int) SendNppMsg(NPPM_GETNBOPENFILES, 0, 0);
                  if ( nFilesNow != nFiles )
                  {
                      nCmdResult = CMDRESULT_SUCCEEDED;
                  }
              }
          }
          
          1 Reply Last reply Reply Quote 1
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors