?
Solved

How to send click event to button on other application

Posted on 2008-10-04
4
Medium Priority
?
1,650 Views
Last Modified: 2013-11-26
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
Comment
Question by:choonghooi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 22641122
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
 

Author Comment

by:choonghooi
ID: 22649574
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
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 200 total points
ID: 22651935
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
 

Author Comment

by:choonghooi
ID: 22686272
Thanks alot :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question