WM_GETTEXT WM_SENDTEXT - HELP ALL OF US UNDERSTAND THIS!!!

  • Thread starter Thread starter Internetdomainowner
  • Start date Start date
I

Internetdomainowner

Programmers,

I'm calling out an SOS... WM_GETTEXT or WM_SENDTEXT has to be most
unexplained thing on the internet. I have spent over 3 hours trying to
search for a newbies guide to using this santax in my programs but I
have been very unsuccesful -- I did however learn how to reveal a
saved password that is hidden with * but other then that...it's been
fruitless. Would someone please explain the basics of how to use this
code...

Please use the details below so that anyone else researching this can
figure it out...

WM_GETTEXT
----------------------
UserForm1 - TextBox1 is the textbox I want to get the value, using
WM_GETTEXT from a program. The program I want to pull the data from
has a Control ID (Shown as [Description] on the target program) of
"1249" (revealed from a program called HookSpy). I want to assume
that Control ID 1249, would be the same as if I was to say
UserForm1.TextBox1.

So how does someone go about extracting the data from Control ID 1249?

What is the correct code to use?
What variables do I need to change?
What type of module do I need to paste the code into?

WM_SENDTEXT
------------------------
Pretty much the complete opposite... Take the value of UserForm1 -
TextBox1 and send it to Control ID 1249.

If someone responds with an answer that actually works and I can gain
the ability to use this code -- I'm serious -- I will PayPal you cash
(USD) for your efforts / answers. This has to be one of the most
valuable pieces of code out there and yet it's the most unexplained...
I don't even know how anyone has ever learned how to use this
successfully.

Thank you in advance... I am looking forward to seeing what happens
with this post.

-Todd
 
Normally you'd send WM_GETTEXT (ie 13) as the "wMsg" argument in the
SendMessage API, which if you using VB/A would be declared like this -

Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd
As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

The big problem you've got though with Office Userform controls is that most
of them are windowless; or rather AFAIK you cannot get a window handle,
which is required as the first argument "hwnd".

The obvious question though is why can't you read the text directly from the
textbox property in the application and project that is running the
userform.

Regards,
Peter T
 
Normally you'd send WM_GETTEXT (ie 13) as the "wMsg" argument in the
SendMessage API, which if you using VB/A would be declared like this -

Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd
As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

The big problem you've got though with Office Userform controls is that most
of them are windowless; or rather AFAIK you cannot get a window handle,
which is required as the first argument "hwnd".

The obvious question though is why can't you read the text directly from the
textbox property in the application and project that is running the
userform.

Regards,
Peter T




Programmers,
   I'm calling out an SOS... WM_GETTEXT or WM_SENDTEXT has to be most
unexplained thing on the internet. I have spent over 3 hours trying to
search for a newbies guide to using this santax in my programs but I
have been very unsuccesful -- I did however learn how to reveal a
saved password that is hidden with * but other then that...it's been
fruitless. Would someone please explain the basics of how to use this
code...
Please use the details below so that anyone else researching this can
figure it out...
WM_GETTEXT
----------------------
UserForm1 - TextBox1 is the textbox I want to get the value, using
WM_GETTEXT from a program. The program I want to pull the data from
has a Control ID (Shown as [Description] on the target program) of
"1249"  (revealed from a program called HookSpy). I want to assume
that Control ID 1249, would be the same as if I was to say
UserForm1.TextBox1.
So how does someone go about extracting the data from Control ID 1249?
What is the correct code to use?
What variables do I need to change?
What type of module do I need to paste the code into?
WM_SENDTEXT
If someone responds with an answer that actually works and I can gain
the ability to use this code -- I'm serious -- I will PayPal you cash
(USD) for your efforts / answers. This has to be one of the most
valuable pieces of code out there and yet it's the most unexplained...
I don't even know how anyone has ever learned how to use this
successfully.
Thank you in advance... I am looking forward to seeing what happens
with this post.
-Todd- Hide quoted text -

- Show quoted text -

