How to Make EmEditor Plug-ins

In EmEditor, you can automate almost all operations with macros, external tools, and snippets. However, some users may still want to develop plug-ins for specific usages. Some benefits of writing of plug-ins include:

  • You can write C++ code with Win32 API.
  • You can write Graphic User Interface (GUI) elements such as dialog boxes.
  • You can use custom bars, custom toolbars, and the output bar.

On the other hand, you will need to use Microsoft Visual C++, which is difficult to write. However, if you are already used to C++ or Win32, plug-ins will be easier to write.

Hello World Sample

If you don’t already have Visual C++ 2012, you can download and install Visual Studio Express 2012 for Windows Desktop. It can be downloaded from here:

In the EmEditor website library, The Hello World!! sample is available for download.  You can download it at:

If you download this file, extract it to a folder, and open the Hello.sln solution with Visual C++, you will find the following files are included in the Hello project.

File nameUsageNeed to edit?
etlframe.hETL (EmEditor Template Library) headerNo
hello.hHello World plug-in implementation fileYes
plugin.hEmEditor plug-in headerNo
resource.hHello World plug-in resource fileYes
stdafx.hPrecompile headerMaybe
bitmap1.bmpToolbar button bitmap (16 colors, 16×16 pixels)Yes
hello.rcHello World plug-in resourceYes
hello.cppHello World plug-in implementation fileMaybe
hello.defDefinition fileNo

Among these files, files that need to be edited are hello.h, hello.rc, resource.h, and bitmap1.bmp. hello.cpp and stdafx.h can be modified if you need to add header files. On the other file, plugin.h and etlframe.h files are header files that are provided by Emurasoft, and should not be modified. The newest versions of these header files can be downloaded from:

hello.def is the file that defines exportable functions EmEditor needs, and does not need to be modified.

First, if you open the project, try building without changing anything. Then you will see the file Hello.dll. Copy this file into the PlugIns sub folder of the EmEditor install folder. Usually, this is C:\Program Files\EmEditor\PlugIns. Then if you run EmEditor, you will see a yellow circle button in the Plug-ins toolbar. If you click on the button, you will see the Hello World!! text in the text editor.

In the next section, let’s modify this sample so that the plug-in opens the Output Bar, and displays the Hello World!! text in the Output Bar.

Most Important Function: OnCommand

The most important function in the hello.h file is OnCommand. This is called when a user selects the plug-in from the menu or clicks on the plug-in button. By modifying the function contents, you can change the plug-in behavior however you like. In this sample, after deleting the existing the Editor_InsertW function, please add the following Editor_OutputString function.

// Editor_InsertW( hwndView, L"Hello World!!\n", true );
Editor_OutputString( hwndView, L"Hello World!!\n", FLAG_OPEN_OUTPUT );

The above functions that start with Editor_ are defined in plug-in.h. After you open hello.h with EmEditor, place the cursor in a function name that starts with Editor_, and press F1 to see the function description in the Help.

In the hello.h file, the next important function is QueryStatus. The QueryStatus function is called when EmEditor displays a menu or when it needs to be updated to refresh toolbar buttons. The function returns TRUE when the plug-in is enabled. Also,

*pbChecked = TRUE

will check the plug-in menu item and the toolbar button will be shown in the pressed state.

OnEvents is called when a file is opened, a document is updated, or various other events happen. The list of events can be found in the HelpPlug-in referenceEvents page. Among these events, we will alter the EVENT_CHANGE event to display the “Text Changed!!” text in the Output Bar. To do this, we will add the following 3 lines:

if( nEvent & EVENT_CHANGE ){
    Editor_OutputString( hwndView, L"Text changed!!\n", FLAG_OPEN_OUTPUT );

Modifying Resources

Next, we will look at the hello.rc file. This file defines various strings including IDS_MENU_TEXT, which is the name of the plug-in. Let’s change this name to “Hello Test!“.

    IDS_MENU_TEXT "Hello Test!"
    IDS_SURE_TO_UNINSTALL "Are you sure you want to uninstall this Plug-in?"

Moreover, bitmap1.bmp can be replaced with your favorite image and saved. In this example, we will change it to a red circle.

That’s all. If you build the sample project with Visual C++, your customized Hello.dll plug-in will be created. If you copy the new plug-in to the PlugIns sub folder of the EmEditor install folder, run EmEditor, and click the plug-in button. The “Hello World!!” text will appear in the Output Bar. Try entering new text in the text editor, and you will see the “Text changed!!” text appear in the Output Bar.

Notes when Customizing Plug-ins

In the above example, we modified the Hello sample. However, if you want to create a new plug-in from scratch, there are some points you will need to make sure are correct. One of them is to prepare a definition file like hello.def. This file defines functions that the DLL file must export. Another point is that the hello.def file must be specified as the Module Definition File in LinkerInput. Moreover, __stdcall must be specified as the Calling Convention in C/C++Advanced. In C/C++Code Generation, select Multi-threaded, not Multi-threaded DLL. In Optimization, select Favor small code. This way, the plug-in becomes small, and reduces dependency to runtime libraries.

Standard Plug-in Source Code

The source code of some plug-ins that come with EmEditor are available to download at:

The following plug-in source code is available:

  • HTMLBar
  • OpenDocuments
  • OutlineText
  • Search
  • WordCount

Among these, the HTMLBar is a good reference to make a custom toolbar. Other plug-ins can be a good reference to make a custom bar. Use these source code as a reference to develop plug-ins for yourself.

I have explained how to create EmEditor plug-ins. We only created a simple sample here, but it is up to your ideas what plug-ins you create. Please create your own useful plug-ins and utilize them to increase your productivity!

Share with friends... Tweet about this on TwitterShare on FacebookShare on Google+Email this to someone