Opened 15 years ago

Closed 15 years ago

#705 closed Bug (Fixed)

_GUICtrlToolbar_ClickButton() function does not always click on buttons

Reported by: Bowmore Owned by: Gary
Milestone: Component: AutoIt
Version: Severity: None
Keywords: GuiToolBar.au3 Cc:


WinXP Home SP3
AutoIt Beta

The coords of the centre of button are calculated in screen coords, but the click is preformed using whatever MouseCoordMode the user has set. The MouseCoordMode option needs setting to 1 and then resetting back to the original value before exiting the function.

Code to demonstrate existing behaviour of existing function and that of the suggested fix below. ToolbaButtonClickTest.exe is a compiled version of the Create a Toolbar control help file example to give some buttons to click.
ToolbaButtonClickTest.exe is the compliled version of the attached file

Opt("MustDeclareVars", 1)
Opt("WinWaitDelay", 100)
Opt("WinTitleMatchMode", 4)
Opt("WinDetectHiddenText", 1)
Opt("MouseCoordMode", 2)
Opt("PixelCoordMode", 2)

#include <GuiToolBar.au3>

Local $hWnd = 0 
Local $iCommandID = 0

Run(@ScriptDir & "\ToolbaButtonClickTest.exe")

$hWnd = ControlGetHandle("Toolbar", "", "ToolbarWindow321")
;Display behaviour of standard function first and the the modified version
For $ifunc = 0 To 1 
	;Display behaviour when mouse is not moved and then when mouse is moved
	For $iMove = 0 To 1
		;Use each of the MouseCoordMode in turn 
		For $iCoordMode = 0 To 2
			Opt("MouseCoordMode", $iCoordMode)
			For $i = 0 To 4
				$iCommandID = _GUICtrlToolbar_IndexToCommand($hWnd, $i)
				If $ifunc = 0 Then
					ToolTip("Standard UDF Function '_GUICtrlTab_ClickTab()' MouseCoordMod = " & $iCoordMode & @CRLF & "Attempting To click on button " & $i & " mouse moving is " & ($iMove <> 0), 20, 20)
					_GUICtrlToolbar_ClickButton($hWnd, $iCommandID, "left", ($iMove <> 0), 1, 50)
					ToolTip("Modified UDF Function '_GUICtrlTab_ClickTab()' MouseCoordMode = " & $iCoordMode & @CRLF & "Attempting To click on button " & $i & " mouse moving is " & ($iMove <> 0), 20, 20)
					MOD_GUICtrlToolbar_ClickButton($hWnd, $iCommandID, "left", ($iMove <> 0), 1, 50)
				Sleep(3000) ;time to see what happens

Func MOD_GUICtrlToolbar_ClickButton($hWnd, $iCommandID, $sButton = "left", $fMove = False, $iClicks = 1, $iSpeed = 1)
	If $Debug_TB Then _GUICtrlToolbar_ValidateClassName($hWnd)
	Local $tPoint, $tRect, $iX, $iY, $iMode, $aPos

	$tRect = _GUICtrlToolbar_GetButtonRectEx($hWnd, $iCommandID)
	$tPoint = _WinAPI_PointFromRect($tRect)
	$tPoint = _WinAPI_ClientToScreen($hWnd, $tPoint)
	_WinAPI_GetXYFromPoint($tPoint, $iX, $iY)
	;Switch to screen MouseCoordMode 
	$iMode = Opt("MouseCoordMode", 1)
	If Not $fMove Then
		$aPos = MouseGetPos()
		;_WinAPI_ShowCursor does not seem to work on XP so set mouse speed it instant 
		MouseClick($sButton, $iX, $iY, $iClicks, 0)
		MouseMove($aPos[0], $aPos[1], 0)
		MouseClick($sButton, $iX, $iY, $iClicks, $iSpeed)
	;Switch back to user MouseCoordMode 
	Opt("MouseCoordMode", $iMode)
EndFunc   ;==>MOD_GUICtrlToolbar_ClickButton

Attachments (1)

ToolbaButtonClickTest.au3 (2.9 KB) - added by anonymous 15 years ago.

Download all attachments as: .zip

Change History (2)

Changed 15 years ago by anonymous

comment:1 Changed 15 years ago by Gary

  • Milestone set to
  • Owner set to Gary
  • Resolution set to Fixed
  • Status changed from new to closed

Fixed in version:

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

as closed The owner will remain Gary.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.