[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1669
  • Last Modified:

How to send click event to button on other application

Hi,

Anyone know how to send "click" to button on other application. I tried alot of example from internet but still no luck.

Below is a portion of my existing code:
Dim hwnd As Long
 hwnd = FindWindowEx(hwnd, 0, "Button", "Cancel") 'vbNullString)
        If hwnd = 0 Then
            MsgBox("Couldn't find the button")
            Exit Sub
        End If

'PostMessage(hwnd, BM_CLICK, 0, 0)

I do not know why its not working. Need help.

0
choonghooi
Asked:
choonghooi
  • 2
  • 2
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
If you are really using VB.Net then you need to change the data types as the code you have posted is for VB6 (or below).

To convert to VB.Net you need to change all "Long" to "Integer".  (You can use "IntPtr" for window handles instead.)

Don't forget to change any other API declarations and all of your local variables as well...

So it would look like:
Private Const BM_CLICK As Integer = &HF5
Private Declare Function SendMessage Lib "user32" (ByVal handle As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
 
...
    Dim hwnd As Integer
    ...
    SendMessage(hwnd, BM_CLICK, 0, 0)

Open in new window

0
 
choonghooiAuthor Commented:
Idle_Mind,

Thanks :)
I need to sendmessage to hide a toolbar inside pdf. By using spy++, i found out that the toolbar described as Window 00B51286 "AVToolBarEasel" AVL_AVView, i try the below codes:

hwnd_box = FindWindowEx(app_hwnd, 0, "AVL_AVView", "AVToolBarEasel")
PostMessage(hwnd_box, SW_HIDE, 0, 0)

However i coudnt get the handler for AVToolBarEasel, any idea? Please refer to the attached print screen, there are several entries of AVL_AVView and the highlighted is the correct one.


AVToolBarEasel.GIF
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
The TreeView in your screenshot shows the hierarchy of the windows.  Each indent represents a parent/child relationship.  To get your desired handle you need to start with the apps main window handle and iteratively grab the next child window until you get down to the desired level...you can't just jump straight there as the FindWindowEx() only searches the DIRECT children of the handle specified.  (Your window is FIVE levels deep.)

When you have multiple controls of the same type at the same level and you want the XXXth one then you have to use some more APIs to get the correct one.  Once you find the first handle, you can get to the next one at the same level using the GetWindow() API and the GW_HWNDNEXT flag:
http://msdn.microsoft.com/en-us/library/ms633515(VS.85).aspx

So you use FindWindowEx() to move "down" the right level and GetWindow() to move "across" controls within levels.  If you want the 4th control at a certain level then you call GetWindow() with GW_HWNDNEXT three times after getting the first control at that level.

Now if there are many different TYPES of controls at the same level and you want the XXXth control of a certain type, then you can check the CLASS of each window using GetClassName():
http://msdn.microsoft.com/en-us/library/ms633582(VS.85).aspx

There are actually many ways to do this type of thing but I think this is the easiest to visualize and understand...especially when you come back and look at the code in the future.

0
 
choonghooiAuthor Commented:
Thanks alot :)
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now