Jump to content

how to highlight the button found by autoit


Recommended Posts

Here is my code

I am trying to press a button that comes up when audacity application crashes.

To my surprise , autoit says it is present in a normal window also . How to highlight the button it has found ?

#include <MsgBoxConstants.au3>
AutoItSetOption ( "WinTitleMatchMode" , 2)
Local $audwnd = WinWait("Audacity","",10)
If $audwnd == 0 Then
MsgBox($MB_ICONERROR, "Script_Info", "No window with title audacity found . Bye !")
Else
    Local $hButton = ControlGetHandle($audwnd, "", "[CLASS:Button; INSTANCE:1]")
    If $hButton Then
        MsgBox($MB_SYSTEMMODAL, "", "The handle of ok button in audacity is : " & $hButton)
    EndIf
EndIf

Thanks.

Link to comment
Share on other sites

Please note that I used autoit window info tool to identify the ok button when audacity crash window had appeared .

ControlGetHandle does not return any coordinates . 

mousemove needs coordinates . How can I get those ? 

Edited by manit
Link to comment
Share on other sites

I downloaded controlviewer(source v0.2024.9.16).

In it there is cv.au3 script which has lot of code . Do i have to use that ? 

I think , you are saying that my search parameter " [CLASS:Button; INSTANCE:1] " has to be fine-tuned .

 

Edited by manit
Link to comment
Share on other sites

5 hours ago, manit said:

Do i have to use that ? 

..well, yeah. Otherwise I have to install audacity, make it crash and do what you're doing. And right now I don't have even the brain power to show you in a MsgBox.
..or maybe I do ...

#include <GuiConstants.au3> ; for GUISquare_Create()
Global $_g__Square_GUI[4], $_g__Square_Color = 0x00CC00, $_g__Square_Width = 3

If StringInStr($CmdLineRaw, "/msgBoxThing") Then Exit MsgBox(262144, "PointerPointingToTheControlDemo", "Where's the button ?")
ShellExecute(@AutoItExe, '"' & @ScriptFullPath & '" /msgBoxThing') ; run a MsgBox()

ConsoleWrite(PointerPointingToTheControl("PointerPointingToTheControlDemo", "", "Button1", 1, 50) & @CRLF)
Func PointerPointingToTheControl($sTitle, $sText, $sCtrlId, $bClickIt = False, $iSpeed = 10)
    ; https://www.autoitscript.com/forum/index.php?showtopic=212400&view=findpost&p=1537933
    Local $hWin = WinWait($sTitle, $sText, 2) ; find the window in 2 seconds or quit
    If Not $hWin Then Return SetError(1, 0, "! can't find the window")
    Local $hCtrlId = ControlGetHandle($hWin, "", $sCtrlId) ; find the control in the window
    If Not $hCtrlId Then Return SetError(2, 0, "! can't find the control")
    Local $aCtrlIdPos = WinGetPos($hCtrlId) ; get the position of the control in the window
    If @error Or UBound($aCtrlIdPos) <> 4 Then Return SetError(3, 0, "! can't find the control's position")
    GUISquare_Create($aCtrlIdPos[0], $aCtrlIdPos[1], $aCtrlIdPos[2], $aCtrlIdPos[3]) ; <--- this may help ?
    Local $hTimer = TimerInit()
    MouseMove($aCtrlIdPos[0] + ($aCtrlIdPos[2] / 2), $aCtrlIdPos[1] + ($aCtrlIdPos[3] / 2), $iSpeed)
    Do
        Sleep(10)
    Until TimerDiff($hTimer) > 500 ; ..to give you time to see it ?
    If $bClickIt Then MouseClick("Main") ; click the darn thing
    GUISquare_Delete()
    Return "Found ya."
EndFunc   ;==>PointerPointingToTheControl

Func GUISquare_Create($X, $Y, $W, $H)
    $X -= $_g__Square_Width
    $Y -= $_g__Square_Width
    $W += $_g__Square_Width
    $H += $_g__Square_Width
    $_g__Square_GUI[0] = GUICreate("", $W, $_g__Square_Width, $X, $Y, $WS_POPUP, $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW)
    $_g__Square_GUI[1] = GUICreate("", $_g__Square_Width, $H, $X, $Y, $WS_POPUP, $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW)
    $_g__Square_GUI[2] = GUICreate("", $_g__Square_Width, $H, $X + $W, $Y, $WS_POPUP, $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW)
    $_g__Square_GUI[3] = GUICreate("", $W + $_g__Square_Width, $_g__Square_Width, $X, $Y + $H, $WS_POPUP, $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW)
    For $i = 0 To 3
        GUISetBkColor($_g__Square_Color, $_g__Square_GUI[$i])
        GUISetState(@SW_SHOW, $_g__Square_GUI[$i])
    Next
EndFunc   ;==>GUISquare_Create

Func GUISquare_Delete()
    If Not $_g__Square_GUI[0] Then Return
    For $i = 0 To 3
        GUIDelete($_g__Square_GUI[$i])
        $_g__Square_GUI[$i] = 0
    Next
EndFunc   ;==>GUISquare_Delete

:)

Edit: Turned it into a function. 👏

Edited by argumentum
better

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

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...