MFC创建notepad++ plugin

    xiaoxiao2021-12-14  19

    MFC创建notepad++ plugin

    flyfish

    所需要的代码文件全部从官网自带的例子NppPluginTemplate中获取

    1 MFC 创建DLL

    创建规则DLL(共享MFC)

    选择 带静态链接MFC的规则DLL(R)

    假设这里创建的项目名称为x 2 创建完成后将下面6个文件添加到项目中

    menuCmdID.h Notepad_plus_msgs.h PluginDefinition.cpp PluginDefinition.h PluginInterface.h Scintilla.h

    3 X.cpp更改代码如下

    #include "stdafx.h" #include "X.h" #include "PluginDefinition.h" #ifdef _DEBUG #define new DEBUG_NEW #endif extern FuncItem funcItem[nbFunc]; extern NppData nppData; // //TODO: 如果此 DLL 相对于 MFC DLL 是动态链接的, // 则从此 DLL 导出的任何调入 // MFC 的函数必须将 AFX_MANAGE_STATE 宏添加到 // 该函数的最前面。 // // 例如: // // extern "C" BOOL PASCAL EXPORT ExportedFunction() // { // AFX_MANAGE_STATE(AfxGetStaticModuleState()); // // 此处为普通函数体 // } // // 此宏先于任何 MFC 调用 // 出现在每个函数中十分重要。 这意味着 // 它必须作为函数中的第一个语句 // 出现,甚至先于所有对象变量声明, // 这是因为它们的构造函数可能生成 MFC // DLL 调用。 // // 有关其他详细信息, // 请参阅 MFC 技术说明 33 和 58。 // // CXApp BEGIN_MESSAGE_MAP(CXApp, CWinApp) END_MESSAGE_MAP() // CXApp 构造 CXApp::CXApp() { // TODO: 在此处添加构造代码, // 将所有重要的初始化放置在 InitInstance 中 } // 唯一的一个 CXApp 对象 CXApp theApp; // CXApp 初始化 BOOL CXApp::InitInstance() { CWinApp::InitInstance(); pluginInit(AfxGetInstanceHandle()); return TRUE; } int CXApp::ExitInstance() { // TODO: 在此添加专用代码和/或调用基类 pluginCleanUp(); return CWinApp::ExitInstance(); } extern "C" __declspec(dllexport) void setInfo(NppData notpadPlusData) { nppData = notpadPlusData; commandMenuInit(); } extern "C" __declspec(dllexport) const TCHAR * getName() { return NPP_PLUGIN_NAME; } extern "C" __declspec(dllexport) FuncItem * getFuncsArray(int *nbF) { *nbF = nbFunc; return funcItem; } extern "C" __declspec(dllexport) void beNotified(SCNotification *notifyCode) { switch (notifyCode->nmhdr.code) { case NPPN_SHUTDOWN: { commandMenuCleanUp(); } break; default: return; } } extern "C" __declspec(dllexport) LRESULT messageProc(UINT /*Message*/, WPARAM /*wParam*/, LPARAM /*lParam*/) { return TRUE; } #ifdef UNICODE extern "C" __declspec(dllexport) BOOL isUnicode() { return TRUE; } #endif //UNICODE

    4 pluginInit函数更改如下

    void pluginInit(HANDLE hModule) { commandMenuInit(); }

    转载请注明原文地址: https://ju.6miu.com/read-971667.html

    最新回复(0)