• Login
Community
  • Login

Sending NPPM_SWITCHTOFILE command freeze npp

Scheduled Pinned Locked Moved Notepad++ & Plugin Development
7 Posts 3 Posters 410 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.
  • G
    Gregory D.
    last edited by May 23, 2020, 4:11 PM

    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
    • P
      PeterJones
      last edited by PeterJones May 23, 2020, 5:01 PM May 23, 2020, 4:59 PM

      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
      • A
        Alan Kilborn
        last edited by May 23, 2020, 6:26 PM

        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.

        P 1 Reply Last reply May 23, 2020, 8:08 PM Reply Quote 1
        • G
          Gregory D.
          last edited by May 23, 2020, 7:09 PM

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

          A 1 Reply Last reply May 23, 2020, 7:34 PM Reply Quote 1
          • A
            Alan Kilborn @Gregory D.
            last edited by May 23, 2020, 7:34 PM

            @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
            • P
              PeterJones @Alan Kilborn
              last edited by May 23, 2020, 8:08 PM

              @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. ;-)

              G 1 Reply Last reply May 24, 2020, 7:39 AM Reply Quote 3
              • G
                Gregory D. @PeterJones
                last edited by May 24, 2020, 7:39 AM

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

                1 Reply Last reply Reply Quote 1
                4 out of 7
                • First post
                  4/7
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors