Sign in to follow this  
Followers 0
junkew

How to handle toolbar button

4 posts in this topic

#1 ·  Posted (edited)

A small handy function to encapsulate handling the toolbar buttons a little easier

Example

#include <GuiToolbar.au3>

$IEWindow = "[REGEXPTITLE:Internet Explorer; INSTANCE:1]"
$GotoButton  = "[CLASS:ToolbarWindow32; INSTANCE:4; CommandID:100]"

_HandleToolBarButton($IEWindow, $GotoButton, "CLICK")
;_HandleToolBarButton($IEWindow, "[CLASS:ToolbarWindow32; INSTANCE:4; CommandID:100]", "CLICK")


;Specific function to handle toolbarwindow32 or compatible toolbars
func _HandleToolbarButton($g_wndDescription, $g_objDescription, $g_objValue)
;local $x, $cmdID, $tbWndDescription
    $x=stringinstr($g_objDescription,";", 0 ,2); Get the location of second semicolon /;
    $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)
    
    $tbHandle = controlgethandle($g_wndDescription,"",$tbWndDescription);Get the toolbar handle
    $aRect = _GUICtrlToolbar_GetButtonRect ($tbHandle, $cmdID)        ;Get its rectangle (relative position)
    
;If the action is to click
                if $g_objValue = "CLICK" Then
                              ;find the location of the toolbar
        $pos=controlgetpos($g_wndDescription,"", $tbWndDescription); Get the toolbar location
;Add the location of the button
        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

Edit 24/02: Fixed the problems reported in the example

Edited by junkew

Share this post


Link to post
Share on other sites



C:\INCLUDE\test.au3(15,51) : WARNING: $g_wndDescription: possibly used before declaration.
    $tbHandle = controlgethandle($g_wndDescription,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\INCLUDE\test.au3(15,51) : ERROR: $g_wndDescription: undeclared global variable.
    $tbHandle = controlgethandle($g_wndDescription,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\INCLUDE\test.au3(16,62) : ERROR: _GUICtrlToolbar_GetButtonRect(): undefined function.
    $aRect = _GUICtrlToolbar_GetButtonRect ($tbHandle, $cmdID)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\INCLUDE\test.au3 - 2 error(s), 1 warning(s)
!>08:03:26 AU3Check ended.rc:2
+>08:03:27 AutoIt3Wrapper Finished
>Exit code: 0    Time: 1.468

source code is missing :)

Share this post


Link to post
Share on other sites

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