Results 1 to 7 of 7

Thread: Clicking other application's buttons.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Is this the way how to click the "OK" or any button from another application?

    Thanks for helping!!!

    Code:
    Option Explicit
    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 Findwindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    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 SendMessageByNum Lib "user32" Alias "SendMessageA" (ByVal hWnd%, ByVal wMsg%, ByVal wparam%, ByVal lparam&)
    Private Const WM_LBUTTONDOWN = &H201
    Private Const WM_LBUTTONUP = &H202
    
    Private Sub Timer1_Timer()
      Dim lng_Dialog As Long
      Dim lng_Button As Long
      lng_Dialog = Findwindow("#32770", vbNullString)
      lng_Button = FindWindowEx(lng_Dialog, 0&, "Button", vbNullString)
      Call Click(lng_Button)
    End Sub
    
    Sub Click(lng_Handle As Long)
      DoEvents
      
      Dim lng_Response As Long
      lng_Response = SendMessage(lng_Handle, WM_LBUTTONDOWN, 0, 0&)
      lng_Response = SendMessage(lng_Handle, WM_LBUTTONUP, 0, 0&)
    End Sub
    Chemically Formulated As:
    Dr. Nitro

  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    Probably, try it and see

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    I can see the button getting click but it is not closing the message box. The other way to close a message box is using the constant - wm_close. I just like to know why the code made the OK button click but it won't close the message box.
    Chemically Formulated As:
    Dr. Nitro

  4. #4
    Lively Member Ishamel's Avatar
    Join Date
    Nov 1999
    Location
    Edinburgh, Scotland
    Posts
    112
    Nitro - did you ever find out why clicking the OK button did not fire the close event on the external applications message box???

    I am also trying to click an external applications button and although I can see the button being clicked, the click event does not appear to be fired off. (Unfortunately, I cannot get away with using WM_CLOSE, becuase I need the event to take place.)

    Any help would be greatly appreciated.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Sorry Ishamel!

    I am still stuck and don't understand why. Someone out there have any ideas?

    The codes above clicks a foreign application's button, but it doesn't do anthing afterward. We can actually see the "OK" button of the message box gets click.

    [Edited by Nitro on 06-13-2000 at 03:46 PM]
    Chemically Formulated As:
    Dr. Nitro

  6. #6
    Fanatic Member
    Join Date
    Jan 1999
    Location
    UK
    Posts
    554
    Hi Nitro,

    question:
    Is the window the Active window when the button is clicked?

    If not try to make it so and then retry.

    DocZaf
    {;->
    course i may be wrong


  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Thanks Zaf!

    It is actually a messagebox. I made it click OK but it won't close the message box. The other alternative is wm_close.

    Thanks buddy.
    Chemically Formulated As:
    Dr. Nitro

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