Results 1 to 13 of 13

Thread: send click event to an other App

  1. #1

    Thread Starter
    Junior Member headache's Avatar
    Join Date
    Aug 2002
    Location
    hire
    Posts
    19

    Unhappy send click event to an other App

    I must send the click evet to the OK button from an other application.
    Please help me.
    I know that I know nothing

  2. #2
    Lively Member mmiill's Avatar
    Join Date
    May 2002
    Location
    SERBIA
    Posts
    73

    !

    try to use API f:SendMessage
    mm

  3. #3

    Thread Starter
    Junior Member headache's Avatar
    Join Date
    Aug 2002
    Location
    hire
    Posts
    19
    My API Literay are bad. Please could you halp me
    VB Code:
    1. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    2.    (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    3. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    4.    (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    5.  
    6. Private Const WM_NCLBUTTONDOWN = &HA1
    7.  
    8. Private Sub cmdCloseApp_Click()
    9. Dim CloseIt As Long
    10.     CloseIt = FindWindow(vbNullString, "Microsoft Outlook")
    11.     SendMessage CloseIt, WM_NCLBUTTONDOWN, CLng(0), CLng(0)
    12. End Sub

    Thank you very mouch!
    Last edited by headache; Aug 8th, 2002 at 02:24 AM.
    I know that I know nothing

  4. #4
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    Send the BM_CLICK message to the window.

  5. #5

    Thread Starter
    Junior Member headache's Avatar
    Join Date
    Aug 2002
    Location
    hire
    Posts
    19

    Thank you

    How can i tell him which button?

    It send something but not to the OK button.

    VB Code:
    1. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    2.      (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    3. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    4.      (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    5.  
    6. Private Const BM_CLICK = &HF5
    7.  
    8. Private Sub cmdCloseApp_Click()
    9. Dim CloseIt As Long
    10.     CloseIt = FindWindow(vbNullString, "Microsoft Outlook")
    11.     SendMessage CloseIt, BM_CLICK, CLng(0), CLng(0)
    12. End Sub
    I know that I know nothing

  6. #6
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    Send BM_CLICK to the actual button (not the parent window).

    To get the handle of the button, use the FindWindowEx function. e.g.

    hwndButton = FindWindowEx(hwndParent, 0, "Button", "Button Text")

  7. #7
    Fanatic Member
    Join Date
    Sep 2000
    Location
    Over There
    Posts
    522
    I've had to do this before. Once you find the windows using find window, you'll have to use use the EnumChildWindows API.
    you'll hva
    Here's some code to get you started.

    Public Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long

    Public Declare Function SendMessageByStr& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String)


    Private Function GetChildControls(apphwnd As Long)
    EnumChildWindows apphwnd, AddressOf EnumChildProc, ByVal 0&
    End Function


    Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
    Dim sSave As String
    Dim sClassName As String
    Dim sWindowText As String
    Dim lControlId As Long

    '// Get window class name

    ReDim Preserve Wlist(UBound(Wlist) + 1)
    sClassName = String(255, Chr(0))
    GetClassName hwnd, sClassName, 255
    sClassName = Left(sClassName, InStr(1, sClassName, Chr(0), vbTextCompare) - 1)

    sWindowText = String(255, Chr(0))
    SendMessageByStr hwnd, WM_GETTEXT, 255, sWindowText
    'if the text is &OK or whatever you're looking for, use sendmessage to click the button.

    sWindowText = Left(sWindowText, InStr(1, sWindowText, Chr(0), vbTextCompare) - 1)
    lControlId = GetWindowLong(hwnd, GWL_ID)
    '// continue enumeration
    EnumChildProc = 1
    End Function

  8. #8
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    Another way to go about this is to use FindWindowEx again; but this time, start at the previous window e.g.

    hChild = FindWindowEx(hParent, hChild, "Button", vbNullstring)

    This will enumerate all buttons.

    But again, you'd only need to do this if the button does not have a caption. If it does, then you should get it on the first try.

  9. #9

    Thread Starter
    Junior Member headache's Avatar
    Join Date
    Aug 2002
    Location
    hire
    Posts
    19
    I have only the capion of the bottom and only the caption from the window.

    Please help
    I know that I know nothing

  10. #10
    Lively Member mmiill's Avatar
    Join Date
    May 2002
    Location
    SERBIA
    Posts
    73

    !

    try this :

    CloseIt = FindWindow(vbNullString, "Microsoft Outlook")
    hwndButton = FindWindowEx(CloseIt, 0, "Button", "OK")
    SendMessage hwndButton, BM_CLICK, CLng(0), CLng(0)

    and tell me if it works becouse i forgot how it works i mean this functions FindWindowEx, i want to refresh my memory
    mm

  11. #11

    Thread Starter
    Junior Member headache's Avatar
    Join Date
    Aug 2002
    Location
    hire
    Posts
    19

    Talking It Works!!!!!!!!!!!

    It Works!!!!!!!!!!!

    Thank you all for the great help.


    hire is my current code

    VB Code:
    1. Option Explicit
    2. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    3.      (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    4. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    5.      (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    6. Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
    7.      (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    8.  
    9. Private Const BM_CLICK = &HF5
    10.  
    11. Private Sub cmdCloseApp_Click()
    12. Dim CloseIt As Long
    13. Dim hwndbutton As Long
    14.     CloseIt = FindWindow(vbNullString, "Microsoft Outlook")
    15.     hwndbutton = FindWindowEx(CloseIt, 0, vbNullString, "OK")
    16.     SendMessage hwndbutton, BM_CLICK, CLng(0), CLng(0)
    17. End Sub
    Last edited by headache; Aug 9th, 2002 at 01:45 AM.

  12. #12
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    You're welcome

    It's usually a good idea to specify the classname as well e.g.
    Code:
    hwndbutton = FindWindowEx(CloseIt, 0, "Button", "OK")
    It just helps narrow your search down a little more.

  13. #13
    Junior Member
    Join Date
    Aug 2002
    Posts
    17
    What's the parameter if it's a dropdown menu or combo box?

    -Roy

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