|
-
Jul 19th, 2000, 03:10 PM
#1
Thread Starter
Junior Member
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.
-
Jul 22nd, 2000, 09:08 PM
#2
New Member
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
-
Jul 23rd, 2000, 06:05 AM
#3
Monday Morning Lunatic
if you wrote both programs you can use DDE.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jul 23rd, 2000, 01:31 PM
#4
Thread Starter
Junior Member
Yes, i no HWND and yet, SendMessageByString is not SendMessage and so how does one declare it?
-
Jul 23rd, 2000, 02:09 PM
#5
Fanatic Member
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)
-
Jul 23rd, 2000, 07:27 PM
#6
Addicted Member
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?.
-
Jul 23rd, 2000, 10:52 PM
#7
Thread Starter
Junior Member
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]
-The Shortest Anecdote: pkunzip.zip
-
Jul 24th, 2000, 08:00 AM
#8
Addicted Member
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.
-
Jul 24th, 2000, 02:16 PM
#9
Thread Starter
Junior Member
hm... not exactly what i need...
There must be a way to get controls' handles...
If u know - pleez help
Thx
-The Shortest Anecdote: pkunzip.zip
-
Jul 25th, 2000, 02:16 PM
#10
Frenzied Member
-
Jul 25th, 2000, 08:54 PM
#11
Thread Starter
Junior Member
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? =)
-The Shortest Anecdote: pkunzip.zip
-
Jul 26th, 2000, 03:33 AM
#12
Lively Member
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.
-
Jul 26th, 2000, 05:33 AM
#13
Addicted Member
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.
-
Jul 26th, 2000, 10:56 AM
#14
Thread Starter
Junior Member
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 Shortest Anecdote: pkunzip.zip
-
Jul 26th, 2000, 05:04 PM
#15
Lively Member
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
-
Jul 26th, 2000, 07:01 PM
#16
Thread Starter
Junior Member
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
-The Shortest Anecdote: pkunzip.zip
-
Jul 26th, 2000, 07:31 PM
#17
Addicted Member
trying sending chr(13) or chr(13) + chr(10)
or if sendmessage api allows it send vbcrlf
-
Jul 26th, 2000, 08:03 PM
#18
New Member
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]
-
Jul 27th, 2000, 02:44 PM
#19
New Member
so IS there a button u can press?
-
Jul 27th, 2000, 03:04 PM
#20
Thread Starter
Junior Member
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
-The Shortest Anecdote: pkunzip.zip
-
Nov 30th, 2000, 09:31 PM
#21
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
First of all..
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.
-
Dec 1st, 2000, 04:12 AM
#22
Hyperactive Member
Hey Parksie
Stop telling people to use DDE.
td.
"One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig
[email protected]
"but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.
-
Dec 1st, 2000, 01:27 PM
#23
Monday Morning Lunatic
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
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|