AHK v2 Migration. What is the syntax for WinGet ControlList? Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
sixtytrees
Posts: 7
Joined: 17 Feb 2017, 12:55

AHK v2 Migration. What is the syntax for WinGet ControlList?

09 Jun 2018, 20:22

AHK v1.1 script uses

Code: Select all

WinGet, ControlList, ControlList, A
Loop , Parse, ControlList, `n 
	{ /*...*/ }
To check content of Menu strings. What function should I use in AHK v2 for this call?
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: AHK v2 Migration. What is the syntax for WinGet ControlList?

09 Jun 2018, 20:38

see this link:

https://autohotkey.com/v2/

you should find two things to help you

1. the v2-changes doc
2. the v2 documentation

User avatar
Flipeador
Posts: 1204
Joined: 15 Nov 2014, 21:31
Location: Argentina
Contact:

Re: AHK v2 Migration. What is the syntax for WinGet ControlList?  Topic is solved

09 Jun 2018, 20:40

https://lexikos.github.io/v2/docs/comma ... m#Controls

Code: Select all

F1::
List := WinGetControlsHwnd("A")
Str := ""
For Index, ControlID in List
    Str .= ControlID . " [" . WinGetClass("ahk_id" . ControlID) . "]`n"
MsgBox Str
Return

Code: Select all

F1::
List := WinGetControls("A")
Str := ""
Loop (ObjLength(List))
    Str .= List[A_Index] . "`n"
MsgBox Str
Return
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: AHK v2 Migration. What is the syntax for WinGet ControlList?

09 Jun 2018, 23:50

Always use the for loop.
If there's only a single element in the array it takes 1.5 times as long as loop + access.
However as soon as there are 2 elements in the loops the normal loop gets slower drastically. (e. g. with a 1000 entries in the loop its 30 times slower than the normal loop)
It also is less clear then the normal for loop and less flexible.
Please don't use this and please don't suggest this.

Btw I would use this:

Code: Select all

for Each, ControlID in WinGetControls("A")
	…
Recommends AHK Studio
User avatar
Flipeador
Posts: 1204
Joined: 15 Nov 2014, 21:31
Location: Argentina
Contact:

Re: AHK v2 Migration. What is the syntax for WinGet ControlList?

10 Jun 2018, 08:08

nnnik wrote:with a 1000 entries in the loop its 30 times slower than the normal loop
Yes, you're right.

Code: Select all

ToolTip "Push"
Arr := []
Arr.SetCapacity(10000000)
Loop 10000000
    Arr.Push(0)

Var := 0

ToolTip "Loop"
QPC(S := A_TickCount)
Loop (ObjLength(Arr))
    Var := Arr[A_Index]
ElapsedTime1 := QPC() . " (" . (A_TickCount-S) . " ms)"

ToolTip "For"
QPC(S := A_TickCount)
For Each, Value in Arr
    Var := Value
ElapsedTime2 := QPC() . " (" . (A_TickCount-S) . " ms)"

MsgBox "Loop: " . ElapsedTime1 . "`nFor: " . ElapsedTime2
; ------------------------------------


QPC(R := 0)
{
    static Frequency := 0, P := 0
         ; https://msdn.microsoft.com/en-us/library/windows/desktop/ms644905(v=vs.85).aspx
         , PC := DllCall("Kernel32.dll\QueryPerformanceFrequency", "Int64P", Frequency)

    ; https://msdn.microsoft.com/en-us/library/windows/desktop/ms644904(v=vs.85).aspx
    return !DllCall("Kernel32.dll\QueryPerformanceCounter", "Int64P", PC) + (R ? (P := PC) / Frequency : (PC - P) / Frequency) 
}
Please don't use this and please don't suggest this
:|
Spoiler
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: AHK v2 Migration. What is the syntax for WinGet ControlList?

10 Jun 2018, 08:42

That is a bug Flipeador, if you define the class above the function definition, it is preserved. The warning should probably be removed too, although it is not really wrong.

Cheers.
lexikos
Posts: 9635
Joined: 30 Sep 2013, 04:07
Contact:

Re: AHK v2 Migration. What is the syntax for WinGet ControlList?

12 Jun 2018, 22:40

The warning will not be removed, as it is both correct and an important hint to avoid reusing the variable name ABC. The class will be overwritten, if only temporarily. Any code that executes before the for-loop exits (whether inside the loop, in a called function, or in some unrelated code that executes in an interrupting thread) will not be able to refer to the actual class by ABC.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: AHK v2 Migration. What is the syntax for WinGet ControlList?

13 Jun 2018, 11:45

Very good, you are correct of course, we should declare the variable local, unless we really want to overwrite the class.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: kunkel321 and 47 guests