Sending NPPM_SWITCHTOFILE command freeze npp
-
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 -
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 withSCI_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. :-)

-
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. -
Don’t know anything about the rubber duck, but thank you this was the problem, thank you !
-
@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.
:-) -
@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. ;-)
-
@PeterJones I checked wikipedia, now I understand the method and already used it without knowing :-)
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