Hey,
I'm intented to write a simple tool for making some of my taksks easier :). Therefore I need to get the content of the file im actually editing in Npp. So far, everything works... I'm able to find the correct handle etc. but unfortunately, the Npp "textbox" doesnt behave like a normal windows editbox. If I try to read the text, I only get garbage in my destination string. If there's only 1 letter in the Npp window, it is captured correctly but if there are more, something goes wrong and I get "????...". Strangely Spy++ shows the correct string but in my external application it seems to be handled in a different way.
I tried it with VisualBasic 6.0 and C (Codeblocks). The function itself works since its able to to read other text boxes
Does Npp (I'm using the ANSI version) use any special format for the box or does anyone have an idea how to fix this?
Thanks in advance! :).
Best regards,
André
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hmm, thanks for your answer... found SCI_GETCHARAT there. It works, if I read the content byte-by-byte using that command but that CANT be the solution. Especially as there is no equivalent for adding text to the npp window.
Any other ideas?
Best regards,
André
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Also please note that the text you get from Scintilla can be:
1) ANSI (one byte per character)
2) UTF-8 (from one to three bytes per character)
3) DBSC (two bytes per character? - actually, I don't know much about these encodings)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
At first, SCI_GETTEXT doesnt work for me. It doesnt do anything (leaves the initialized string unchanged).
If I use WM_GETTEXT instead, I get for the string "ttttt" written in npp (while reading out 20 characters - so enough:
3f 3f 74 0
? ? t
The t is the only *true* character, everything else is simply garbage.
hard to do anything wrong there:
char p[80] = "a";
SendMessageA(hwndx, WM_GETTEXT, 20, p);
printf("\n%s\n\n", p);
The problem seems to be, that WM_gettext tries to read unicode characters even if they are not there and throws away garbage (while I need it...). Im really wondering how Spy++ reads the data :(
Thank you
Best regards,
André
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
???
Here is a part of oficial documentation of Scintilla:
>>>>
SCI_GETTEXT(int length, char *text)
This returns length-1 characters of text from the start of the document plus one terminating 0 character. To collect all the text in a document, use SCI_GETLENGTH to get the number of characters in the document (nLen), allocate a character buffer of length nLen+1 bytes, then call SCI_GETTEXT(nLen+1, char *text). If the text argument is 0 then the length that should be allocated to store the entire document is returned. If you then save the text, you should use SCI_SETSAVEPOINT to mark the text as unmodified.
<<<<
So, to get some text, you must do something similar to the following:
const int BUF_SIZE = 1024; // for example
char szText[BUF_SIZE];
SendMessage(hScintillaWnd, SCI_GETTEXT, BUF_SIZE, (LPARAM) szText);
Now, the text inside the szText buffer can be ANSI, UTF-8 or DBSC depending on current Scintilla's editing window's encoding (code page). You can get this encoding (code page) from the same hScintillaWnd using the SCI_GETCODEPAGE message.
I recommend you to download latest sources of Notepad++. You'll find a subfolder "scintilla" there, and this subfolder contains a subfolder "doc" with a file "ScintillaDoc.html". And I HIGHLY recommend you to read this "ScintillaDoc.html" because it contains all the information you need. Also, you may be interested in source files "UniConversion.cpp/h" (in the "PowerEditor\src" subfolder) which have functions for such text transformation as ANSI<->UTF8, UTF8<->UCS2 (UCS2 is Windows'es WideChar Unicode) and so on.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am trying to achieve the same thing i.e
**send current windows text to a richEdit20A or Edit control of notepad**
So sending text using **SendMessage** is working but as with André I too am getting ???? 's or non English characters. I am working with notepad++ 5.4.5 UNICODE.
I have looked into encoding and SCI_GETCODEPAGE but as I am new to this I haven't succeeded getting a result.
If anyone knows how to capture english text in notepad++ and send it to RichEdit20A AS plain English please help !!!
Appreciate your anticipated response,
Thanks,
ohme
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
As an example, you can download sources of the plugin NppExec ver. 0.3.2. In the file "NppExec.cpp", there is a function "CNppExec::selSaveTo" which reads the selected text from Notepad++ and saves it into desired file with desired encoding (ANSI, UTF-8 or UCS-2 LE). The code which actually reads the text starts from the line "HWND hSci = ScintillaHandle();". The following variable "pSciText" will contain the selected text from Scintilla, and the variable "pOutText" will contain the same text converted to desired encoding.
Also you may be interested in function "CNppExec::selSetText" which sets (or replaces) the selected text in Notepad++.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for replying. I have downloaded the plugin source and will check the function right away. But as I mentioned that I am able to send the complete text of current window to the richEdit20A control of my other application using sendMessage() & WM_SETTEXT but I just receive **????'s** or **little boxes** with a correct last character.
So when I open notepad++, by default, under "**Format menu**" "**Encode in ANSI**" is selected. So doest this mean whatever I type in the current window is in ANSI encoding? And what encoding does controls like Notepad's **Edit** or **RichEdit20A** want the text in??
I am on Win XP, SP3 using notepad++ 5.4.5(Unicode).
Thanks a lot for guiding,
ohme
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
ok now when I used that function you told me about and as soon as I #include "encodings/SysUniConv.h"
I strat getting this error
**1>C:\Program Files\Microsoft Visual Studio 9.0\VC\include\TCHAR.h(797) : error C3861: 'wcstok_s': identifier not found**
any idea what must be the reason?
Thanks,
ohme
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hey,
I'm intented to write a simple tool for making some of my taksks easier :). Therefore I need to get the content of the file im actually editing in Npp. So far, everything works... I'm able to find the correct handle etc. but unfortunately, the Npp "textbox" doesnt behave like a normal windows editbox. If I try to read the text, I only get garbage in my destination string. If there's only 1 letter in the Npp window, it is captured correctly but if there are more, something goes wrong and I get "????...". Strangely Spy++ shows the correct string but in my external application it seems to be handled in a different way.
I tried it with VisualBasic 6.0 and C (Codeblocks). The function itself works since its able to to read other text boxes
Does Npp (I'm using the ANSI version) use any special format for the box or does anyone have an idea how to fix this?
Thanks in advance! :).
Best regards,
André
http://www.scintilla.org/ScintillaDoc.html
Hmm, thanks for your answer... found SCI_GETCHARAT there. It works, if I read the content byte-by-byte using that command but that CANT be the solution. Especially as there is no equivalent for adding text to the npp window.
Any other ideas?
Best regards,
André
Get: SCI_GETTEXTRANGE
Add: SCI_INSERTTEXT
Del: SCI_REPLACETARGET
http://www.scintilla.org/ScintillaDoc.html#TextRetrievalAndModification
Also please note that the text you get from Scintilla can be:
1) ANSI (one byte per character)
2) UTF-8 (from one to three bytes per character)
3) DBSC (two bytes per character? - actually, I don't know much about these encodings)
I think thats one of my problems...
At first, SCI_GETTEXT doesnt work for me. It doesnt do anything (leaves the initialized string unchanged).
If I use WM_GETTEXT instead, I get for the string "ttttt" written in npp (while reading out 20 characters - so enough:
3f 3f 74 0
? ? t
The t is the only *true* character, everything else is simply garbage.
hard to do anything wrong there:
char p[80] = "a";
SendMessageA(hwndx, WM_GETTEXT, 20, p);
printf("\n%s\n\n", p);
The problem seems to be, that WM_gettext tries to read unicode characters even if they are not there and throws away garbage (while I need it...). Im really wondering how Spy++ reads the data :(
Thank you
Best regards,
André
???
Here is a part of oficial documentation of Scintilla:
>>>>
SCI_GETTEXT(int length, char *text)
This returns length-1 characters of text from the start of the document plus one terminating 0 character. To collect all the text in a document, use SCI_GETLENGTH to get the number of characters in the document (nLen), allocate a character buffer of length nLen+1 bytes, then call SCI_GETTEXT(nLen+1, char *text). If the text argument is 0 then the length that should be allocated to store the entire document is returned. If you then save the text, you should use SCI_SETSAVEPOINT to mark the text as unmodified.
<<<<
So, to get some text, you must do something similar to the following:
const int BUF_SIZE = 1024; // for example
char szText[BUF_SIZE];
SendMessage(hScintillaWnd, SCI_GETTEXT, BUF_SIZE, (LPARAM) szText);
Now, the text inside the szText buffer can be ANSI, UTF-8 or DBSC depending on current Scintilla's editing window's encoding (code page). You can get this encoding (code page) from the same hScintillaWnd using the SCI_GETCODEPAGE message.
I recommend you to download latest sources of Notepad++. You'll find a subfolder "scintilla" there, and this subfolder contains a subfolder "doc" with a file "ScintillaDoc.html". And I HIGHLY recommend you to read this "ScintillaDoc.html" because it contains all the information you need. Also, you may be interested in source files "UniConversion.cpp/h" (in the "PowerEditor\src" subfolder) which have functions for such text transformation as ANSI<->UTF8, UTF8<->UCS2 (UCS2 is Windows'es WideChar Unicode) and so on.
HI there,
I am trying to achieve the same thing i.e
**send current windows text to a richEdit20A or Edit control of notepad**
So sending text using **SendMessage** is working but as with André I too am getting ???? 's or non English characters. I am working with notepad++ 5.4.5 UNICODE.
I have looked into encoding and SCI_GETCODEPAGE but as I am new to this I haven't succeeded getting a result.
If anyone knows how to capture english text in notepad++ and send it to RichEdit20A AS plain English please help !!!
Appreciate your anticipated response,
Thanks,
ohme
As an example, you can download sources of the plugin NppExec ver. 0.3.2. In the file "NppExec.cpp", there is a function "CNppExec::selSaveTo" which reads the selected text from Notepad++ and saves it into desired file with desired encoding (ANSI, UTF-8 or UCS-2 LE). The code which actually reads the text starts from the line "HWND hSci = ScintillaHandle();". The following variable "pSciText" will contain the selected text from Scintilla, and the variable "pOutText" will contain the same text converted to desired encoding.
Also you may be interested in function "CNppExec::selSetText" which sets (or replaces) the selected text in Notepad++.
HI dv,
Thanks for replying. I have downloaded the plugin source and will check the function right away. But as I mentioned that I am able to send the complete text of current window to the richEdit20A control of my other application using sendMessage() & WM_SETTEXT but I just receive **????'s** or **little boxes** with a correct last character.
So when I open notepad++, by default, under "**Format menu**" "**Encode in ANSI**" is selected. So doest this mean whatever I type in the current window is in ANSI encoding? And what encoding does controls like Notepad's **Edit** or **RichEdit20A** want the text in??
I am on Win XP, SP3 using notepad++ 5.4.5(Unicode).
Thanks a lot for guiding,
ohme
ok now when I used that function you told me about and as soon as I #include "encodings/SysUniConv.h"
I strat getting this error
**1>C:\Program Files\Microsoft Visual Studio 9.0\VC\include\TCHAR.h(797) : error C3861: 'wcstok_s': identifier not found**
any idea what must be the reason?
Thanks,
ohme