Skip to content

v.1.3.0 Add support for plugin communication via NPPM_MSGTOPLUGIN

Compare
Choose a tag to compare
@Ekopalypse Ekopalypse released this 06 Oct 09:27
· 5 commits to main since this release
1993f87

Add support for plugin communication via NPPM_MSGTOPLUGIN.
For an example of a Python script, see the following:

import ctypes
from ctypes import wintypes
from Npp import editor, console

NPPM_MSGTOPLUGIN = 2071  # 1000 + 1024 + 47

class CommunicationInfo(ctypes.Structure):
    _fields_ = [
        ('internalMsg', wintypes.INT),
        ('srcModuleName', wintypes.LPCWSTR),
        ('info', ctypes.c_void_p),
    ]

user32 = ctypes.WinDLL('user32', use_last_error=True)

SendMessage = user32.SendMessageW
SendMessage.argtypes = [wintypes.HWND, wintypes.UINT, wintypes.WPARAM, wintypes.LPARAM]
SendMessage.restype = ctypes.c_ssize_t

FindWindow = user32.FindWindowW
FindWindow.argtypes = [wintypes.LPCWSTR, wintypes.LPCWSTR]
FindWindow.restype = wintypes.HWND

ci = CommunicationInfo()
ci.internalMsg = 1  # file saved message
ci.srcModuleName = u"PythonScript.dll"
ci.info = 0
destModuleName = ctypes.create_unicode_buffer("EnhanceAnyLexer.dll")

def on_error(msg):
    console.show()
    print('Error:', msg)

def main():


    npp_hwnd = FindWindow(u'Notepad++', None) # Only required if using PythonScript2, if using Python3 use notepad.hwnd instead
    if not npp_hwnd:  # This should never happen, but who knows ...
        on_error('The Notepad++ window was not found!!')
        return
    if not SendMessage(npp_hwnd, NPPM_MSGTOPLUGIN, ctypes.addressof(destModuleName), ctypes.addressof(ci)):
        # When we come here it usually means that the corresponding plugin was not found.
        on_error('Sending the file saved message to EnhanceAnyLexer plugin failed!!')
        return

main()