I'm confused on how NPPM_GETCURRENTSCINTILLA should work.
I've seen several samples, both in C++ and Delphi, but can't get it to work.
I'm using Delphi myself (the delphi example I saw was from zobo)
this function is quite similar to the sample I saw, fNPPHandle is the handle to Notepad++ (which you get in setInfo()).
I'm quite sure that handle is OK.
This function always returns 0 though.
function TNPPInterface.GetCurrentPrimaryScintillaHandle: hwnd;
var CurEdit: integer;
begin
SendMessage(fNPPHandle, NPPM_GETCURRENTSCINTILLA, 0, integer(@CurEdit));
result := CurEdit;
end;
tia
Merijn
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
--------
NPPM_GETCURRENTSCINTILLA
wParam : 0
lParam : [out] int * currentEdit
currentEdit indicates the current Scintilla view : 0 is the main Scintilla view 1 is the second Scintilla view.
--------
in your function, to return the handle of the current scintilla, you should do something like that :
ok, that clarifies, thanks
Other question then: if you have 2 files open in N++
are that two different scintilla instances?
In other words, can you look through the contents of one file, while you 'see' another file in N++?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
if (hSciBuffer == NULL)
{
/* create own parser buffer */
hSciBuffer = (HWND)::SendMessage(nppData._nppHandle, WM_CREATESCINTILLAHANDLE, 0, (LPARAM)hwnd);
}
/* get text of current scintilla and copy to buffer to hidden scintilla */
length = ::SendMessage(g_hSource, SCI_GETTEXTLENGTH, 0, 0)+1;
buffer = (char*)new char[length];
::SendMessage(g_hSource, SCI_GETTEXT, length, (LPARAM)buffer);
/* remove old content with a little UNDO and add the text */
::SendMessage(hSciBuffer, SCI_UNDO, 0, 0);
::SendMessage(hSciBuffer, SCI_ADDTEXT, length, (LPARAM)buffer);
delete [] buffer;
}
Best Regards
Jens
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
ok, but since this means getting the whole buffer into your plugin:
/* get text of current scintilla and copy to buffer to hidden scintilla */
length = ::SendMessage(g_hSource, SCI_GETTEXTLENGTH, 0, 0)+1;
buffer = (char*)new char[length];
::SendMessage(g_hSource, SCI_GETTEXT, length, (LPARAM)buffer);
what the advantage above just getting the whole buffer into your plugin and process it there?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I'm confused on how NPPM_GETCURRENTSCINTILLA should work.
I've seen several samples, both in C++ and Delphi, but can't get it to work.
I'm using Delphi myself (the delphi example I saw was from zobo)
this function is quite similar to the sample I saw, fNPPHandle is the handle to Notepad++ (which you get in setInfo()).
I'm quite sure that handle is OK.
This function always returns 0 though.
function TNPPInterface.GetCurrentPrimaryScintillaHandle: hwnd;
var CurEdit: integer;
begin
SendMessage(fNPPHandle, NPPM_GETCURRENTSCINTILLA, 0, integer(@CurEdit));
result := CurEdit;
end;
tia
Merijn
That message will return the "id" of the current scintilla (0 or 1), not its handle :
http://notepad-plus.sourceforge.net/uk/plugins-HOWTO.php
--------
NPPM_GETCURRENTSCINTILLA
wParam : 0
lParam : [out] int * currentEdit
currentEdit indicates the current Scintilla view : 0 is the main Scintilla view 1 is the second Scintilla view.
--------
in your function, to return the handle of the current scintilla, you should do something like that :
if(CurEdit=0) result:= scintillaMainHandle;
else result:= scintillaSecondHandle;
ok, that clarifies, thanks
Other question then: if you have 2 files open in N++
are that two different scintilla instances?
In other words, can you look through the contents of one file, while you 'see' another file in N++?
Hi,
this is not possible. But you can create a hidden scintilla in your plugin. Here you can access change the content and do what ever you want.
HWND hSciBuffer = NULL;
HWND g_hSource =nppData.MainHandle;
void copyBuffer()
{
char* buffer = NULL;
UINT length = 0;
if (hSciBuffer == NULL)
{
/* create own parser buffer */
hSciBuffer = (HWND)::SendMessage(nppData._nppHandle, WM_CREATESCINTILLAHANDLE, 0, (LPARAM)hwnd);
}
/* get text of current scintilla and copy to buffer to hidden scintilla */
length = ::SendMessage(g_hSource, SCI_GETTEXTLENGTH, 0, 0)+1;
buffer = (char*)new char[length];
::SendMessage(g_hSource, SCI_GETTEXT, length, (LPARAM)buffer);
/* remove old content with a little UNDO and add the text */
::SendMessage(hSciBuffer, SCI_UNDO, 0, 0);
::SendMessage(hSciBuffer, SCI_ADDTEXT, length, (LPARAM)buffer);
delete [] buffer;
}
Best Regards
Jens
ok, but since this means getting the whole buffer into your plugin:
/* get text of current scintilla and copy to buffer to hidden scintilla */
length = ::SendMessage(g_hSource, SCI_GETTEXTLENGTH, 0, 0)+1;
buffer = (char*)new char[length];
::SendMessage(g_hSource, SCI_GETTEXT, length, (LPARAM)buffer);
what the advantage above just getting the whole buffer into your plugin and process it there?