Notepad++ plugin(插件)开发之消息HOOK (文件保存,文件打开,文件关闭)

Notepad++ plugin(插件)开发之消息HOOK (文件保存,文件打开,文件关闭)

Notepad++ 插件 开发(上一篇关于 notepad++ plugin(插件开发)的文章)

(找了比较久才发现,记录一下 IS2120#CSDN )
http://blog.csdn.net/is2120/article/details/7190482
1. 在notepad++提供了一些hook消息,能够 用于通知plugin一些消息,诸如
文件的打开,文件的保存等

2. 如何利用这些消息(使用c++开发)
在开发plugin时会有一些必须的函数。其中之一是
typedef void (__cdecl * PBENOTIFIED)(SCNotification *);
void __cdeclbeNotified(struct SCNotification *notifyCode);
这个函数在编辑文件的时候总是会被调用。
http://blog.csdn.net/is2120/article/details/7190482
可以在这个函数里获取这些通知消息,完成自己想做的事情。

http://blog.csdn.net/is2120/article/details/7190482

//z 2012-6-6 10:25:22 AM is2120@csdn
3. 文件的打开 (NPPN_FILEOPENED)
这个消息只能提示你一个文件打开了,但是不能告知你文件是否载入好了。
可以通过使用 NPPN_BUFFERACTIVATED 来提示文件文件已经载入,但是这个与FILEOPENED并不一样。
NPPN_FILEOPENED sends a BufferID which a plugin should
transparently use to retrieve information about a file, but not its contents.

//z 2012-1-10 11:21 AM IS2120@CSDN
详细信息如下:
// Notification code
#define NPPN_FIRST 1000
    #define NPPN_READY (NPPN_FIRST + 1// To notify plugins that all the procedures of launchment of notepad++ are done.
    //scnNotification->nmhdr.code = NPPN_READY;
    //scnNotification->nmhdr.hwndFrom = hwndNpp;
    //scnNotification->nmhdr.idFrom = 0;

    #define NPPN_TBMODIFICATION (NPPN_FIRST + 2// To notify plugins that toolbar icons can be registered
    //scnNotification->nmhdr.code = NPPN_TB_MODIFICATION;
    //scnNotification->nmhdr.hwndFrom = hwndNpp;
    //scnNotification->nmhdr.idFrom = 0;

    #define NPPN_FILEBEFORECLOSE (NPPN_FIRST + 3// To notify plugins that the current file is about to be closed
    //scnNotification->nmhdr.code = NPPN_FILEBEFORECLOSE;
    //scnNotification->nmhdr.hwndFrom = hwndNpp;
    //scnNotification->nmhdr.idFrom = BufferID;

    #define NPPN_FILEOPENED (NPPN_FIRST + 4// To notify plugins that the current file is just opened
    //scnNotification->nmhdr.code = NPPN_FILEOPENED;
    //scnNotification->nmhdr.hwndFrom = hwndNpp;
    //scnNotification->nmhdr.idFrom = BufferID;

    #define NPPN_FILECLOSED (NPPN_FIRST + 5// To notify plugins that the current file is just closed
    //scnNotification->nmhdr.code = NPPN_FILECLOSED;
    //scnNotification->nmhdr.hwndFrom = hwndNpp;
    //scnNotification->nmhdr.idFrom = BufferID;

    #define NPPN_FILEBEFOREOPEN (NPPN_FIRST + 6// To notify plugins that the current file is about to be opened
    //scnNotification->nmhdr.code = NPPN_FILEBEFOREOPEN;
    //scnNotification->nmhdr.hwndFrom = hwndNpp;
    //scnNotification->nmhdr.idFrom = BufferID;
    
    #define NPPN_FILEBEFORESAVE (NPPN_FIRST + 7// To notify plugins that the current file is about to be saved
    //scnNotification->nmhdr.code = NPPN_FILEBEFOREOPEN;
    //scnNotification->nmhdr.hwndFrom = hwndNpp;
    //scnNotification->nmhdr.idFrom = BufferID;
    
    #define NPPN_FILESAVED (NPPN_FIRST + 8// To notify plugins that the current file is just saved
    //scnNotification->nmhdr.code = NPPN_FILESAVED;
    //scnNotification->nmhdr.hwndFrom = hwndNpp;
    //scnNotification->nmhdr.idFrom = BufferID;

    #define NPPN_SHUTDOWN (NPPN_FIRST + 9// To notify plugins that Notepad++ is about to be shutdowned.
    //scnNotification->nmhdr.code = NPPN_SHUTDOWN;
    //scnNotification->nmhdr.hwndFrom = hwndNpp;
    //scnNotification->nmhdr.idFrom = 0;

    #define NPPN_BUFFERACTIVATED (NPPN_FIRST + 10// To notify plugins that a buffer was activated (put to foreground).
    //scnNotification->nmhdr.code = NPPN_BUFFERACTIVATED;
    //scnNotification->nmhdr.hwndFrom = hwndNpp;
    //scnNotification->nmhdr.idFrom = activatedBufferID;

    #define NPPN_LANGCHANGED (NPPN_FIRST + 11// To notify plugins that the language in the current doc is just changed.
    //scnNotification->nmhdr.code = NPPN_LANGCHANGED;
    //scnNotification->nmhdr.hwndFrom = hwndNpp;
    //scnNotification->nmhdr.idFrom = currentBufferID;

    #define NPPN_WORDSTYLESUPDATED (NPPN_FIRST + 12// To notify plugins that user initiated a WordStyleDlg change.
    //scnNotification->nmhdr.code = NPPN_WORDSTYLESUPDATED;
    //scnNotification->nmhdr.hwndFrom = hwndNpp;
    //scnNotification->nmhdr.idFrom = currentBufferID;

    #define NPPN_SHORTCUTREMAPPED (NPPN_FIRST + 13// To notify plugins that plugin command shortcut is remapped.
    //scnNotification->nmhdr.code = NPPN_SHORTCUTSREMAPPED;
    //scnNotification->nmhdr.hwndFrom = ShortcutKeyStructurePointer;
    //scnNotification->nmhdr.idFrom = cmdID;
        //where ShortcutKeyStructurePointer is pointer of struct ShortcutKey:
        //struct ShortcutKey {
        //  bool _isCtrl;
        //  bool _isAlt;
        //  bool _isShift;
        //  UCHAR _key;
        //};

    #define NPPN_FILEBEFORELOAD (NPPN_FIRST + 14// To notify plugins that the current file is about to be loaded
    //scnNotification->nmhdr.code = NPPN_FILEBEFOREOPEN;
    //scnNotification->nmhdr.hwndFrom = hwndNpp;
    //scnNotification->nmhdr.idFrom = NULL;

    #define NPPN_FILELOADFAILED (NPPN_FIRST + 15)  // To notify plugins that file open operation failed
    //scnNotification->nmhdr.code = NPPN_FILEOPENFAILED;
    //scnNotification->nmhdr.hwndFrom = hwndNpp;
    //scnNotification->nmhdr.idFrom = BufferID;

    #define NPPN_READONLYCHANGED (NPPN_FIRST + 16)  // To notify plugins that current document change the readonly status,
    //scnNotification->nmhdr.code = NPPN_READONLYCHANGED;
    //scnNotification->nmhdr.hwndFrom = bufferID;
    //scnNotification->nmhdr.idFrom = docStatus;
        // where bufferID is BufferID
        //       docStatus can be combined by DOCSTAUS_READONLY and DOCSTAUS_BUFFERDIRTY

        #define DOCSTAUS_READONLY 1
        #define DOCSTAUS_BUFFERDIRTY 2

    #define NPPN_DOCORDERCHANGED (NPPN_FIRST + 16)  // To notify plugins that document order is changed
    //scnNotification->nmhdr.code = NPPN_DOCORDERCHANGED;
    //scnNotification->nmhdr.hwndFrom = newIndex;
    //scnNotification->nmhdr.idFrom = BufferID;

#endif

/z 2012-1-10 11:21 AM IS2120@CSDN

http://blog.csdn.net/is2120/article/details/7190482
posted @ 2012-01-10 12:30  BiG5  阅读(402)  评论(0编辑  收藏  举报