Solved

How to send click event to button on other application

Posted on 2008-10-04
4
1,622 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
  • 2
  • 2
4 Comments
 
LVL 85

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 85

Accepted Solution

by:
Mike Tomlinson earned 50 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

789 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