The point of learning this is all about automation... If the program
has selectable text I suppose I could write a script to tab to that
box and pull it... however I hate using sendkeys to do stuff like this
and sendkeys seems amature compaired to what the WM_GETTEXT and
WM_SENDTEXt is capable of. If I need to use a caption on a radio
button to send the text (from my VBA userform) to a specified area in
another program, I will do so...

Peter you seem to know more about this then what's going on... would
you please continue with what you were saying. Lets imagine that the
userform element (textbox1) isn't "AFAIK" ... how to do I send text to
that Control ID?
 
Normally you'd send WM_GETTEXT (ie 13) as the "wMsg" argument in the
SendMessage API, which if you using VB/A would be declared like this -

Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd
As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

The big problem you've got though with Office Userform controls is that most
of them are windowless; or rather AFAIK you cannot get a window handle,
which is required as the first argument "hwnd".

The obvious question though is why can't you read the text directly from the
textbox property in the application and project that is running the
userform.

Regards,
Peter T




Programmers,
I'm calling out an SOS... WM_GETTEXT or WM_SENDTEXT has to be most
unexplained thing on the internet. I have spent over 3 hours trying to
search for a newbies guide to using this santax in my programs but I
have been very unsuccesful -- I did however learn how to reveal a
saved password that is hidden with * but other then that...it's been
fruitless. Would someone please explain the basics of how to use this
code...
Please use the details below so that anyone else researching this can
figure it out...
WM_GETTEXT
----------------------
UserForm1 - TextBox1 is the textbox I want to get the value, using
WM_GETTEXT from a program. The program I want to pull the data from
has a Control ID (Shown as [Description] on the target program) of
"1249" (revealed from a program called HookSpy). I want to assume
that Control ID 1249, would be the same as if I was to say
UserForm1.TextBox1.
So how does someone go about extracting the data from Control ID 1249?
What is the correct code to use?
What variables do I need to change?
What type of module do I need to paste the code into?
WM_SENDTEXT
If someone responds with an answer that actually works and I can gain
the ability to use this code -- I'm serious -- I will PayPal you cash
(USD) for your efforts / answers. This has to be one of the most
valuable pieces of code out there and yet it's the most unexplained...
I don't even know how anyone has ever learned how to use this
successfully.
Thank you in advance... I am looking forward to seeing what happens
with this post.
-Todd- Hide quoted text -

- Show quoted text -

The point of learning this is all about automation... If the program
has selectable text I suppose I could write a script to tab to that
box and pull it... however I hate using sendkeys to do stuff like this
and sendkeys seems amature compaired to what the WM_GETTEXT and
WM_SENDTEXt is capable of. If I need to use a caption on a radio
button to send the text (from my VBA userform) to a specified area in
another program, I will do so...

Peter you seem to know more about this then what's going on... would
you please continue with what you were saying. Lets imagine that the
userform element (textbox1) isn't "AFAIK" ... how to do I send text to
that Control ID?

=================================

You say "this is all about automation" and "from my VBA userform" so why on
earth can't you get the text directly from the textbox's text property, eg

sTxt = Me.TextBox1.Text ' from within the form
sTxt = frm.TextBox1.Text ' from a reference to the form
sTxt = Userform1.TextBox1.Text w/out a ref but from elsewhere in the
project.

Perhaps I'm not following what you are doing.
" Lets imagine that the userform element (textbox1) isn't "AFAIK" "

