Programming Notepad++ plugins
In this article we will show how to program Notepad++ plugins using a simple Hello World program. For this you need Visual Studio from Microsoft. It is available for free at https://visualstudio.microsoft.com/de/downloads/.
Download the Notepad++ Plugin Template and unzip it. Then open the file NppPluginTemplate.vcxproj with Visual Studio.
The name of the plugin is defined in the PluginDefinition.h file.
const TCHAR NPP_PLUGIN_NAME[] = TEXT("Notepad++ plugin template");
The template already contains two functions. These are defined in the same PluginDefinition.h file.
//
// Your plugin command functions
//
void hello();
void helloDlg();
#endif //PLUGINDEFINITION_H
The implementation of the functions is located in the PluginDefinition.cpp file.
void hello()
{
// Open a new document
::SendMessage(nppData._nppHandle, NPPM_MENUCOMMAND, 0, IDM_FILE_NEW);
// Get the current scintilla
int which = -1;
::SendMessage(nppData._nppHandle, NPPM_GETCURRENTSCINTILLA, 0, (LPARAM)&which);
if (which == -1)
return;
HWND curScintilla = (which == 0)?nppData._scintillaMainHandle:nppData._scintillaSecondHandle;
// Say hello now :
// Scintilla control has no Unicode mode, so we use (char *) here
::SendMessage(curScintilla, SCI_SETTEXT, 0, (LPARAM)"Hello, Notepad++!");
}
Here a new text file is created and "Hello, Notepad++!" is written into this file.
void helloDlg()
{
::MessageBox(NULL, TEXT("Hello, Notepad++!"), TEXT("Notepad++ Plugin Template"), MB_OK);
}
The helloDlg() function opens a textbox with the same message.
The two functions are made available with the following code in the navigation bar under Plugins>>Notepad++ plugin template.
void commandMenuInit()
{
setCommand(0, TEXT("Hello Notepad++"), hello, NULL, false);
setCommand(1, TEXT("Hello (with dialog)"), helloDlg, NULL, false);
}
Now click Start without debugging. The file NppPluginTemplate.dll is now created and is available in the solution folder under x64\Debug.
Copy the NppPluginTemplate.dll into the Notepad++ installation folder under Notepad++\plugins\NppPluginTemplate.
If you now start Notepad++ your plugin with the two functions is available under the Plugins Menu.
You are welcome to upload your solution on our website.