Jump to content

afx:toolbar manipulation


Recommended Posts

On the most current release of my company's software, we updated our ToolbarWindow32 controls to an afx:Toolbar

I'm able to find the commandids for the buttons I need on the toolbar, but performing the _GUICtrlToolbar_ClickButton on it results in clicking the top left corner of the toolbar.

Anyone familiar with this type of control? Suggestions?

I've tried:

#include <Array.au3>
#include <GuiToolbar.au3>
$hwndWindow = WinGetHandle ( "Our application" )
$hwndToolbar = ControlGetHandle ( $hwndWindow, "", 59392 )
$aPos = ControlGetPos ( $hwndWindow, "", $hwndToolbar ) ; able to find pos of toolbar
$aTools = GetVisibleToolbarButtons ( $hwndWindow, $hwndToolbar )
$iDeleteControlPos = _ArraySearch ( $aTools, "Delete" )
$iDeleteControl = $aTools[$iDeleteControlPos][0]
ConsoleWrite ( $iDeleteControl & @CRLF ) ; Returns 36558
WinActivate ( $hwndWindow )
ControlFocus ( $hwndWindow, "", $hwndToolbar )
_GUICtrlToolbar_ClickButton ( $hwndToolbar, $iDeleteControl, "left", True, 1, 80 )
$atest1 = _GUICtrlToolbar_GetButtonRect ( $hwndToolbar, $iDeleteControl )
$atest2 = _GUICtrlToolbar_GetButtonRectEx ( $hwndToolbar, $iDeleteControl )
$atest3 = _GUICtrlToolbar_GetButtonSize ($hwndToolbar )
;_ArrayDisplay ($atest1,1 ) ; Returns all 0's
;_ArrayDisplay ($atest2,2 ) ; Returns all 0's
;_ArrayDisplay ($atest3,3 ) ; Returns all 0's
ControlFocus ( $hwndWindow, "", $hwndToolbar )
_GUICtrlToolbar_PressButton ( $hwndToolbar, $iDeleteControl )
ControlFocus ( $hwndWindow, "", $hwndToolbar )
$result = ControlCommand ( $hwndWindow, "", $hwndToolbar, "SendCommandID", $iDeleteControl )
ConsoleWrite ( $result & @CRLF ) ; Returns 0

Edit: using relative positions of the control now...only a temporary fix, since there are hundreds of potential buttons that are dynamically present...

Edited by jdelaney
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.
Link to comment
Share on other sites

phew, ControlCommand works...my issue was i was sending the wrong delete controlcommandid...the function i use to get the id's was not able to filter by isvisible...just need a workaround for that.

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.
Link to comment
Share on other sites

  • 10 years later...

@jdelaney I know its an old post. But recently I am struck automating the afx tool bar. I have identified the button control, but when I do a button click it always clicked at the top left corner as you mentioned in your above post. I am posting the code, can you please help.

 

Func PassportInputs()
Local $IE = _IECreate("My Application")
sleep(10000)

  $hwndWindow =  WinGetHandle('[CLASS:IEFrame]')
  $hwndToolbar  = ControlGetHandle ( $hwndWindow, "", '[CLASS:Afx:ToolBar:400000:8:10003:10; INSTANCE:2]' )
  $aPos = ControlGetPos ( $hwndWindow, "", $hwndToolbar )
    WinActivate ( $hwndWindow )
    ControlFocus ( $hwndWindow, "", $hwndToolbar )
        $iCmdID = _GUICtrlToolbar_IndexToCommand($hwndToolbar, 16)
        ConsoleWrite ( $iCmdID & @CRLF ) 
        $sText = _GUICtrlToolbar_GetButtonText($hwndToolbar, $iCmdID)
        _GUICtrlToolbar_ClickButton ( $hwndToolbar, $iCmdID, "left", True, 1, 80 )
        $atest1 = _GUICtrlToolbar_GetButtonRect ( $hwndToolbar, $iCmdID )
        $atest2 = _GUICtrlToolbar_GetButtonRectEx ( $hwndToolbar, $iCmdID )
        $atest3 = _GUICtrlToolbar_GetButtonSize ($hwndToolbar )
        ControlFocus ( $hwndWindow, "", $hwndToolbar )
        _GUICtrlToolbar_PressButton ( $hwndToolbar, $iCmdID )
    

EndFunc

 

Edited by Soundarya
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...