Jump to content
Sign in to follow this  
Danith

Help with pushing button on toolbar

Recommended Posts

Danith

I'm trying to automate a old reporting app we have (that no one can find the source code for /sigh). I'm having trouble where manually you would go up to the 'export report' button and click it.

According to Window Info, the button is on ToolbarWindow32 but theres about 6 other controls on that same toolbar and I don't see any specific identification information to differentiate between them. I suppose I could select it by the coordinates on the toolbar (you can do that right?) but I would like it better if there was a way to activate it directly.

Looking through it with the window info tool, there is no identifying information for that specific button besides the coordinates. It does have a tooltip that pops up if you hover over the button but I'm not sure if I can utilize that to grab/push the button..

Should I just use the button coordinates to push it?

Edited by Danith

Share this post


Link to post
Share on other sites
herewasplato

... Should I just use the button coordinates to push it?

If the toolbar can be moved around by the user, then PixelCheckSum might be a good way to know where to click.

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
Danith

If the toolbar can be moved around by the user, then PixelCheckSum might be a good way to know where to click.

Thank you for the response. No, the toolbar can't be moved around, and when the window is resized the toolbar stays the same size so I'm guessing it would be easier/faster to just use the coordinate to push it.

Share this post


Link to post
Share on other sites
herewasplato

... just use the coordinate to push it.

yep :-)

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
junkew

CommandId should be able to differentiate them

$g_objDescription="[CLASS:ToolbarWindow32; INSTANCE:4; CommandID:100]"

I just copied pasted some code out of my framework that hopefully gives enough reference to see

1. How to retrieve all command ids on a toolbar based on their index and where the mouse is hovering (spy program)

2. Shows how based on above description dynamically determines the right location to click

if (stringinstr($sClassname,"Toolbar") > 0) Then
    $iCount = _GUICtrlToolbar_ButtonCount($hWnd)
    for $i=0 to $icount -1
    ;Determine rectangle and check matching area
        $aRect = _GUICtrlToolbar_GetButtonRect ($hWnd, _GUICtrlToolbar_IndexToCommand($hWnd, $i))
        $mPos=mousegetpos()
        $wPos=wingetpos($hWnd)
        if (($mPos[0] - $wPos[0]) > $arect[0] ) and (($mPos[0] - $wPos[0]) < $arect[2] ) _
        And (($mPos[1] - $wPos[1]) > $arect[1] ) and (($mPos[1] - $wPos[1]) < $arect[3] ) Then
            $tbText = "[Index: "     & $i & _ 
                      " CommandID: " & _GUICtrlToolbar_IndexToCommand($hWnd, $i) & _
                      " text: "   & _GUICtrlToolbar_GetButtonText($hWnd, $i) & " ]"
            GUICtrlSetData($mainLabel,$tbText)
        endif   
    next
endIf

;Specific function to handle toolbarwindow32 or compatible toolbars
func HandleToolbar()
;local $x, $cmdID, $tbWndDescription
    $x=stringinstr($g_objDescription,";", 0 ,2);Second;
    $tbWndDescription = stringleft($g_objDescription,$x-1) & "]"; Get the actual AutoIt TB Description
    $cmdID = stringmid($g_objdescription,stringinstr($g_objDescription,"CommandID:")+stringlen("CommandID:"))
    $cmdID= stringleft($cmdID,stringlen($cmdId)-1)
;   consolewrite("1" & $g_wnddescription & @crlf)
;   consolewrite($tbWndDescription & @crlf)
;   consolewrite($cmdID & @crlf)
    
    $tbHandle = controlgethandle($g_wndDescription,"",$tbWndDescription) ;Get the toolbar handle
    $aRect = _GUICtrlToolbar_GetButtonRect ($tbHandle, $cmdID)         ;Get its rectangle (relative position)
;   consolewrite($aRect[0] & @crlf)
;   consolewrite($aRect[1] & @crlf)
;   consolewrite($aRect[2] & @crlf)
;   consolewrite($aRect[3] & @crlf)
    
    if $g_objValue = "CLICK" Then
        $pos=controlgetpos($g_wndDescription,"", $tbWndDescription) ; Get the toolbar location
        
        mousemove($pos[0]+$aRect[0]+(($aRect[2]-$aRect[0])/2),$pos[1]+$arect[1]+(($aRect[3]-$aRect[1])/2),0)  ;Move the mouse to the toolbarlocation and to right control
        sleep(2000)
        mouseclick("left")

;Don't click with below functions as it will click on disabled buttons
;       ControlFocus($$g_wndDescription, "", $c)
;       ControlClick($g_wndDescription, "", $tbHandle, "left",1, $aRect[0], 5)

    endif
EndFunc

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  

×