-
could someone tell me how to manipulate another richtextbox that doesn't belong to my program (without using sendkeys)?
i.e. i know the hWnd of the "target" richtextbox (richedit), and i would like to change the target's properties such as .text etc...?
i presume it would be something like
Dim objTarget as TextBox
objTarget.hWnd = target.hWnd
objTarget.Text = "text..."
thanx.
-
You can access it directly, but you can use PostMessage and send the WM_CHAR message.
Code:
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_CHAR = &H102
Private Sub Command1_Click()
'Send the "A" key to the richtextbox.
PostMessage hWnd_RichEdit, WM_CHAR, vbKeyA, 0
End Sub
-
Or if you need to send strings longer than 1 char, you can send the WM_SETTEXT message.
Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_SETTEXT = &HC
Private Sub Command1_Click()
SendMessage hWnd_RichEdit, WM_SETTEXT, 0, ByVal "New String to be entered"
End Sub
-
thanx, could you tell me where i could get a list of all the
wMsg constants for different controls? i need to click a button.
thanx
-
The Window message constants can be found in your win32api.txt file somewhere in your vb directory. To click a foreign apps command button send a WM_LBUTTONDOWN and a WM_LBUTTONUP
-
You can get different messages by checking out the Platform SDK at msdn.microsoft.com, or www.allapi.net..
To click a button, send the BM_CLICK message.
Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const BM_CLICK = &H00F5
Private Sub Command1_Click()
SendMessage hWnd_Button, BM_CLICK, 0, 0
End Sub
-
Oh, I forgot to add: Usually messages are classified according to a specific prefix, for example:
BM = button message
EM = edit message
LVM = ListView message
WM = any window message
etc.
-
thanx ppl.
i've now been introduced into the world of the C++ spy and the API viewer thingy... :) (*Yay*, bout time too...) but just one more humble quesiton:
how do you know which message/constant to track/use?
when i had a little snoop with tracking the button there must have been at least a dozen which looked like the message i wanted to send... BM_Click etc...
thanx for helping.
-
err...
sorry forget that last posting...
just a classic case of me not reading the previous posts.