Solved

How to send click event to button on other application

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now