Results 1 to 23 of 23

Thread: Info exchange between apps

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2000
    Location
    toronto
    Posts
    19

    Question

    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.

  2. #2
    New Member
    Join Date
    Jun 2000
    Posts
    9

    Red face

    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
    -CLouDX

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jul 2000
    Location
    toronto
    Posts
    19
    Yes, i no HWND and yet, SendMessageByString is not SendMessage and so how does one declare it?

  5. #5
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    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)
    Courgettes.

  6. #6
    Addicted Member
    Join Date
    Apr 2000
    Posts
    215
    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?.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jul 2000
    Location
    toronto
    Posts
    19
    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

  8. #8
    Addicted Member
    Join Date
    Apr 2000
    Posts
    215
    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.

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Jul 2000
    Location
    toronto
    Posts
    19
    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

  10. #10
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341
    How do you use DDE

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Jul 2000
    Location
    toronto
    Posts
    19
    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

  12. #12
    Lively Member
    Join Date
    Jul 2000
    Location
    Ireland, Dublin
    Posts
    76

    Wink

    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.

  13. #13
    Addicted Member
    Join Date
    Apr 2000
    Posts
    215
    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.

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Jul 2000
    Location
    toronto
    Posts
    19

    Smile

    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

  15. #15
    Lively Member
    Join Date
    Jul 2000
    Location
    Ireland, Dublin
    Posts
    76

    Talking

    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
    ---------------------------------
    TopMan
    ---------------------------------

  16. #16

    Thread Starter
    Junior Member
    Join Date
    Jul 2000
    Location
    toronto
    Posts
    19

    Talking

    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

  17. #17
    Addicted Member
    Join Date
    Apr 2000
    Posts
    215
    trying sending chr(13) or chr(13) + chr(10)
    or if sendmessage api allows it send vbcrlf

  18. #18
    New Member
    Join Date
    Jun 2000
    Posts
    9

    Red face

    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]
    -CLouDX

  19. #19
    New Member
    Join Date
    Jun 2000
    Posts
    9
    so IS there a button u can press?
    -CLouDX

  20. #20

    Thread Starter
    Junior Member
    Join Date
    Jul 2000
    Location
    toronto
    Posts
    19
    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

  21. #21
    Guest
    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.

  22. #22
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362

    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.

  23. #23
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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
  •  



Click Here to Expand Forum to Full Width