|
-
Aug 12th, 2005, 11:00 AM
#1
Thread Starter
Lively Member
Sending text
Hi guys. I have a form using API and can find a text box in another app, but I dont know how the code to send text to the textbox in the other app.
What is the code to send text to an external textbox?
Life is proof that God has a sick sence of humor.
-
Aug 12th, 2005, 11:58 AM
#2
Re: Sending text
 Originally Posted by Jackrabbit319
Hi guys. I have a form using API and can find a text box in another app, but I dont know how the code to send text to the textbox in the other app.
What is the code to send text to an external textbox?
This is how you would send some text to a notepade file
VB Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, _
ByVal lParam As Any) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, _
ByVal wCmd As Long) As Long
Private Const WM_SETTEXT = &HC
Private Const GW_CHILD = 5
Private Sub Command1_Click()
Dim hWnd1 As Long
Dim hWnd2 As Long
Dim sText As String
Clipboard.Clear
Clipboard.SetText Text1.Text
Shell "Notepad", vbNormalFocus
hWnd1 = FindWindow(vbNullString, "Untitled - Notepad")
hWnd2 = GetWindow(hWnd1, GW_CHILD)
sText = Clipboard.GetText
SendMessage hWnd2, WM_SETTEXT, Len(sText), sText
End Sub
So, following this logic, you would lose the references to Notepad, substitute hWnd2 with the handle of the textbox in the other application (which you say you already have), and that should work.
-
Aug 12th, 2005, 12:18 PM
#3
Thread Starter
Lively Member
Re: Sending text
Ok thanx I'll give it a try
Life is proof that God has a sick sence of humor.
-
Aug 12th, 2005, 12:35 PM
#4
Thread Starter
Lively Member
Re: Sending text
Ok I tried it but Im having trouble now with the API function.
Say I have a chat window open in MSN Messenger......here would be the code for the window :
VB Code:
Dim imwindowclass As Long, directuihwnd As Long
imwindowclass = FindWindow("imwindowclass", vbNullString)
directuihwnd = FindWindowEx(imwindowclass, 0&, "directuihwnd", vbNullString)
I cant get it to send the text to that window for some reason.
Life is proof that God has a sick sence of humor.
-
Aug 13th, 2005, 09:15 AM
#5
-
Aug 13th, 2005, 10:49 AM
#6
Thread Starter
Lively Member
Re: Sending text
Im not using a different API spy software. If anyone can tell me where I can get spy ++ I would greatly appreciate it
Life is proof that God has a sick sence of humor.
-
Aug 13th, 2005, 06:41 PM
#7
-
Aug 13th, 2005, 10:35 PM
#8
Thread Starter
Lively Member
Re: Sending text
Ahh ok. Well that would explain why I dont have it, Im running Visual Basic lol
Life is proof that God has a sick sence of humor.
-
Aug 14th, 2005, 02:24 AM
#9
Thread Starter
Lively Member
Re: Sending text
I used an API Spy program in another chat program that does show the child handle and I modified my code but Im still needing a lil help:
VB Code:
Private Sub Command1_Click()
Dim hWnd1 As Long
Dim hWnd2 As Long
Dim sText As String
Dim livveusamic As Long, afxframeorview As Long, afxolecontrol As Long
Dim afxmdiframe As Long, richedita As Long
livveusamic = FindWindow("livveusa-mic", vbNullString)
afxframeorview = FindWindowEx(livveusamic, 0&, "afxframeorview42", vbNullString)
afxmdiframe = FindWindowEx(afxframeorview, 0&, "afxmdiframe42", vbNullString)
afxframeorview = FindWindowEx(afxmdiframe, 0&, "afxframeorview42", vbNullString)
afxframeorview = FindWindowEx(afxmdiframe, afxframeorview, "afxframeorview42", vbNullString)
afxolecontrol = FindWindowEx(afxframeorview, 0&, "afxolecontrol42", vbNullString)
afxmdiframe = FindWindowEx(afxolecontrol, 0&, "afxmdiframe42", vbNullString)
richedita = FindWindowEx(afxmdiframe, 0&, "richedit20a", vbNullString)
Clipboard.Clear
Clipboard.SetText "TEXT TO SEND"
FindWindow "livveusa-mic", vbNormalFocus
hWnd1 = FindWindow(vbNullString, "afxmdiframe42")
hWnd2 = GetWindow(hWnd1, GW_CHILD)
sText = Clipboard.GetText
SendMessage hWnd2, WM_SETTEXT, Len(sText), sText
End Sub
Life is proof that God has a sick sence of humor.
-
Aug 14th, 2005, 05:42 AM
#10
-
Aug 14th, 2005, 05:49 AM
#11
-
Aug 14th, 2005, 10:15 AM
#12
Thread Starter
Lively Member
Re: Sending text
No I used MSN as an example but messed up because I could'nt get the child window like you said earlier. This is another chat program I use. From what i gather the parent window is "afxmdiframe" and the child window is "richedit20a".
I need to be able to set focus on the "richedit20a" window to send the text but Im having trouble doing it.
Last edited by Jackrabbit319; Aug 14th, 2005 at 10:19 AM.
Life is proof that God has a sick sence of humor.
-
Aug 14th, 2005, 11:40 AM
#13
Thread Starter
Lively Member
Re: Sending text
Ok I figured out a better way to do this. I've coded it to copy to clipboard but I am still having trouble setting focus to the texbox in the external app based on my code I posted earlier.
Life is proof that God has a sick sence of humor.
-
Aug 14th, 2005, 03:20 PM
#14
-
Aug 14th, 2005, 04:25 PM
#15
Thread Starter
Lively Member
Re: Sending text
Thats what Im having trouble with. Im not sure why its not doing it. I thought it was because its not setting focus to the richedit but now I dunno
Life is proof that God has a sick sence of humor.
-
Aug 15th, 2005, 12:11 AM
#16
Thread Starter
Lively Member
Re: Sending text [RESOLVED]
I finally figured it out !!! I figured out how to send the text in a differnt way:
VB Code:
Call SendMessage(richedita, WM_SETTEXT, 0&, ByVal List1.Text)
tyvm for your help manavo11 !!
Life is proof that God has a sick sence of humor.
-
Aug 15th, 2005, 02:57 AM
#17
Thread Starter
Lively Member
Re: Sending text
Ok I was gonna post "RESOLVE" but unfortunatly I'm not out of the woods yet. Here is how I have the command button coded to send the text from the listbox on my form to the textbox in the external app using API :
VB Code:
Private Sub Command1_Click()
Do
DoEvents
livveusamic = FindWindow("livveusa-mic", vbNullString)
afxframeorview = FindWindowEx(livveusamic, 0&, "afxframeorview42", vbNullString)
afxmdiframe = FindWindowEx(afxframeorview, 0&, "afxmdiframe42", vbNullString)
afxframeorview = FindWindowEx(afxmdiframe, 0&, "afxframeorview42", vbNullString)
afxframeorview = FindWindowEx(afxmdiframe, afxframeorview, "afxframeorview42", vbNullString)
afxolecontrol = FindWindowEx(afxframeorview, 0&, "afxolecontrol42", vbNullString)
afxmdiframe = FindWindowEx(afxolecontrol, 0&, "afxmdiframe42", vbNullString)
richedita = FindWindowEx(afxmdiframe, 0&, "richedit20a", vbNullString)
Call SendMessage(richedita, WM_SETTEXT, 0&, ByVal List1.Text)
Loop Until richedita <> 0
End Sub
Now what line or lines of code do I need so that my send does the ENTER command after it sends the text to the textbox? I've used "Sendkeys" and other API functions but none seem to work. And I'm sure I'm not modifying it right either.
Life is proof that God has a sick sence of humor.
-
Aug 15th, 2005, 03:05 PM
#18
-
Aug 15th, 2005, 06:52 PM
#19
Thread Starter
Lively Member
Re: Sending text
That would be great but there is no button to push lol
Life is proof that God has a sick sence of humor.
-
Aug 15th, 2005, 06:56 PM
#20
-
Aug 17th, 2005, 11:46 AM
#21
Thread Starter
Lively Member
Re: Sending text
No there's no send button. Its not a chat client like Yahoo or MSN, it's more like CamFrog or Eyeball chat where it has its own borwser window, user list in lobbys and rooms...ect. And yes I agree with ya that there should be, it would've made things alot easier. I messed around with it last night and discovered that the sendkey was working but I had to keep focus on that child window where the text is entered. It works great now tyvm for all your help 
Now before I resolve this thread, is there a way I could code my form so that my timer pauses when focus is lost on the texbox I send the text too, then unpause when focus is back? Reason being is whenever I set focus to another textbox it sends text then enters it to that.
Last edited by Jackrabbit319; Aug 17th, 2005 at 11:49 AM.
Life is proof that God has a sick sence of humor.
-
Aug 17th, 2005, 05:08 PM
#22
-
Aug 17th, 2005, 08:25 PM
#23
-
Aug 19th, 2005, 11:54 PM
#24
Thread Starter
Lively Member
Re: Sending text
Would I have to use a code that interrupts the event when focus is lost? If so then I have never done that
Life is proof that God has a sick sence of humor.
-
Aug 20th, 2005, 07:21 AM
#25
Re: Sending text
On every timer event, check the foreground window to see if it is your textbox or not. Use GetForegroundWindow() (I think that will work for a textbox).
-
Aug 20th, 2005, 02:24 PM
#26
-
Aug 21st, 2005, 12:54 AM
#27
Re: Sending text
OK, nice
-
Aug 21st, 2005, 11:33 AM
#28
Re: Sending text
Use this to send enter to a richedit textbox:
VB Code:
Public Const WM_CHAR As Long = &H102
SendMessage hWndTextbox, WM_CHAR, (vbKeyReturn), 0
-
Aug 28th, 2005, 04:13 PM
#29
Software Eng.
Re: Sending text
 Originally Posted by Jackrabbit319
Now what line or lines of code do I need so that my send does the ENTER command after it sends the text to the textbox? I've used "Sendkeys" and other API functions but none seem to work. And I'm sure I'm not modifying it right either.
Have you tried sending WM_KEYDOWN and WM_KEYUP messages? (Using PostMessage)
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
|