Results 1 to 11 of 11

Thread: Sendmessage API

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2000
    Location
    Manchester NH
    Posts
    833
    I thought I got it but I don't

    I have an app with the form caption "Clock Data" and a text box in that app called txtClock.

    how can I send a message from one app to that text box
    Kurt Simons
    [I know I'm a hack but my clients don't!]

  2. #2
    Guest
    Use FindWindowEx to get the hWnd of a child window.
    Code:
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    
    Private Sub Command1_Click()
    
        Dim hParent As Long
        Dim hChild As Long
        
        'Get the hWnd of the parent window
        hParent = FindWindow(vbNullString, "Clock Data")
        'Get the hWnd of the child window. If Clock Data is a Visual C++ app, then
        'change ThunderTextBox to Edit
        hChild = FindWindowEx(hParent, 0&, "ThunderTextBox", vbNullString)
        'Send a message to the TextBox
        SendMessage hChild, MyMessage, 0, 0
        
    End Sub

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2000
    Location
    Manchester NH
    Posts
    833
    so in the place of thundertext box I type
    "txtClock"

    - i would just try it but i'm not at work
    Kurt Simons
    [I know I'm a hack but my clients don't!]

  4. #4
    Guest
    No, ThunderTextBox is the ClassName for the TextBox. Likewise, Visual C++ uses a TextBox with the ClassName of Edit. If this program (Clock Data) was made in Visual Basic, then leave it at ThunderTextBox.

    PS: is txtClock the only TextBox on the Form?

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2000
    Location
    Manchester NH
    Posts
    833
    No its not, what do I do
    Kurt Simons
    [I know I'm a hack but my clients don't!]

  6. #6
    Guest
    No problem, Just make the search more specific. Enter the text of the TextBox for the last argument in FindWindowEx,

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2000
    Location
    Manchester NH
    Posts
    833
    Can I use a label as well as a text box?
    ------------------

    this is what it looks like then...


    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long

    Private Sub Command1_Click()

    Dim hParent As Long
    Dim hChild As Long

    'Get the hWnd of the parent window
    hParent = FindWindow(vbNullString, "Clock Data")
    'Get the hWnd of the child window. If Clock Data is a Visual C++ app, then
    'change ThunderTextBox to Edit
    hChild = FindWindowEx(hParent, 0&, "ThunderTextBox", "txtClock")
    'Send a message to the TextBox
    SendMessage hChild, MyMessage, 0, 0

    End Sub
    Kurt Simons
    [I know I'm a hack but my clients don't!]

  8. #8
    Guest
    Is txtClock the actual name of the clock? You must enter the Text that's in txtClock. for example, it could be 12:00, so you would change it to
    Code:
    hChild = FindWindowEx(hParent, 0&, "ThunderTextBox", "12:00")

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2000
    Location
    Manchester NH
    Posts
    833
    OH,

    so it looks for the text in all the text boxes and inserts into the one that matches
    Kurt Simons
    [I know I'm a hack but my clients don't!]

  10. #10
    Guest
    Yes. It will look through each instance of the ThunderTextBox class (in their ZOrder) and see if text matches. If so, it will return the hWnd of that window.

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2000
    Location
    Manchester NH
    Posts
    833
    Thanks a bundle...

    I have a program that has a running clock and its going to update another program, It will change the text boxes text which will call the change event. I guess I'll set the text boxes property back to "<CLOCK>" or something so it always finds it.

    QUESTIONS

    what happens is the program is busy doing a query or something will it respond to the change event.

    Does the sending programs freeze until it has been updated (this is what i am trying to avoid)
    Kurt Simons
    [I know I'm a hack but my clients don't!]

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