Simple change to Gui breaks functionality

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
fade2gray
Posts: 85
Joined: 21 Apr 2015, 12:28

Simple change to Gui breaks functionality

10 Feb 2023, 12:55

This simple Gui just disables the checkboxes and changes their background colour when the button is clicked. After inserting a couple of tabs, the checkboxes still get disabled, but the background colour doesn't change.

Can anyone tell me what's up?

Simple Gui

Code: Select all

Gui, add, Text,, Some stuff here
Gui, add, Checkbox, vCB1 hwndH1, Checkbox one label
Gui, add, Checkbox, vCB2 hwndH2, Checkbox two label
Gui, Add, Button, gBtn, Button
Gui, Show
Return

Btn:
    Gui, Submit, NoHide
    SetStaticColor(H1, "0x60FF60")
    GuiControl, Disabled, CB1
    SetStaticColor(H2, "0x60FF60")
    GuiControl, Disabled, CB2
Return

GuiEscape:
GuiClose:
ExitApp

Gui with tabs added

Code: Select all

Gui, Add, Tab3,, One|Two
Gui, Tab, 1
Gui, add, Text,, Some stuff here
Gui, Tab, 2
Gui, add, Checkbox, vCB1 hwndH1, Checkbox label
Gui, add, Checkbox, vCB2 hwndH2, Checkbox label
Gui, Add, Button, gBtn, Button
Gui, Show
Return

Btn:
    Gui, Submit, NoHide
    SetStaticColor(H1, "0x60FF60")
    GuiControl, Disabled, CB1
    SetStaticColor(H2, "0x60FF60")
    GuiControl, Disabled, CB2
Return

GuiEscape:
GuiClose:
ExitApp

Functions common to both - courtesy of @teadrinker viewtopic.php?p=179339#p179339

Code: Select all

SetStaticColor(hStatic, b_color, f_color := 0){
    static arr := [], GWL_WNDPROC := -4
    b_color := DllCall("Ws2_32\ntohl", UInt, b_color << 8, UInt)
    f_color := DllCall("Ws2_32\ntohl", UInt, f_color << 8, UInt)
    hGui := DllCall("GetParent", Ptr, hStatic, Ptr)
    If !arr.HasKey(hGui)  {
        arr[hGui] := {}, arr[hGui].Statics := []
        arr[hGui].ProcOld := DllCall("SetWindowLong" . (A_PtrSize = 8 ? "Ptr" : ""), Ptr, hGui, Int, GWL_WNDPROC
        , Ptr, RegisterCallback("WindowProc", "", 4, Object(arr[hGui])), Ptr)
    }Else If arr[hGui].Statics.HasKey(hStatic)
        DllCall("DeleteObject", Ptr, arr[hGui].Statics[hStatic].hBrush)
    arr[hGui].Statics[hStatic] := { b_color: b_color, f_color: f_color
    , hBrush: DllCall("CreateSolidBrush", UInt, b_color, Ptr) }
    WinSet, Redraw,, ahk_id %hStatic%
}

WindowProc(hwnd, uMsg, wParam, lParam){
    Critical
    static WM_CTLCOLORSTATIC := 0x138
    obj := Object(A_EventInfo)
    If (uMsg = WM_CTLCOLORSTATIC && k := obj.Statics[lParam]){
        DllCall("SetBkColor", Ptr, wParam, UInt, k.b_color)
        DllCall("SetTextColor", Ptr, wParam, UInt, k.f_color)
        Return k.hBrush
    }
    Return DllCall("CallWindowProc", Ptr, obj.ProcOld, Ptr, hwnd, UInt, uMsg, Ptr, wParam, Ptr, lParam)
}
Last edited by fade2gray on 11 Feb 2023, 09:01, edited 1 time in total.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Simple change to Gui breaks functionality

10 Feb 2023, 15:26

from looking at it, the functions assumes the parent of whatever control hwnd u passed in is going to be the Gui(so it can then subclass it). but the parent of controls belonging to Tab3 is not the Gui, but the Tab3 frame

either dont use Tab3 or the function needs to be rewritten to ask u for the exact Gui hwnd instead of trying to figure that out on its own, and then u have to supply that Gui hwnd urself
User avatar
fade2gray
Posts: 85
Joined: 21 Apr 2015, 12:28

Re: Simple change to Gui breaks functionality

11 Feb 2023, 08:58

Thanks for the feedback @swagfag.

I came up with a compromise, by superimposing the checkboxes over progress bars, with the progress bars initially set at 0%, then set to 100% when the button is clicked.

gui2.png
gui2.png (4.59 KiB) Viewed 215 times

Code: Select all

Gui, Add, Tab3, w200, One|Two
Gui, Tab, 1
Gui, add, Text,, Some stuff here
Gui, Tab, 2
Gui, Add, Progress, w176 h19 w170 c60FF60 vPCB1 Disabled, 0
Gui, add, Checkbox, xp+3 yp+3 vCB1, Checkbox one
Gui, Add, Progress, xp-3 yp+24 w170 h19 c60FF60 vPCB2 Disabled, 0
Gui, add, Checkbox, xp+3 yp+3 vCB2, Checkbox two
Gui, Add, Button, gBtn, Button
Gui, Show
Return

Btn:
    Loop, 2{
        GuiControl,, PCB%A_Index%, 100
        GuiControl, Disabled, CB%A_Index%
        GuiControl,, CB%A_Index%, 0
    }
Return

GuiEscape:
GuiClose:
ExitApp

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: bobstoner289, peter_ahk, Spawnova and 357 guests