Community
    • Login

    Sending NPPM_SWITCHTOFILE command freeze npp

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    7 Posts 3 Posters 1.1k Views 2 Watching
    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.
    • Gregory D.G Offline
      Gregory D.
      last edited by

      Hello, I’m trying to swith to a specific file tab by sending the NPPM_SWITCHTOFILE command with the full local path, but it makes notepad++ unresponsive.
      This is my code:

      wstring localpath=L"c:\\test.txt";
      
      int which = -1;
      ::SendMessage(nppData._nppHandle, NPPM_GETCURRENTSCINTILLA, 0, (LPARAM)&which);
      if (which == -1)
      	return;
      
      HWND curScintilla = (which == 0) ? nppData._scintillaMainHandle : nppData._scintillaSecondHandle;
      
      ::SendMessage(curScintilla, NPPM_SWITCHTOFILE, 0, (LPARAM)localpath.c_str());
      

      (SendMessage returns 0)

      What’s the problem with my code ? I don’t find example of how to call this command.
      THanks

      1 Reply Last reply Reply Quote 1
      • PeterJonesP Offline
        PeterJones
        last edited by PeterJones

        My guess is it’s because you are sending a Notepad++ message to one of the Scintilla windows, instead of to Notepad++ itself.

        Try:

        ::SendMessage(nppData._nppHandle, NPPM_SWITCHTOFILE, 0, (LPARAM)localpath.c_str());
        

        As a reminder, all Notepad++ messages start with NPPM_, and go to the NPP handle. Scintilla messages start with SCI_ and go to one of the Scintilla handles.

        For future reference, the Notepad++ messages are officially documented at https://npp-user-manual.org/docs/plugin-communication/ … though @Ekopalypse just did a revamp which is available at github but not yet on the official site.

        Though the docs wouldn’t have been the Rubber Duck that I provided. :-)

        1 Reply Last reply Reply Quote 3
        • Alan KilbornA Offline
          Alan Kilborn
          last edited by

          I don’t think this was a “rubber duck” issue.
          Why?
          Because if the rubber duck method had been used by the OP, the OP probably would have realized the mistake while talking to the duck, and a posting never would have been created.

          PeterJonesP 1 Reply Last reply Reply Quote 1
          • Gregory D.G Offline
            Gregory D.
            last edited by

            Don’t know anything about the rubber duck, but thank you this was the problem, thank you !

            Alan KilbornA 1 Reply Last reply Reply Quote 1
            • Alan KilbornA Offline
              Alan Kilborn @Gregory D.
              last edited by

              @Gregory-D said in Sending NPPM_SWITCHTOFILE command freeze npp:

              Don’t know anything about the rubber duck

              Probably should learn about the duck.
              He’s helpful.
              :-)

              1 Reply Last reply Reply Quote 2
              • PeterJonesP Offline
                PeterJones @Alan Kilborn
                last edited by

                @Alan-Kilborn said in Sending NPPM_SWITCHTOFILE command freeze npp:

                would have realized the mistake while talking to the duck

                Yeah, probably not technically a rubber duck. But a second set of eyes helps, too. ;-)

                Gregory D.G 1 Reply Last reply Reply Quote 3
                • Gregory D.G Offline
                  Gregory D. @PeterJones
                  last edited by

                  @PeterJones I checked wikipedia, now I understand the method and already used it without knowing :-)

                  1 Reply Last reply Reply Quote 1

                  Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                  Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                  With your input, this post could be even better 💗

                  Register Login
                  • First post
                    Last post
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors