Solved

How to send click event to button on other application

Posted on 2008-10-04
4
1,629 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 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

Independent Software Vendors: 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

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 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