Retaining Toggle (Hide/Show) Between Script Runs

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Desdichado
Posts: 11
Joined: 04 Jun 2015, 16:57

Retaining Toggle (Hide/Show) Between Script Runs

26 Jun 2017, 19:56

Hello Community,

I am attempting to hide/show controls in a gui-based script, based upon a checkbox/radio button control; i.e., if a checkbox/radio button is checked on one tab, it will "unhide"/show the gui controls on other tabs.

I have the read/write of the checkbox/radio button controls to an .ini file worked out, thanks to the assistance of Boiler in a separate thread. I am, thanks to his/her assistance, able to save the checkbox/radio button/edit box control contents to an .ini file successfully, as well as read them when the script is run. Additionally, I am able to toggle the hidden controls on and off successfully when the script is running... however, when I close the script and rerun it, the hidden controls are hidden, despite the control type being checked.

I've cobbled a proof-of-concept script together using examples from the various threads that I could find that related to my need, please find the code enclosed below. I try to use simple proof-of-concept scripts so that I can understand what the various moving parts are actually doing before I incorporate them into more complex projects. I'd also like to thank those forum members (I can't remember whose scripts I bastardized; if you recognize your code in my test script, THANK YOU!!!).

The "More Options" checkbox in the script toggles and hides/shows the four hidden checkboxes below it. I am able to save the checkbox values for all the checkboxes in the script, but when I reload/close and re-open the script, the hidden checkboxes are default hidden, despite the "More Options" and the hidden checkboxes being checked. I'd like them to stay open/shown, if the "More Options" checkbox is ticked. I've looked at this until I'm cross-eyed. What am I missing? Any assistance is GREATLY APPRECIATED!

Best Regards,

Desdichado

Code: Select all

SetWorkingDir %A_ScriptDir%

ini := "TestSettings.ini"

IniRead, MOCB, %ini%, CheckState, MOCB
IniRead, cb1, %ini%, CheckState, CB1
IniRead, cb2, %ini%, CheckState, CB2
IniRead, cb3, %ini%, CheckState, CB3
IniRead, cb4, %ini%, CheckState, CB4
IniRead, oc1, %ini%, CheckState, OC1
IniRead, oc2, %ini%, CheckState, OC2
IniRead, oc3, %ini%, CheckState, OC3
IniRead, oc4, %ini%, CheckState, OC4

Gui, Add, checkbox, Checked%MOCB% gMoreOptions vMOCB, More Options

; ---------------- Will be Show/Hide ----------------
gui, font, cred
Gui, Add, checkbox, Checked%cb1% vcb1 section, hidden 1
Gui, Add, checkbox, Checked%cb2% vcb2, hidden 2
Gui, Add, checkbox, Checked%cb3% vcb3 ys, hidden 11
Gui, Add, checkbox, Checked%cb4% vcb4, hidden 22
gui, font
; ---------------- /Will be Show/Hide ----------------

Gui, Add, checkbox, Checked%oc1% voc1 xm, 3
Gui, Add, checkbox, Checked%oc2% voc2, 4
Gui, Add, checkbox, Checked%oc3% voc3, 5
Gui, Add, checkbox, Checked%oc4% voc4, 6

Gui, Add, Button, x125 y125 gSave, Save

Gui, Show

Gui +LastFound
WinGet, cList, ControlList
RegExReplace( cList, "`n", "", cnt )

MoreOptions:
Loop % ( cnt, i:=!i ) {
	GuiControlGet, hCon, Pos, cb%A_Index%
	GuiControlGet, oCon, Pos, oc%A_Index%
	GuiControl, % ( i ? "Hide" : "Show" ), cb%A_Index%
		RegExMatch(cY:=RegExReplace(cY.=oConY "|", "\d+\|\d+\|\K.*"), "(\d+)\|(\d+)", m)
		GuiControl, Move, oc%A_Index%, % "y" (A_Index<3 ? i ? hConY : m%A_Index% : i ? oConY-38 : oConY+38)
}
Return

Save:
Gui, Submit, NoHide
WinGetPos, Posx,Posy,,,Example
IniWrite, %MOCB%, %ini%, CheckState, MOCB
IniWrite, %cb1%, %ini%, CheckState, CB1
IniWrite, %cb2%, %ini%, CheckState, CB2
IniWrite, %cb3%, %ini%, CheckState, CB3
IniWrite, %cb4%, %ini%, CheckState, CB4
IniWrite, %oc1%, %ini%, CheckState, OC1
IniWrite, %oc2%, %ini%, CheckState, OC2
IniWrite, %oc3%, %ini%, CheckState, OC3
IniWrite, %oc4%, %ini%, CheckState, OC4
Reload
Return

GuiClose:
ExitApp
Desdichado
Posts: 11
Joined: 04 Jun 2015, 16:57

Re: Retaining Toggle (Hide/Show) Between Script Runs

27 Jun 2017, 12:07

I have moved away from the toggle option as described above, and am now exploring a function (ShowControl) I created that, if I am understanding all this correctly, will either GuiControl, Hide or GuiControl, Show based upon the value of a checkbox. It seems to me that this should be very simple, but I can't seem to get the function to work. As I just started using functions, any and all input would be appreciated.

Thanks,

Desdichado

P.S. Here's my latest code:

Code: Select all

SetWorkingDir %A_ScriptDir%

ini := "TestSettings.ini"

IniRead, MOCB, %ini%, CheckState, MOCB
IniRead, cb1, %ini%, CheckState, CB1
IniRead, cb2, %ini%, CheckState, CB2
IniRead, cb3, %ini%, CheckState, CB3
IniRead, cb4, %ini%, CheckState, CB4
IniRead, oc1, %ini%, CheckState, OC1
IniRead, oc2, %ini%, CheckState, OC2
IniRead, oc3, %ini%, CheckState, OC3
IniRead, oc4, %ini%, CheckState, OC4

ShowControl(MOCB, cb1)

Gui, Add, checkbox, Checked%MOCB% gMoreOptions vMOCB, More Options

; ---------------- Will be Show/Hide ----------------
gui, font, cred
Gui, Add, checkbox, Checked%cb1% vcb1 section, hidden 1
Gui, Add, checkbox, Checked%cb2% vcb2, hidden 2
Gui, Add, checkbox, Checked%cb3% vcb3 ys, hidden 11
Gui, Add, checkbox, Checked%cb4% vcb4, hidden 22
gui, font
; ---------------- /Will be Show/Hide ----------------

Gui, Add, checkbox, Checked%oc1% voc1 xm, 3
Gui, Add, checkbox, Checked%oc2% voc2, 4
Gui, Add, checkbox, Checked%oc3% voc3, 5
Gui, Add, checkbox, Checked%oc4% voc4, 6

Gui, Add, Button, x125 y125 gSave, Save

Gui, Show

Gui +LastFound
WinGet, cList, ControlList
RegExReplace( cList, "`n", "", cnt )

MoreOptions:
;~ Loop % ( cnt, i:=!i ) {
	;~ GuiControlGet, hCon, Pos, cb%A_Index%
	;~ GuiControlGet, oCon, Pos, oc%A_Index%
	;~ GuiControl, % ( i ? "Hide" : "Show" ), cb%A_Index%
		;~ RegExMatch(cY:=RegExReplace(cY.=oConY "|", "\d+\|\d+\|\K.*"), "(\d+)\|(\d+)", m)
		;~ GuiControl, Move, oc%A_Index%, % "y" (A_Index<3 ? i ? hConY : m%A_Index% : i ? oConY-38 : oConY+38)
;~ }
Return

Save:
Gui, Submit, NoHide
WinGetPos, Posx,Posy,,,Example
IniWrite, %MOCB%, %ini%, CheckState, MOCB
IniWrite, %cb1%, %ini%, CheckState, CB1
IniWrite, %cb2%, %ini%, CheckState, CB2
IniWrite, %cb3%, %ini%, CheckState, CB3
IniWrite, %cb4%, %ini%, CheckState, CB4
IniWrite, %oc1%, %ini%, CheckState, OC1
IniWrite, %oc2%, %ini%, CheckState, OC2
IniWrite, %oc3%, %ini%, CheckState, OC3
IniWrite, %oc4%, %ini%, CheckState, OC4
Reload
Return

GuiClose:
ExitApp

;======================================================

ShowControl(Val, Cont){
If (Val=1)
	GuiControl, Show, Cont
Else
	GuiControl, Hide, Cont
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 239 guests