Is control count limit hardcoded into ahk?

Get help with using AutoHotkey and its commands and hotkeys
User avatar
KuroiLight
Posts: 327
Joined: 12 Apr 2015, 20:24
GitHub: KuroiLight

Is control count limit hardcoded into ahk?

Post by KuroiLight » 06 Jan 2018, 02:51

doing some testing to optimize some code, using the following example:

Code: Select all

#SingleInstance, force
#Persistent
DetectHiddenWindows, On

Gui, New, +HwndNotify_Window,
Gui, %Notify_Window%: Add, Text, +HwndStatic1Hwnd Right, "Hello World"
HwndCount := 1
Loop {
    DllCall("User32\DestroyWindow", "UInt", Static1Hwnd)
    Gui, %Notify_Window%: Add, Text, X5 Y5 +HwndStatic1Hwnd Right, "Hello World"
    HwndCount++
    ToolTip, %HwndCount%
    Sleep, -1
}
return
I'd expect to never reach the "Too many controls" error message since the controls are properly destroyed, but I do at 11K; I'm guessing there is an internal counter that isn't getting updated?
Is there a way to de-increment this counter?
I tried Gui, %Static1Hwnd%: Destroy, but that gives "Invalid gui name".
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]
01/24/18
[/color]

User avatar
Alguimist
Posts: 374
Joined: 05 Oct 2015, 16:41
Contact:

Re: Is control count limit hardcoded into ahk?

Post by Alguimist » 06 Jan 2018, 03:35

The counter cannot be decremented with DllCall.
Documentation wrote:GuiControl, Delete (not yet implemented): This sub-command does not yet exist. As a workaround, use Hide and/or Disable (above), or destroy and recreate the entire window via Gui Destroy.

User avatar
KuroiLight
Posts: 327
Joined: 12 Apr 2015, 20:24
GitHub: KuroiLight

Re: Is control count limit hardcoded into ahk?

Post by KuroiLight » 06 Jan 2018, 04:08

I'm aware of that bit about GuiControl, Delete, its unfortunate that its not implemented, At the very least I'd expect it could decrement the internal counter.
I ended up doing this in one of the timer functions:

Code: Select all

    if((HwndCount >= 500 and (A_TimeIdle >= (1000 * 60 * 5))) or HwndCount >= 1000) {
        Gui, %Notify_Window%: Destroy
        Notify_Window := 0 ;window will be created next time its needed if this is 0
        HwndCount := 0
    }
But still open to suggestions.
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]
01/24/18
[/color]

Post Reply

Return to “Ask For Help”