Results 1 to 4 of 4

Thread: Clicking on a button...

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    4

    Question

    Hello!
    I need to raise a click-event on a command button which is on another application.
    How can I manage to do that...
    I tried using the windows API PostMessage Function to broadcast the WM_LBUTTONDOWN message to this particular program, but, it seemed not to work...
    So, any idea is welcome!
    Thank you!

  2. #2
    Addicted Member
    Join Date
    Nov 2000
    Posts
    217

    .

    cant u do
    Code:
    formname.command1_click

  3. #3
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Nope you can't if it's not your prog

    Either download my class at:
    http://www.geocities.com/despotez/WH/

    or use this code (I use it in the Class too )

    Code:
    Private Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End Type
    
    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 Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    
    Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
    Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    
    Private Sub Click(WinhWnd As Long, x As Long, y As Long, Optional Left As Boolean = True, Optional Right As Boolean, Optional Middle As Boolean, Optional DoubleClick As Boolean = False)
    Dim i%
    
    If DoubleClick Then
    MouseDown Left, Right, Middle, True, True, x, y
    MouseDown Left, Right, Middle, True, True, x, y
    Else
    MouseDown Left, Right, Middle, True, True, x, y
    End If
    End Sub
    
    Private Sub MouseDown(Optional Left As Boolean = True, Optional Right As Boolean, Optional Middle As Boolean, Optional Click As Boolean, Optional MoveToPoint As Boolean, Optional x As Long, Optional y As Long)
    'Thanks to Kedaman for this:
    If MoveToPoint Then SetCursorPos x, y
        mouse_event -Left * 2 - Right * 8 - Middle * 32, 0, 0, 0&, 0&
        If Click Then mouse_event -Left * 4 - Right * 16 - Middle * 64, 0&, 0&, 0&, 0&
    End Sub
    Private Sub MouseUp(Optional Left As Boolean = True, Optional Right As Boolean, Optional Middle As Boolean, Optional MoveToPoint As Boolean, Optional x As Long, Optional y As Long)
    'Thanks to Kedaman for this:
    If MoveToPoint Then SetCursorPos x, y
        mouse_event -Left * 4 - Right * 16 - Middle * 64, 0, 0, 0&, 0&
    End Sub
    Use it like
    Code:
    Private Sub Command1_Click()
    Dim z&,button&, win As RECT
    z = FindWindow("MYCLASSNAME", "MYCAPTION") 'Gets the window's hanlde by either classname or caption
    button = FindWindowEx(z, ByVal 0&, "Button", "") 'gets the handle of the first button
    GetWindowRect button, win 'get's the position of the button
    Click button, win.Left + 10, win.Top + 10, True, False, False, False 'Clicks it :)
    End Sub

    Hope it's not too confusing...
    anyway, to make thing easier, download my class
    @ http://www.geocities.com/despotez/WH/
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  4. #4
    Guest

    Re: .

    Incase your wondering...

    Originally posted by mpSmooth
    cant u do
    Code:
    formname.command1_click
    I don't think that will work. If you want to set off the event of a command button on another form. Just mess with it's Value property.


    Private Sub Command1_Click()
    'Form1 Command Button
    Form2.Command1.Value = True
    End Sub

    Private Sub Command1_Click()
    'Form2 Command Button
    Msgbox "Command1_Click"
    End Sub

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