Page 1 of 1

How to extract text from Notepad using SendMessage Command?

Posted: 28 Oct 2018, 13:48
by Sabestian Caine
Hello friends...

I am trying to learn SendMessage command. Suppose I want to retrieve any selected text in notepad. for example, please look at this screen shot-

Image

In the above image you can see that i have selected a text- "New Notepad Title" written in notepad window, now i ran these codes-

Code: Select all

f1::
SendMessage, 0x301, , , Edit1, Untitled - Notepad
MsgBox % Errorlevel
return
After running these codes a msgbox appears something like this-

Image


In the above msgbox you can see a number 34 is shown, while it should show the text- "New Notepad Title".
As I am using 0x301 in the above codes, which is, according to documentation, is the hex value of copy (WM_COPY = 0x301), so it should copy the selected text and should show that text in msgbox. I don't understand why it is showing 34 in msgbox?

I know the text can be retrieved very easily by using ControlGetText command in the present scenario, but I want to use SendMessage command only for learning purpose.


Please help me..

Thanks a lot...

Re: How to extract text from Notepad using SendMessage Command?

Posted: 28 Oct 2018, 14:59
by Xtra
SendMessage: ErrorLevel is set to the word FAIL if there was a problem or the command timed out. Otherwise, it is set to the numeric result of the message, which might sometimes be a "reply" depending on the nature of the message and its target window.
Did you try pasting after using it? If there was a problem ErrorLevel would = "Fail"

HTH

Re: How to extract text from Notepad using SendMessage Command?  Topic is solved

Posted: 28 Oct 2018, 15:01
by jballi
There is no return value for the WM_COPY message, so showing the value of Errorlevel is not correct. Some number is returned but I don't know what it is and officially, you're supposed to ignore it.

The WM_COPY message copies the selected text to the clipboard so to see the text, just show the value of the Clipboard variable. Something like this:

Code: Select all

MsgBox %Clipboard%
I hope this helps.

Re: How to extract text from Notepad using SendMessage Command?

Posted: 28 Oct 2018, 15:04
by jeeswg

Code: Select all

;replace:
MsgBox % ErrorLevel
;with:
MsgBox % Clipboard
Cheers.
[EDIT:] As jballi said, the ErrorLevel value (return value) should be ignored, although for Notepad it seems to correspond to the number of bytes put on the clipboard.

Re: How to extract text from Notepad using SendMessage Command?

Posted: 29 Oct 2018, 06:23
by Sabestian Caine
jballi wrote:
28 Oct 2018, 15:01
There is no return value for the WM_COPY message, so showing the value of Errorlevel is not correct. Some number is returned but I don't know what it is and officially, you're supposed to ignore it.

The WM_COPY message copies the selected text to the clipboard so to see the text, just show the value of the Clipboard variable. Something like this:

Code: Select all

MsgBox %Clipboard%
I hope this helps.


Thank you so much dear jballi ....

you are right I must use msgbox %clipboard% in stead of msgbox %ErrorLevel%

Thank You so much sir... So nice of you....

Re: How to extract text from Notepad using SendMessage Command?

Posted: 29 Oct 2018, 09:24
by Sabestian Caine
jeeswg wrote:
28 Oct 2018, 15:04

Code: Select all

;replace:
MsgBox % ErrorLevel
;with:
MsgBox % Clipboard
Cheers.
[EDIT:] As jballi said, the ErrorLevel value (return value) should be ignored, although for Notepad it seems to correspond to the number of bytes put on the clipboard.
Thanks a lot dear jeeswg ...

Now, i have replaced MsgBox % ErrorLevel to MsgBox % Clipboard and now it is showing the copied text in the msgbox... Thanks a lot sir...

Re: How to extract text from Notepad using SendMessage Command?

Posted: 01 Nov 2018, 01:22
by Sabestian Caine
Xtra wrote:
28 Oct 2018, 14:59
SendMessage: ErrorLevel is set to the word FAIL if there was a problem or the command timed out. Otherwise, it is set to the numeric result of the message, which might sometimes be a "reply" depending on the nature of the message and its target window.
Did you try pasting after using it? If there was a problem ErrorLevel would = "Fail"

HTH
Thank you so much dear Xtra for your kind reply ... problem is solved by the help of great expert people like you... Thanks a lot once again sir...