Well it is "AFAIK" but I vaguely recall there is some cunning way to get it.
Perhaps you can see it in your HookSpy thing (I can't in "Spy"), what you
need is it's window handle, a number. If you can get that post back and I'll
try and put together what you'll need to use the SendMessage API just for
testing using VB/A (if that's not your language you'll need to adapt). Of
course eventually you'd need to be able to get the handle without using
HookSpy.

Regards,
Peter T
 
(e-mail address removed) schrieb im Beitrag
I'm calling out an SOS... WM_GETTEXT or WM_SENDTEXT has to be most
unexplained thing on the internet. I have spent over 3 hours trying to
search for a newbies guide to using this santax in my programs but I
have been very unsuccesful -- I did however learn how to reveal a
saved password that is hidden with * but other then that...it's been
fruitless. Would someone please explain the basics of how to use this
code...

Please use the details below so that anyone else researching this can
figure it out...

WM_GETTEXT
----------------------
UserForm1 - TextBox1 is the textbox I want to get the value, using
WM_GETTEXT from a program. The program I want to pull the data from
has a Control ID (Shown as [Description] on the target program) of
"1249" (revealed from a program called HookSpy). I want to assume
that Control ID 1249, would be the same as if I was to say
UserForm1.TextBox1.

I really don't understand what the problem is:
- For WM_GETTEXT and WM_SENDTEXT there is a documentation available in the
MSDN.
- You can't use WM_GETTEXT and WM_SENDTEXT with a control ID but only with
a Window handle unless you send these messages with SendDlgItemMessage();
but there you still have to provide the handle of the windows/dialog which
is the parent of the dialog control.

To explain to us where your problem actually is please show us some code.
 
I'm curious. What language are you using? If it's VB, is it 6.0 or
earlier, or .net?

I've worked with the Win32 API for some 12 years now and I've never seen
WM_SENDTEXT. I've worked with WM_SETTEXT, so maybe it's roughly the same
thing?

Either way, those kinds of messages are used in conjunction with
SendMessage, either declaring the lParam as String or Long, depending on
what you are sending, or declaring it AsAny and using ByVal in your actual
call. Very important to do this.

The SendMessage API relies on knowing the window handle (or hWnd) of the
actual control you want to get/set text with (not the some thing as a
control ID).

Typically, these kinds of API calls are only really needed between processes
and not within your own program as each control has its own properties for
getting and setting text, so assuming you are doing cross-task work, you
would need to obtain the actual hWnd for the program you want to communicate
with using the FindWindow API. Once you have this window handle, you can
use the FindWindowEx API to cycle through the various child window to find
the actual control you want to manipulate. To use the FindWindow APIs, you
will need to know the class names (and optionally the window title, although
it's not always available, in which case the class name would be sufficent).
The easiest way to obtain class names is to use Spy++ or equivalent.

A lot to take in, I know. It is considered faily advanced stuff. If you
could post a sample of the code you are attempting to use, it would be a lot
easier to help you out in terms of guidance and/or corrections.

- Kev

| Programmers,
|
| I'm calling out an SOS... WM_GETTEXT or WM_SENDTEXT has to be most
| unexplained thing on the internet. I have spent over 3 hours trying to
| search for a newbies guide to using this santax in my programs but I
| have been very unsuccesful -- I did however learn how to reveal a
| saved password that is hidden with * but other then that...it's been
| fruitless. Would someone please explain the basics of how to use this
| code...
|
| Please use the details below so that anyone else researching this can
| figure it out...
|
| WM_GETTEXT
| ----------------------
| UserForm1 - TextBox1 is the textbox I want to get the value, using
| WM_GETTEXT from a program. The program I want to pull the data from
| has a Control ID (Shown as [Description] on the target program) of
| "1249" (revealed from a program called HookSpy). I want to assume
| that Control ID 1249, would be the same as if I was to say
| UserForm1.TextBox1.
|
| So how does someone go about extracting the data from Control ID 1249?
|
| What is the correct code to use?
| What variables do I need to change?
| What type of module do I need to paste the code into?
|
| WM_SENDTEXT
| ------------------------
| Pretty much the complete opposite... Take the value of UserForm1 -
| TextBox1 and send it to Control ID 1249.
|
| If someone responds with an answer that actually works and I can gain
| the ability to use this code -- I'm serious -- I will PayPal you cash
| (USD) for your efforts / answers. This has to be one of the most
| valuable pieces of code out there and yet it's the most unexplained...
| I don't even know how anyone has ever learned how to use this
| successfully.
|
| Thank you in advance... I am looking forward to seeing what happens
| with this post.
|
| -Todd
 
First, try solving the problem using automation. The API approach can be
complicated sometimes. For example, try using this code(air code):

Userform1.TextBox1.SelText = "ABC"

Or:

' Clear selection
Userform1.TextBox1.SelText = ""

And:

Debug.Print Userform1.TextBox1.Text

Second, it seems that the hWnd is not exposed in Office automation, unlike
VB6 which exposes hWnd for its controls, so you have to find it using the
API if you want to use WM_GETTEXT and similar messages. Search the
newsgroups for "Userform hWnd", you will find multiple approaches, some one
line, and some are made from 50+ lines.

Third, the opposite of WM_GETTEXT is WM_SETTEXT. WM_SENDTEXT is not a
Windows message, I can't find it in MSDN. Also, if you are not using "Option
Explicit" at the beginning of the code, then all constants are treated as 0,
and this is equivalent to sending WM_NULL, which means that the message is
ignored, so make sure that you declare these constants if you want to use
the API approach, but I think that you can do what you using automation.
 
expvb said:
Second, it seems that the hWnd is not exposed in Office automation, unlike
VB6 which exposes hWnd for its controls, so you have to find it using the
API if you want to use WM_GETTEXT and similar messages. Search the
newsgroups for "Userform hWnd", you will find multiple approaches, some one
line, and some are made from 50+ lines.

As I mentioned in my other posts AFAIK the majority of built in Userform
controls are windowless and as such do not have an hWnd. IOW it's not just a
matter of the hwnd not being exposed in Office automation, it doesn't exist,
I assume.

It is easy with API's to get the hwnd of the Userform itself and that of the
form as a container (two hwnd's). The only built-in controls I know of that
do have a retrievable hwnd are Frame, Multipage & Listbox. However these all
have the same classname and no caption, so a bit of inference would also be
required.

You implied you had found some approaches, could you point to one of them,
eg to how to return the hwnd of a Userform textbox.

Regards,
Peter T
 
Peter T said:
As I mentioned in my other posts AFAIK the majority of built in Userform
controls are windowless and as such do not have an hWnd. IOW it's not just
a
matter of the hwnd not being exposed in Office automation, it doesn't
exist,
I assume.

It is easy with API's to get the hwnd of the Userform itself and that of
the
form as a container (two hwnd's). The only built-in controls I know of
that
do have a retrievable hwnd are Frame, Multipage & Listbox. However these
all
have the same classname and no caption, so a bit of inference would also
be
required.

You implied you had found some approaches, could you point to one of them,
eg to how to return the hwnd of a Userform textbox.

Regards,
Peter T

I didn't read your entire post, so I didn't know that the controls are
windowless in Office, at least in Excel 2002. Microsoft has a reputation for
bloating many things, so I assumed the controls have a hWnd. One way to work
with these is API hooking and detours, but it's too complicated and better
left to another thread. Another approach is using OCR, but this works with
the displayed portion in the control. In any case, these are complicated
solutions to a simple problem that is better done through automation.
 
Nobody can do that with a TextBox from the MSForms library, they are lightweight controls, not a window, this kind of "non-window" are painted, you only are able to send a message to a window using it's windows handle. This control is called lightweight because the system doesn't store any information about them, no handle, no control identifier, no styles, ...and so on. In your case, only the TextBox class knows how to set and retrieve it's properties like it's Text.

You see the HookSpy application revealing the contents of another type of control, like an Edit control, VB.TextBox, Access.TextBox, or another type of Edit control added to an ActiveX control embedded on a UserForm, but you will never see any application revealing the contents of an MSForms.TextBox, you can send a message to it's parent window, or you can send synthesized keystrokes 'to the air' when the parent window has the input focus, but you can't do what you are asking for.



--
Regards
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
( ! ) Preceding answers in Google:
http://groups.google.com/group/microsoft.public.vb.winapi
( i ) Temperance in the forum:
http://www.microsoft.com/communities/conduct/default.mspx
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top