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

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Sabestian Caine
Posts: 420
Joined: 12 Apr 2015, 03:53

How to extract text from Notepad using SendMessage Command?

28 Oct 2018, 13:48

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...
I don't normally code as I don't code normally.
YOU do what YOU want, but happens what HE wants.
YOU do what HE wants, will happen what YOU want.
User avatar
Xtra
Posts: 1378
Joined: 02 Oct 2015, 12:15

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

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
User avatar
jballi
Posts: 568
Joined: 29 Sep 2013, 17:34

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

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.
User avatar
jeeswg
Posts: 6648
Joined: 19 Dec 2016, 01:58
Location: UK

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

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.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
Sabestian Caine
Posts: 420
Joined: 12 Apr 2015, 03:53

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

29 Oct 2018, 06:23

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....
I don't normally code as I don't code normally.
YOU do what YOU want, but happens what HE wants.
YOU do what HE wants, will happen what YOU want.
User avatar
Sabestian Caine
Posts: 420
Joined: 12 Apr 2015, 03:53

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

29 Oct 2018, 09:24

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...
I don't normally code as I don't code normally.
YOU do what YOU want, but happens what HE wants.
YOU do what HE wants, will happen what YOU want.
User avatar
Sabestian Caine
Posts: 420
Joined: 12 Apr 2015, 03:53

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

01 Nov 2018, 01:22

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...
I don't normally code as I don't code normally.
YOU do what YOU want, but happens what HE wants.
YOU do what HE wants, will happen what YOU want.

Return to “Ask For Help”

Who is online

Users browsing this forum: devnullsp, Google [Bot], kkleinfelter, sikongshan and 147 guests