Jump to content

how to enumerate controls


martin
 Share

Recommended Posts

I have a design with about 70 components. I don't want to create them programmatiaclly so I've done it using Koda.

I would like to do something like this pseudo code, but can't see how to do it.

for Controlnumber = 1 to NumerOfControls ;how to find the number of controls

if controlType(Controlnumber) = Button then ;how to identify the control type

do something

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I'm out of time, but maybee you can play with this.

As you can figure out GuiCtrlCreate* returns a internal id to a control reference created by the script engine. You should be able to use that information to achive what you want.

Func GuiEnumerateControls()
   Local $gui = GUICreate("Test", 200, 200, 200, 200)
   Local $arr[6]
   $arr[0] = 5
   $arr[1] = GUICtrlCreateButton("Test 1", 10, 0)
   $arr[2] = GUICtrlCreateCheckbox("Check 1", 10, 30)
   $arr[3] = GUICtrlCreateButton("Test 2", 10, 60)
   $arr[4] = GUICtrlCreateCheckbox("Check 2", 10, 90)
   $arr[5] = GUICtrlCreateButton("Test 3", 10, 120)
   ;TODO: This did not retuyrn the type as I expected
   dbg(GUICtrlGetHandle($arr[1]) & " :: " & WinGetClassList(GUICtrlGetHandle($arr[1])))
   dbg(GUICtrlGetHandle($arr[3]) & " :: " & WinGetClassList(GUICtrlGetHandle($arr[2])))
   GUISetState()
   dbgArr($arr)
   While 1
      $msg = GuiGetMsg()
      Switch $msg
         Case -3 
            Exit
      EndSwitch
   WEnd
EndFunc   
Func dbg($msg, $line=@ScriptLineNumber, $err=@error, $ext=@extended)
   If NOT @Compiled Then 
      ConsoleWrite("(" & $line & ") := (" & $err & ")(" & $ext & ") " & $msg & @CRLF)
   EndIf
EndFunc
Func dbgArr($arr, $line=@ScriptLineNumber, $err=@error, $ext=@extended)
   dbg("dbgArr: ", $line, $err, $ext)
   Local $i
   For $i = 0 to UBound($arr) -1 
      dbg("$arr[$i]:=" & $arr[$i], $line, $err, $ext)
   Next
EndFunc

Happy Scripting..:shocked:

Link to comment
Share on other sites

I'm out of time, but maybee you can play with this.

As you can figure out GuiCtrlCreate* returns a internal id to a control reference created by the script engine. You should be able to use that information to achive what you want.

Func GuiEnumerateControls()
   Local $gui = GUICreate("Test", 200, 200, 200, 200)
   Local $arr[6]
   $arr[0] = 5
   $arr[1] = GUICtrlCreateButton("Test 1", 10, 0)
   $arr[2] = GUICtrlCreateCheckbox("Check 1", 10, 30)
   $arr[3] = GUICtrlCreateButton("Test 2", 10, 60)
   $arr[4] = GUICtrlCreateCheckbox("Check 2", 10, 90)
   $arr[5] = GUICtrlCreateButton("Test 3", 10, 120)
   ;TODO: This did not retuyrn the type as I expected
   dbg(GUICtrlGetHandle($arr[1]) & " :: " & WinGetClassList(GUICtrlGetHandle($arr[1])))
   dbg(GUICtrlGetHandle($arr[3]) & " :: " & WinGetClassList(GUICtrlGetHandle($arr[2])))
   GUISetState()
   dbgArr($arr)
   While 1
      $msg = GuiGetMsg()
      Switch $msg
         Case -3 
            Exit
      EndSwitch
   WEnd
EndFunc   
Func dbg($msg, $line=@ScriptLineNumber, $err=@error, $ext=@extended)
   If NOT @Compiled Then 
      ConsoleWrite("(" & $line & ") := (" & $err & ")(" & $ext & ") " & $msg & @CRLF)
   EndIf
EndFunc
Func dbgArr($arr, $line=@ScriptLineNumber, $err=@error, $ext=@extended)
   dbg("dbgArr: ", $line, $err, $ext)
   Local $i
   For $i = 0 to UBound($arr) -1 
      dbg("$arr[$i]:=" & $arr[$i], $line, $err, $ext)
   Next
EndFunc

Happy Scripting..:shocked:

Thanks for the idea Uten, I didn't know about WinGetClassList! :">

WinGetClassList(GUICtrlGetHandle($arr[1]))) doesn't return anything, but then the parameter should be a window title or handle.

But no matter, WinGetClassList("Test") gives the list of classes is in the order the controls were created, so I can find out the gui IDs for all the buttons, and the number of classes in the list tells me how many controls I should search through so I can get what I need.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...