Results 1 to 11 of 11

Thread: Passing text to another application (RESOLVED)

  1. #1

    Thread Starter
    Member dark.journey's Avatar
    Join Date
    Nov 2002
    Location
    somewhere between Hell and back
    Posts
    36

    Passing text to another application (RESOLVED)

    I am attempting to write an program which will send text to another application. The other application contains a textbox. In this case I am trying to write a poetry reader for a chat group - to save having to enter each line manually.
    questions is - how do I find the running application - and how do i find and enter text into the textbox....
    I am relatively new to VB - and am trying to teach myself - but this has me stumped. =/
    thanks in advance
    Last edited by dark.journey; Nov 20th, 2002 at 11:07 AM.
    *follow the white rabbit neo*

    .¸¸.·´¯`·.¸.·>dark journey<·.¸¸.·´¯`·.¸.

    To accomplish great things, we must dream as well as act.
    Anatole France (1844 - 1924)

  2. #2

    Thread Starter
    Member dark.journey's Avatar
    Join Date
    Nov 2002
    Location
    somewhere between Hell and back
    Posts
    36
    thanks to the FAQ by "The Hobo" I have solved the first problem - I have managed to find the find window HWND - (not sure how to use it yet - but hope to real fast.)
    *follow the white rabbit neo*

    .¸¸.·´¯`·.¸.·>dark journey<·.¸¸.·´¯`·.¸.

    To accomplish great things, we must dream as well as act.
    Anatole France (1844 - 1924)

  3. #3
    New Member
    Join Date
    Nov 2002
    Location
    Over your Head !
    Posts
    3

    If You Know What App or Window Was ACTIVE ...

    Hi !

    If You Know The Name Of Active Window You Can Find Hwnd Of It ! With These Codes !

    '---------------------------------------
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

    Private sub cmdFind_click()
    Dim Handle as Long

    ' For Exm : Handle=FindWindow(Class Here , Name Here) {You Can Find Class With API SPY Or Spy++ And Find Name That Wrote Top Of Windows}

    Handle=FindWindow("Calculator",vbNullString)
    MSGBOX (Handle)

    End Sub


  4. #4

    Thread Starter
    Member dark.journey's Avatar
    Join Date
    Nov 2002
    Location
    somewhere between Hell and back
    Posts
    36
    old hex thanks - that works a real treat - i have found the window classname now - which makes things easier as the caption is ever changing - i also found the textbox classname - but have no idea how to implement the idea i have of transferring text from a vb program to the text input window of the chat client
    *follow the white rabbit neo*

    .¸¸.·´¯`·.¸.·>dark journey<·.¸¸.·´¯`·.¸.

    To accomplish great things, we must dream as well as act.
    Anatole France (1844 - 1924)

  5. #5
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    VB Code:
    1. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    2.      ByVal hwnd As Long, _
    3.      ByVal wMsg As Long, _
    4.      ByVal wParam As Long, _
    5.      ByVal lParam As String) As Long
    6. Private Const WM_SETTEXT As Long = &HC
    7.  
    8. SendMessage hwndTextBox, WM_SETTEXT, 0&, "MY String"

  6. #6

    Thread Starter
    Member dark.journey's Avatar
    Join Date
    Nov 2002
    Location
    somewhere between Hell and back
    Posts
    36
    thanx ami - I think this one is going to take some working on =/ - guess you cant just "dive in at the deep end" - i really needed this too - thought it would be soooo simple - lol - welp - I guess simple is relative =)
    *follow the white rabbit neo*

    .¸¸.·´¯`·.¸.·>dark journey<·.¸¸.·´¯`·.¸.

    To accomplish great things, we must dream as well as act.
    Anatole France (1844 - 1924)

  7. #7
    New Member
    Join Date
    Nov 2002
    Location
    Columbus OH
    Posts
    1

    Possble sidebar but...

    I am a little behind in this. I can find the handle and I understand how to use the SendMessage. My problem is getting the textbox handle.

    I am in a different situation, I think. What I am trying to do is send the text message to a window that is for a terminal emulator. I don't think it is windows based and therefore may not have a textbox as such. What I would like to do is just send the string of characters to where the cursor is currently positioned in that window.
    Using the "Notepad", when I sent the message to the handle of the window it was sent to the caption. I also have an idea for a work around if it is not possible to send the text as described.

    So my questions are:
    1. Is it possible, and how can you send a message to where the cursor is in the window.

    2. If that is not possible then how can I send a CTRL V to the window so that I can paste from the clipboard. I think I can get the information to the clipboard.

    Craig
    One step above an Expert Novice
    Craig

  8. #8

    Thread Starter
    Member dark.journey's Avatar
    Join Date
    Nov 2002
    Location
    somewhere between Hell and back
    Posts
    36
    Originally posted by amitabh
    VB Code:
    1. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    2.      ByVal hwnd As Long, _
    3.      ByVal wMsg As Long, _
    4.      ByVal wParam As Long, _
    5.      ByVal lParam As String) As Long
    6. Private Const WM_SETTEXT As Long = &HC
    7.  
    8. SendMessage hwndTextBox, WM_SETTEXT, 0&, "MY String"
    ok i used this and managed to update the window caption - are there any special variable names I need to use to find the object that I am after - in this case - a textbox?
    *follow the white rabbit neo*

    .¸¸.·´¯`·.¸.·>dark journey<·.¸¸.·´¯`·.¸.

    To accomplish great things, we must dream as well as act.
    Anatole France (1844 - 1924)

  9. #9
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    Do you have Spy++? If yes, then find out the class name of the textbox. After that, use this code to find the handle to the text box.
    VB Code:
    1. Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
    2. (ByVal hWndParent As Long, ByVal hWndChildAfter As Long, ByVal lpszClassName As String, _
    3. ByVal lpszWindowCaption As String) As Long
    4.  
    5. Dim hwndTxtBox As Long
    6.     hwndTxtBox = FindWindowEx("<Window handle>", 0&, "<text box class name>", vbNullString)
    This assumes that you have only one text box, other wise you might try replacing the vbNullString with whatever is in the textbox.

  10. #10

    Thread Starter
    Member dark.journey's Avatar
    Join Date
    Nov 2002
    Location
    somewhere between Hell and back
    Posts
    36
    Originally posted by amitabh
    Do you have Spy++? If yes, then find out the class name of the textbox. After that, use this code to find the handle to the text box.
    VB Code:
    1. Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
    2. (ByVal hWndParent As Long, ByVal hWndChildAfter As Long, ByVal lpszClassName As String, _
    3. ByVal lpszWindowCaption As String) As Long
    4.  
    5. Dim hwndTxtBox As Long
    6.     hwndTxtBox = FindWindowEx("<Window handle>", 0&, "<text box class name>", vbNullString)
    This assumes that you have only one text box, other wise you might try replacing the vbNullString with whatever is in the textbox.

    Thank You so much amitabh this works perfectly - I was up till 4am looking for just this piece of information - I appreciate your help very much =)
    *follow the white rabbit neo*

    .¸¸.·´¯`·.¸.·>dark journey<·.¸¸.·´¯`·.¸.

    To accomplish great things, we must dream as well as act.
    Anatole France (1844 - 1924)

  11. #11
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    Anytime

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