Results 1 to 29 of 29

Thread: Sending text

  1. #1

    Thread Starter
    Lively Member Jackrabbit319's Avatar
    Join Date
    Sep 2004
    Location
    PA
    Posts
    80

    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.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Sending text

    Quote 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:
    1. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    2.     (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    3. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    4.     (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, _
    5.     ByVal lParam As Any) As Long
    6. Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, _
    7.     ByVal wCmd As Long) As Long
    8.  
    9. Private Const WM_SETTEXT = &HC
    10. Private Const GW_CHILD = 5
    11. Private Sub Command1_Click()
    12. Dim hWnd1 As Long
    13. Dim hWnd2 As Long
    14. Dim sText As String
    15.  
    16.     Clipboard.Clear
    17.     Clipboard.SetText Text1.Text
    18.    
    19.     Shell "Notepad", vbNormalFocus
    20.     hWnd1 = FindWindow(vbNullString, "Untitled - Notepad")
    21.     hWnd2 = GetWindow(hWnd1, GW_CHILD)
    22.    
    23.     sText = Clipboard.GetText
    24.     SendMessage hWnd2, WM_SETTEXT, Len(sText), sText
    25.  
    26. 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.

  3. #3

    Thread Starter
    Lively Member Jackrabbit319's Avatar
    Join Date
    Sep 2004
    Location
    PA
    Posts
    80

    Re: Sending text

    Ok thanx I'll give it a try
    Life is proof that God has a sick sence of humor.

  4. #4

    Thread Starter
    Lively Member Jackrabbit319's Avatar
    Join Date
    Sep 2004
    Location
    PA
    Posts
    80

    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:
    1. Dim imwindowclass As Long, directuihwnd As Long
    2. imwindowclass = FindWindow("imwindowclass", vbNullString)
    3. 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.

  5. #5
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Sending text

    That handle (directuihwnd) is generally for the window, not the textbox part of the window... Using Spy++ I can't see any child windows under that handle, so this might not be possible!
    Last edited by manavo11; Aug 27th, 2005 at 11:03 AM. Reason: Fixed typo


    Has someone helped you? Then you can Rate their helpful post.

  6. #6

    Thread Starter
    Lively Member Jackrabbit319's Avatar
    Join Date
    Sep 2004
    Location
    PA
    Posts
    80

    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.

  7. #7
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Sending text

    It comes with Visual Studio. In the start menu, in programs, in MS Visual Studio, in MS Visual Studio Tools you should see Spy++


    Has someone helped you? Then you can Rate their helpful post.

  8. #8

    Thread Starter
    Lively Member Jackrabbit319's Avatar
    Join Date
    Sep 2004
    Location
    PA
    Posts
    80

    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.

  9. #9

    Thread Starter
    Lively Member Jackrabbit319's Avatar
    Join Date
    Sep 2004
    Location
    PA
    Posts
    80

    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:
    1. Private Sub Command1_Click()
    2. Dim hWnd1 As Long
    3. Dim hWnd2 As Long
    4. Dim sText As String
    5. Dim livveusamic As Long, afxframeorview As Long, afxolecontrol As Long
    6. Dim afxmdiframe As Long, richedita As Long
    7.  
    8. livveusamic = FindWindow("livveusa-mic", vbNullString)
    9. afxframeorview = FindWindowEx(livveusamic, 0&, "afxframeorview42", vbNullString)
    10. afxmdiframe = FindWindowEx(afxframeorview, 0&, "afxmdiframe42", vbNullString)
    11. afxframeorview = FindWindowEx(afxmdiframe, 0&, "afxframeorview42", vbNullString)
    12. afxframeorview = FindWindowEx(afxmdiframe, afxframeorview, "afxframeorview42", vbNullString)
    13. afxolecontrol = FindWindowEx(afxframeorview, 0&, "afxolecontrol42", vbNullString)
    14. afxmdiframe = FindWindowEx(afxolecontrol, 0&, "afxmdiframe42", vbNullString)
    15. richedita = FindWindowEx(afxmdiframe, 0&, "richedit20a", vbNullString)
    16.  
    17.  
    18. Clipboard.Clear
    19. Clipboard.SetText "TEXT TO SEND"
    20.  
    21. FindWindow "livveusa-mic", vbNormalFocus
    22. hWnd1 = FindWindow(vbNullString, "afxmdiframe42")
    23. hWnd2 = GetWindow(hWnd1, GW_CHILD)
    24.  
    25.  
    26. sText = Clipboard.GetText
    27. SendMessage hWnd2, WM_SETTEXT, Len(sText), sText
    28.  
    29.  
    30. End Sub
    Life is proof that God has a sick sence of humor.

  10. #10
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Sending text

    First thing I notice is that this line :

    VB Code:
    1. FindWindow "livveusa-mic", vbNormalFocus

    does nothing... It's wrong and you don't save the return value anywhere... I'll check the rest now.


    Has someone helped you? Then you can Rate their helpful post.

  11. #11
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Sending text

    Is this for MSN? I'm confused


    Has someone helped you? Then you can Rate their helpful post.

  12. #12

    Thread Starter
    Lively Member Jackrabbit319's Avatar
    Join Date
    Sep 2004
    Location
    PA
    Posts
    80

    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.

  13. #13

    Thread Starter
    Lively Member Jackrabbit319's Avatar
    Join Date
    Sep 2004
    Location
    PA
    Posts
    80

    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.

  14. #14
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Sending text

    You should be able to use the SetFocus API to set the focus to the handle of the richedit you got from the FindWindowEx call.

    VB Code:
    1. Declare Function SetFocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long

    Why do you need it to set focus though? Can't you set the text with the WM_SETTEXT message or the SetWindowText API?


    Has someone helped you? Then you can Rate their helpful post.

  15. #15

    Thread Starter
    Lively Member Jackrabbit319's Avatar
    Join Date
    Sep 2004
    Location
    PA
    Posts
    80

    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.

  16. #16

    Thread Starter
    Lively Member Jackrabbit319's Avatar
    Join Date
    Sep 2004
    Location
    PA
    Posts
    80

    Re: Sending text [RESOLVED]

    I finally figured it out !!! I figured out how to send the text in a differnt way:

    VB Code:
    1. 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.

  17. #17

    Thread Starter
    Lively Member Jackrabbit319's Avatar
    Join Date
    Sep 2004
    Location
    PA
    Posts
    80

    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:
    1. Private Sub Command1_Click()
    2.  
    3. Do
    4.     DoEvents
    5.     livveusamic = FindWindow("livveusa-mic", vbNullString)
    6.     afxframeorview = FindWindowEx(livveusamic, 0&, "afxframeorview42", vbNullString)
    7.     afxmdiframe = FindWindowEx(afxframeorview, 0&, "afxmdiframe42", vbNullString)
    8.     afxframeorview = FindWindowEx(afxmdiframe, 0&, "afxframeorview42", vbNullString)
    9.     afxframeorview = FindWindowEx(afxmdiframe, afxframeorview, "afxframeorview42", vbNullString)
    10.     afxolecontrol = FindWindowEx(afxframeorview, 0&, "afxolecontrol42", vbNullString)
    11.     afxmdiframe = FindWindowEx(afxolecontrol, 0&, "afxmdiframe42", vbNullString)
    12.     richedita = FindWindowEx(afxmdiframe, 0&, "richedit20a", vbNullString)
    13.    
    14.     Call SendMessage(richedita, WM_SETTEXT, 0&, ByVal List1.Text)
    15.    
    16. Loop Until richedita <> 0
    17.  
    18.  
    19. 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.

  18. #18
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Sending text

    Instead of "sending" the enter key, could you simulate a click on a button?


    Has someone helped you? Then you can Rate their helpful post.

  19. #19

    Thread Starter
    Lively Member Jackrabbit319's Avatar
    Join Date
    Sep 2004
    Location
    PA
    Posts
    80

    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.

  20. #20
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Sending text

    Huh? What kind of chat application is that? Isn't there a "Send" button? Kinda makes sense to have one


    Has someone helped you? Then you can Rate their helpful post.

  21. #21

    Thread Starter
    Lively Member Jackrabbit319's Avatar
    Join Date
    Sep 2004
    Location
    PA
    Posts
    80

    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.

  22. #22
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Sending text

    You should be able to use the GetAncestor API to see the parent window of each textbox. Using FindWindow you can find the handle of the window containing the textbox you want. Compare the GetAncestor result for the active control with the FindWindow result (should be this "livveusamic = FindWindow("livveusa-mic", vbNullString)") and see if it's the same, then depending on if it is or not, send the text

    If you need help with any of this just ask


    Has someone helped you? Then you can Rate their helpful post.

  23. #23
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Sending text

    Or even better, send the WM_KEYDOWN, WM_KEYUP messages to the textbox with the VK_RETURN key


    Has someone helped you? Then you can Rate their helpful post.

  24. #24

    Thread Starter
    Lively Member Jackrabbit319's Avatar
    Join Date
    Sep 2004
    Location
    PA
    Posts
    80

    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.

  25. #25
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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).

  26. #26
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Sending text

    Using SendMessage doens't require the textbox to have focus.

    penagate, the GetForegroundWindow will get you the window that is in focus, not the control. To get the handle of the control you can use this : http://www.vbforums.com/showpost.php...1&postcount=10
    Last edited by manavo11; Aug 20th, 2005 at 02:28 PM.


    Has someone helped you? Then you can Rate their helpful post.

  27. #27
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Sending text

    OK, nice

  28. #28
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Sending text

    Use this to send enter to a richedit textbox:

    VB Code:
    1. Public Const WM_CHAR As Long = &H102
    2. SendMessage hWndTextbox, WM_CHAR, (vbKeyReturn), 0

  29. #29
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286

    Re: Sending text

    Quote 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
  •  



Click Here to Expand Forum to Full Width