Sign in to follow this  
Followers 0
MattNis

Control Text Intead Of Name

5 posts in this topic

#1 ·  Posted (edited)

;==========================================================================================
; AutoIt Version: 3.0
; Language:       English
; Platform:       Win9x/NT/200X
; Author:         MattNis (matt@fotkee.com)
;
;   Three(3) User Functions: _WinSet, _click, _Exit
;
;===========================================================================================

Opt("TrayIconDebug", 1)
Opt("RunErrorsFatal", 0)
Opt("WinTitleMatchMode", 2)
HotKeySet("^!{END}", "_Exit")


func _winSet($winName, $winText)

    BlockInput(1)
    winWait($winName, $WinText)
    WinSetOnTop($WinName, $WinText, 1)
    winActivate($winName, $WinText)

endfunc

;=========================================================================================
;=    _click($winName, $winText, $controlName)
;=
;=    Inputs:  Window Name, Window Text, Visible Text of the class or control
;=  (Button, checkbox,etc) (Excluding any "&")
;=    Returns: 1 if successfull, 0 if button is not found or is not active.
;=             Displays MessageBox alerting user that button is not active
;=    Uses:  _WinSet, WinGetClassList, stringSplit, stringReplace, stringStripWS, 
;=           controlCommand, controlFocus, controlClick, winSetOnTop, MsgBox, return.
;=
;=    Purpose: Simplify the coding and reading process by being able to specify a visible
;=             name of the button instead of finding it's control name through AUT_spy
;=     Example:   _click("Test Application","some text","Next >")
;=========================================================================================
func _click($winName, $winText, $controlName)
    _winSet($winName, $winText)
    $controls    = WinGetClassList($winname, $winText)
    $controlsArr = stringSplit($controls,@LF)

    for $n = 1 to 30
    for $x = 1 to $controlsArr[0]
  Global $controlNN = $controlsArr[$x] & $n
  $getText = ControlGetText($winName, $winText, $controlNN)
  if ($controlName = stringStripWS(StringReplace($getText,"&",""), 7)) then
     if ControlCommand($winName, $winText, $controlNN, "IsEnabled","") then
    ControlFocus($winName, $winText, $controlNN)
    ControlClick($winName, $winText, $controlNN)
    WinSetOnTop($WinName, $WinText, 0)
    Return 1
     else
    WinSetOnTop($WinName, $WinText, 0)
    BlockInput(0)
    MsgBox(4096, "Error", $ControlName & " is not Enabled")
    Return 0
     endif
  endif
    next
    next
    MsgBox(4096, "ERROR!!!", "Error Finding: " & $controlName & " in Window: " & $winName);
    Return 0
endfunc

func _Exit()
    Exit
endfunc

Edited by MattNis

[quote]I was busy waiting all night for the Columbus Day Bunny to come down my chimney and light fireworks in my pumpkin.There's so much wrong with that.Oh, I'm sorry, i forgot you were Jewish.[/quote]

Share this post


Link to post
Share on other sites



?

You can use text instead of controlnn already.  I think.  Didn't I add that a couple of versions ago?  Or is this code slightly different?

You added that... I use special recognizable text when using Au3GuiXP to allow myself to get the classnameNN for a control after its created. On that note, however, I suggest a function that will return the classnameNN of a control. Currently I use ControlFocus then ControlGetFocus gives me the classnameNN.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Oh, sorry about that. I didn't know it was already implemented.

The only difference between this one and the one that's already implemented is that you don't have to specify the "&" as part of the control text.

Once I encountered a button that did not have any letter underlined, even after pressing the Alt key, but did have a "&" in it's text.

otherwise, unless it's already implemented, here's a function to return just the controlNN of a control with a specified text

edit: Function to get the controlNN name (ex. Edit1, Button1) from any control without any control status constrictions (enabled, disabled...etc) and without having to specify the "&" in the control text.

func _controlNN($winName, $winText, $controlName)
$controls    = WinGetClassList($winname, $winText)
$controlsArr = stringSplit($controls,@LF)

for $n = 1 to 30
   for $x = 1 to $controlsArr[0]
      Global $controlNN = $controlsArr[$x] & $n
      $getText = ControlGetText($winName, $winText, $controlNN)
      if ($controlName = stringStripWS(StringReplace($getText,"&",""), 7)) then
        Return $controlNN
      endif
   next
next
Return 0

endfunc
Edited by MattNis

[quote]I was busy waiting all night for the Columbus Day Bunny to come down my chimney and light fireworks in my pumpkin.There's so much wrong with that.Oh, I'm sorry, i forgot you were Jewish.[/quote]

Share this post


Link to post
Share on other sites

ControlFocus("Window", "Text", "ControlText")

$classnameNN = ControlGetFocus("Window", "text")

That's all you need to get a control's classnameNN form (Won't work on disabled controls, however).

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