If someone could tell me how to make my VB application send a certain string to other application's textbox i would be glad. Email me or explain here.
Thx.
Printable View
If someone could tell me how to make my VB application send a certain string to other application's textbox i would be glad. Email me or explain here.
Thx.
1st of all i hope u no whats HWND and how to get it from windows.
use HWND in
Call SendMessageByString(HWND%,WM_SETTEXT,0&,"YourString")
this will let u set the text or captions on a window including certain labels or textboxes
good luck
if you wrote both programs you can use DDE.
Yes, i no HWND and yet, SendMessageByString is not SendMessage and so how does one declare it?
Public Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As String) As Long
(Just like SendMessage except lParam is String instead of Any)
because you need to use the textboxes hwnd not the forms hwnd.
I can never get this api to work for me (I've tried to use in the past) but my string always comes out in gibberish and only 3 characters long in the textbox, any ideas what I am doing wrong?.
try excluiding iParam in sendmessage by replacing it to ByVal Clng(1)
btw How to get textbox HWND then?
[Edited by merlinkk on 07-23-2000 at 11:55 PM]
I don't know how to get a textboxes hwnd from the forms hwnd, but there is probably an api call to enum all controls or something similar just don't know of one, if it is your own textbox on another form then just use form2.text8.hwnd or something like that but on another program I don't have a clue
but http://forums.vb-world.net/showthrea...threadid=23015 has an api call (look at the code posted by dennis) that can get the hwnd of the object the mouse is currently over, don't know if that will be any help though.
hm... not exactly what i need...
There must be a way to get controls' handles...
If u know - pleez help
Thx
How do you use DDE
cant really help wit DDE, just need a way to get controls' handle independantly of mouse etc.
....deep in working on dis problem.....
ps Dis post is a hit - so many peeps look here but so few reply. Is it really so hard to get those handles? =)
If you have the Handle of the window then you can find the handle of a text box or any control on that window by using the API call FindWindowEx. Send Edit as the child class.
It will be something like this:
hWndChild = FindWindowEx(hWnd, CLng(0), "Edit", clng(0))
Try it and let me know how it goes. You may also want to try using RichEdit in case the text box is a rich one.
you could do it using the enum child api, but you will need to know something about the content of the textbox to really find the correct textboxes api as the enum child api returns all the hwnds of the controls on that program
Code:'In a modules
Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim ChildsText As String
ChildsText = Space$(GetWindowTextLength(hwnd) + 1)
GetWindowText hwnd, ChildsText, Len(ChildsText)
ChildsText = Left$(ChildsText, Len(ChildsText) - 1)
If ChildsText = "Text1" Then Form1.Text2.Text = hwnd
EnumChildProc = 1
End Function
'Replace If ChildsText = "Text1" Then Form1.Text2.Text = hwnd with what ever you want to, get the right hwnd
'to call on it in your form use like so:
EnumChildWindows Form1.hwnd, AddressOf EnumChildProc, ByVal 0&
'all you need to do is replace form1.hwnd with the hwnd of the program with the textbox you want to use.
FindWindowEx works! But the only thing i know about class names is class name for command buttons. Whats the one for
textboxes?
Thx IrishJoker.
The textbox class name is 'Edit'.
They are called this because windows is written in C.
And in C they are call edit boxes.
So there you go, I hope it works for you.
If anyone knows how to retrieve data from an edit box on another app, can you please let me know. I can't get GetWindowText to work.
Cheers
IJ
Everything works for me now, thx esp. IrishJoker
Im trying to get retrieve info work, ill tell if ill
succeed.
One more problem:
Now i can send a string to textbox, but i need to send a
keystroke - ENTER, after it... Is there a way to do it?
Im sure there is =) Help if u can
Thx
trying sending chr(13) or chr(13) + chr(10)
or if sendmessage api allows it send vbcrlf
nah i dont think the chr(13) press is detected thru the textbox.
if theres is a button which u can activate this..
try the codes...
Dim X%
X=NuttonHwnd
Call PostMessage(X, WM_LBUTTONDOWN, 0, 0)
Call PostMessage(X, WM_LBUTTONUP, 0, 0)
to click the button
if that doesnt werk...
try again pressin enter on the textbox [i doubt it will werk]
WM_CHAR=258
Sub SendCharNum(A%, B As Byte)
Call SendMessageByNum(A, WM_CHAR, B, 0)
End Sub
and use ...
SendCharNum([theTextHWnd],13)
good luck... and let me no what happens
[Edited by CLoudX on 07-26-2000 at 09:06 PM]
so IS there a button u can press?
No, there r no buttons.
U can use SendKeys(key$) to send keystrokes to an active
window - theres a solution, at least one of them.
IrishJoker, u can use
Call Sendmessage(hwnd,WM_GETTEXT,iParam, byval info)
to retrieve info from control if u know its hWnd, though i didnt relly tested dis method
Anyone knows how to make an app intercept all input from keyboard even if aother app is in focus?
Thx
First of all..Quote:
Originally posted by merlinkk
No, there r no buttons.
U can use SendKeys(key$) to send keystrokes to an active
window - theres a solution, at least one of them.
IrishJoker, u can use
Call Sendmessage(hwnd,WM_GETTEXT,iParam, byval info)
to retrieve info from control if u know its hWnd, though i didnt relly tested dis method
Anyone knows how to make an app intercept all input from keyboard even if aother app is in focus?
Thx
in retrieving text you want to do it a little more like this:
temp$=spc(255)
textlength=SendMessage(hWnd,WM_GETTEXT,255,temp$)
temp$=left$(temp$,textlength)
Sendmessage returns the length of the text in this case and the 255 in the wParam of Sendmessage indicates the maximum length.
Secondly..one of the easier ways to send the enter key besides SendKeys is:
Declare SendMessageByNum ... alias "SendMessage" (byval...,
byval lParam as long) as long
SendMessageByNum (hWnd,WM_CHAR,13,0)
IF this isnt quite right move 13 to the lparam..Im a little tired right now so I cant remember off the top of my head.
Lastly, Keyboard hooks are a trick..you'll be using WindowProc and SetWindowsHookEx and they require you to have a DLL file which you will have to write yourself most likely even for a global keyboard hook. That info should get you pointed in the right direction.
Stop telling people to use DDE.
td.
Er...td...I think that's the first and only post where I've said to use DDE. Anyway - I didn't tell him to...I suggested it as a possibility :(