Sign in to follow this  
Followers 0
MortenM

ControlClick/WinExist not working

6 posts in this topic

Hi,

I'm trying to click a button in a popup window, but have so far failed all attempts. This is the output from Au3Info:

>>>> Window <<<<
Title:  VncViewer Message Box
Class:  #32770
Position:   752, 397
Size:   416, 378
Style:  0x94C800CC
ExStyle:    0x00010101
Handle: 0x00190364

>>>> Control <<<<
Class:  Button
Instance:   1
ClassnameNN:    Button1
Name:   
Advanced (Class):   [CLASS:Button; INSTANCE:1]
ID: 1
Text:   Close
Position:   278, 265
Size:   84, 23
ControlClick Coords:    69, 17
Style:  0x50010000
ExStyle:    0x00000004
Handle: 0x00160440

>>>> Mouse <<<<
Position:   1102, 701
Cursor ID:  0
Color:  0xD4D0C8

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<
Close
Failed to get server address !
Info Message
UltraVnc 1.0.9.5
Sponsored
 Link


>>>> Hidden Text <<<<

This code does not work for me:

If WinExists("VncViewer Message Box") Then
      ControlClick("VncViewer Message Box", "", "[CLASS:Button ;INSTANCE:1]")
EndIf

Can someone point out to me what is wrong?

Using the CLASS ID for the window creates an endless loop before I even start the VNC Viewer, so I can not use it.

Thanks

Share this post


Link to post
Share on other sites



Hi Morten,

  Try to get the Window Handle and use that.

Some error checking helps sometimes too( in the form of a MsgBox )

Example:

While 1
    If WinExists("Run") Then
        MsgBox(0, "", "Win now exists")
        $hWnd = WinGetHandle("Run")
        ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:4]")
    Else
        ContinueLoop
    EndIf
WEnd

Share this post


Link to post
Share on other sites

I tried using a msgbox for error checking, but it never pops up. There must be something I do wrong in the IF statement.

Using the same code to look for notepad Works as expected, but not with this window.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

No MsgBox probably means WinExists cant see the window you have named "VncViewer Message Box"

which means your error check worked :-) you have an error ;-)

could not find where to get the "VncViewer Message Box" to popup but here is a working reproducer that might help you along:

If you run this script, then start VNC Viewer, it will click on the INFO button 2 seconds after the window is registered.

While 1
    If WinExists("VNC Viewer") Then
;~      MsgBox(0, "", "Win now exists")
        $hWnd = WinGetHandle("VNC Viewer")
        Sleep(2000) ; couple of seconds to collect thoughts
        ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:2]")
        Exit
    Else
        ContinueLoop
    EndIf
WEnd
Edited by l3ill

Share this post


Link to post
Share on other sites

You could use the ControlCommand function as an alternative. The 'Check' parameter is the same as doing a click.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

Remarks

Some controls will resist clicking unless they are the active window. Use the WinActivate() function to force the control's window to the top before using ControlClick().

Using 2 for the number of clicks will send a double-click message to the control - this can even be used to launch programs from an explorer control!

If the user has swapped the left and right mouse buttons in the control panel, then the behaviour of the buttons is different. "Left" and "right" always click those buttons, whether the buttons are swapped or not. The "primary" or "main" button will be the main click, whether or not the buttons are swapped. The "secondary" or "menu" buttons will usually bring up the context menu, whether the buttons are swapped or not.

I also like to ControlFocus on the button, first.

 


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0