;Demo Plugin for Notepad++ (Npp) in PureBasic 4.20 - rev 2 (ANSI) ;---------------------------------------------------------------- ;By Carlo Somigliana, email: somic@libero.it or somic@semelinanno.com, website: www.semelinanno.com ;This Demo is released FREE (with no warranty. use at yourown risk) to the PB community with the intent ;that more Npp plugins will be developed and added to the Npp collection and support Free Software. ; ;Notepad++ is an award winning Open Source (Free) Text Editor written by Don with many features and Plugins ;it uses the same Scintilla component of the PB editor. ; ;see the Notepadd++ & Scintilla web sites for all the details related to the development. ; Notepad++ homepage at http://notepad-plus.sourceforge.net/uk/site.htm ; Scintilla homepage at http://www.scintilla.org/ ;Note: This code in Delphi 2.0 compiled 30 kb of dll, see the size of compiling this code in PB. ;History: ;-------- ;rev 0: first issue ;rev 1: ANSI version ;rev 2: changed from *NotePadPlusData (wrong) to @*NotePadPlusData (right) in setInfo() ;PERSONAL NOTES: ;---------------- ;I developed too a Npp plugin that uses my calculation library aNuMet.dll (Array of Numerical Methods) ;Download it at: http://www.semelinanno.com/downloads/anmxnpp/ver0010/anmXNpp_v0010.zip ;It transforms Npp (and other editors as soon as I've time to develop the plugins) in a powerfull ;expression evaluator, simple to use and with many functions for numbers and matrices. ; ;The Npp plugin name is anmXNpp.dll (Array of Numerical Methods for Notepad++) that works as an ;interface with an executable called anmEval.exe that actually uses the aNuMet.dll library. ;Why this? ;For four reasons : ; 1st to keep the plugin small and simple; ; 2nd to make the set more editor indipendent. ; 3rd to let the set (exe + dll) work without plugin for those editors with script capabilities ; 4th the plugin and the executable are free, while the aNuMet.dll SHAREWARE (with some limitations). ;Even If I'm conisdering the alternative to release aNuMet.dll free without limitations and wait for donations ;(you are free to let me know your opinion on this matter). ;This is my first trial to get some money from a software. If I'll ever succeed, I'll share an amount for the ;PB development. ; ;Last note: Visit my site www.semelinanno.com for more info and some more programs. ;Feel free to send me comments and suggestions (don't worry, I'a nice person) EnableExplicit Structure NppData ;12 bytes *nppHnd *sciMainHnd *sciScndHnd EndStructure Structure FuncItem itemName.character[64] ;more stable in ANSI ;itemName.s{64} *pFunc cmdID.l init2Check.l *PShKey EndStructure #DLLName = "Npp_PBan" Global LocalNppData.NppData Global Dim FI.FuncItem(1); {2 submenu: MyProc1 e MyProc2 in menu' "My PB PlugIn"} Global Result$ Global ShowF.b;Show Messsages Flag ProcedureC.l MyProc1() Protected st.s st = "_nppHandle: " + Hex(LocalNppData\nppHnd) + Chr(13) + Chr(10); st = st + "_scintillaMainHandle: " + Hex(LocalNppData\sciMainHnd) + Chr(13) + Chr(10); st = st + "_scintillaSecndHandle: " + Hex(LocalNppData\sciScndHnd) + Chr(13) + Chr(10); MessageRequester(#DLLName, "Menu MyProc 1:" + #CRLF$ + st); EndProcedure; ProcedureC.l MyProc2() MessageRequester(#DLLName, "Menu MyProc 2: Hello World!"); EndProcedure; ProcedureDLL.l AttachProcess(Instance.l) Protected st.s ShowF = 1; set to 0 if no Show Messages If ShowF : MessageRequester(#DLLName, "Begin AttachProcess: " + Str(Instance)) : EndIf ZeroMemory_(@FI(0), SizeOf(FuncItem)) ; /// if itemName.character[64] ; lstrcpyn_(@FI(0)\itemName[0], "MyProc1", sizeof("MyProc1")) ; alternative way st = "MyProc1" + Chr(0) ;null terminated string lstrcpy_(@FI(0)\itemName[0], st) ; /// if itemName.s[64] ; FI(0)\itemName = "MyProc1" FI(0)\pFunc = @MyProc1() FI(0)\init2Check = 0; FI(0)\PShKey = #Null; ZeroMemory_(@FI(1), SizeOf(FuncItem)) ; /// if itemName.character[64] st = "MyProc2" + Chr(0) lstrcpy_(@FI(1)\itemName[0], st) ; FI(1)\itemName = "MyProc2" FI(1)\pFunc = @MyProc2() FI(1)\init2Check = 0; FI(1)\PShKey = #Null If ShowF : MessageRequester(#DLLName, "End AttachProcess: " + Str(Instance)) : EndIf ProcedureReturn #True EndProcedure ProcedureDLL DetachProcess(Instance.l) If ShowF : MessageRequester(#DLLName, "DetachProcess: " + Str(Instance) ) : EndIf EndProcedure ProcedureDLL AttachThread(Instance.l) MessageBeep_(0); EndProcedure ProcedureDLL DetachThread(Instance.l) MessageBeep_(0); EndProcedure ;1a procedure called after AttachProcess() ProcedureCDLL setInfo(*NotePadPlusData); get struct nppdata from Npp Protected st.s If ShowF : st = "Proc setInfo: @*NotePadPlusData from Npp: " + Str(@*NotePadPlusData) MessageRequester(#DLLName, st) EndIf CopyMemory(@*NotePadPlusData, @LocalNppData, SizeOf(nppData)) Delay(10); If ShowF : st = "Proc setInfo: LocalNppData\nppHnd: " + Str(LocalNppData\nppHnd) st = st + #CRLF$ + "copied: " + Str(SizeOf(nppData)) + " bytes" MessageRequester(#DLLName, st) EndIf EndProcedure; ; ; ;2a procedure called after AttachProcess() ProcedureCDLL.l getFuncsArray(*nFuncs) Protected st.s ;MessageRequester(#DLLName, "123") PokeL(*nFuncs, 2); st = "Proc getFuncsArray: *nFuncs from Npp: " + Str(*nFuncs) If ShowF : MessageRequester(#DLLName, st) : EndIf ProcedureReturn @FI(0);return address of menu array EndProcedure; ;3a procedure called after AttachProcess() ProcedureCDLL.l getName() Protected st.s st = "Proc getName: MenuName: My Test Plug-in" If ShowF : MessageRequester(#DLLName, st) : EndIf ProcedureReturn @"Npp PB Plugin";name of menu in Plugin menu of Npp EndProcedure; ;This Procedure is continuously called ProcedureCDLL.l beNotified() Protected ret.l, st.s If ShowF : st = "Proc " + #PB_Compiler_Procedure st = st + ": This Procedure is continuously called." + #CRLF$ st = st + "Press YES to stop this message to appear" ret = MessageRequester(#DLLName, st, #PB_MessageRequester_YesNo) If ret = #PB_MessageRequester_Yes ShowF = 0 EndIf EndIf EndProcedure; ;This Procedure is continuously called ProcedureCDLL.l messageProc(p1.l, p2.l, *p3) Protected ret.l, st.s If ShowF : st = "Proc " + #PB_Compiler_Procedure st = st + ": This Procedure is continuously called." + #CRLF$ st = st + "Press YES to stop this message to appear" ret = MessageRequester(#DLLName, st, #PB_MessageRequester_YesNo) If ret = #PB_MessageRequester_Yes ShowF = 0 EndIf EndIf ProcedureReturn 0 EndProcedure; ; IDE Options = PureBasic 4.30 (Windows - x86) ; ExecutableFormat = Shared Dll ; CursorPosition = 17 ; Folding = -- ; Executable = C:\Program Files\Notepad++\plugins\Npp_PBan.dll