In this GUI I make two BIG checkboxes.
When one is checked - the other is unchecked. (like a radio button)
and at the same time the text is changed (in the same way)
This text script works (as desired)
Code without function() - Works!
Code: Select all
#NoEnv
#SingleInstance force
; Gui Create
Wide = 400
; Gui 1: Default
Gui 1: Color, 0xFFA500 ; Orange
; Gui 1: Color, 0x00FF00 ; Green
Gui 1: +AlwaysOnTop hwndGuiHwnd ; This option stores the window handle (HWND) of the GUI in OutputVar (GuiHwnd)
; Gui +Resize ; Allow the user to maximize or drag-resize the window:
Gui 1: Font, cBlack s14 Bold, Verdana
Gui 1: Add, Text, x0 y10 h25 w%Wide% +Center vInfoTxt1, Test - BIG checkbox!
; Gui 1: Add, Text, x120 y10 h25 w250 vInfoTxt1, Välj fil från listan!
Gui 1: Font, cBlue s25, Wingdings
Gui 1: Add, Text, x50 y80 w25 h25 0x6 vU1
Gui 1: Add, Text, xp yp w25 h25 0x12
Gui 1: Add, Text, xp yp w25 h25 0x200 center BackgroundTrans vmyBigCheckBox1 gBigCheckBox1
Gui 1: Font, cBlack s16 Normal, Arial
Gui 1: Add, Text, xp+40 yp h25 w200 Left vU2, % "One choice"
Gui 1: Font, cBlue s25, Wingdings
Gui 1: Add, Text, x50 y110 w25 h25 0x6 vO1
Gui 1: Add, Text, xp yp w25 h25 0x12
Gui 1: Add, Text, xp yp w25 h25 0x200 center BackgroundTrans vmyBigCheckBox2 gBigCheckBox2
Gui 1: Font, cBlack s16 Normal, Arial
Gui 1: Add, Text, xp+40 yp h25 w200 Left vO2, % "Another choice"
Gui 1: Add, Button, x200 yp+50 h40 w100 +Center disabled vButtOK gButtonOK, OK
Gui 1:Show, x100 y100 h250 w%Wide%, TextBox test - 2020
Return
ButtonOK:
; Resultat
; Gui 1: Submit, NoHide
MsgBox 64, Rad.: %A_LineNumber% -> %A_ScriptName%, % "Checkbox 1 .: " myBigCheckBox1 "`nCheckBox 2 .: " myBigCheckBox2
Return
BigCheckBox1:
GuiControl 1:, myBigCheckBox1, % ( myBigCheckBox1 := !myBigCheckBox1 ) ? Chr(252) : ""
Gui 1:Font, cBlue s16 Bold, Arial
GuiControl 1: Font, U2
GuiControl 1:, myBigCheckBox2, % ( myBigCheckBox2 := False ) ? Chr(252) : ""
Gui 1:Font, cBlack s16 Normal, Arial
GuiControl 1: Font, O2
If !myBigCheckBox1 and !myBigCheckBox2
{ Gui 1:Font, cBlack s16 Normal, Arial
GuiControl 1: Font, U2
GuiControl 1: Font, O2
GuiControl 1: Disable, ButtOK
}
else
GuiControl 1: Enable, ButtOK
; MsgBox ,, Row.: %A_LineNumber%, % "Checkbox 1 .: " myBigCheckBox1 "`nCheckBox 2 .: " myBigCheckBox2
ToolTip % "Row .: " A_lineNumber "`nCheckbox 1 .: " myBigCheckBox1 "`nCheckBox 2 .: " myBigCheckBox2
Return
BigCheckBox2:
GuiControl 1:, myBigCheckBox2, % ( myBigCheckBox2 := !myBigCheckBox2 ) ? Chr(252) : ""
Gui 1:Font, cBlue s16 Bold, Arial
GuiControl 1: Font, O2
GuiControl 1:, myBigCheckBox1, % ( myBigCheckBox1 := False ) ? Chr(252) : ""
Gui 1:Font, cBlack s16 Normal, Arial
GuiControl 1: Font, U2
If !myBigCheckBox1 and !myBigCheckBox2
{ Gui 1:Font, cBlack s16 Normal, Arial
GuiControl 1: Font, U2
GuiControl 1: Font, O2
GuiControl 1: Disable, ButtOK
}
else
GuiControl 1: Enable, ButtOK
; MsgBox ,, Row.: %A_LineNumber%, % "Checkbox 1 .: " myBigCheckBox1 "`nCheckBox 2 .: " myBigCheckBox2
ToolTip % "Row .: " A_lineNumber "`nCheckbox 1 .: " myBigCheckBox1 "`nCheckBox 2 .: " myBigCheckBox2
Return
1GuiClose: ; Indicate that the script should exit automatically when the window is closed.
ExitApp
ESC::
{ ; MsgBox ,,, This program ends!, 1
ExitApp
}
When I try to put this GUI (above) - in a function() - some features stop working...
(with strategy by @just me - To use GUI in a function() - risky or easy or the original link GUI in Function)
The GUI above in a function() (doesn't work)
Code: Select all
; Version 28 maj 2020
#NoEnv
#SingleInstance force
funcResult := FuncCheckBox()
MsgBox 64, Row.: %A_LineNumber%, % funcResult
ExitApp
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FuncCheckBox()
{ ; Create the Gui
; - - -- - - -
Static Header
, U1, U2, O1, O2
, myBigCheckBox1, myBigCheckBox2
, ButtOK
; Create the GUI
Wide = 400
Gui, +LastFound ; Sets the window to be the "Last Found Window"
; Gui 1: Default
Gui 1: Color, 0xFFA500 ; Orange
Gui 1: +AlwaysOnTop hwndGuiHwnd ; This option stores the window handle (HWND) of the GUI in OutputVar (GuiHwnd)
; Gui +Resize ; Allow the user to maximize or drag-resize the window:
Gui 1: Font, cBlack s14 Bold, Verdana
Gui 1: Add, Text, x0 y10 h25 w%Wide% +Center vHeader, Test - BIG checkbox!
; Big check box1
Gui 1: Font, cBlue s25, Wingdings
Gui 1: Add, Text, x50 y80 w25 h25 0x6 vU1
Gui 1: Add, Text, xp yp w25 h25 0x12
Gui 1: Add, Text, xp yp w25 h25 0x200 center BackgroundTrans vmyBigCheckBox1 gBigCheckBox1
Gui 1: Font, cBlack s16 Normal, Arial
Gui 1: Add, Text, xp+40 yp h25 w200 Left vU2, % "One choice"
; Big check box2
Gui 1: Font, cBlue s25, Wingdings
Gui 1: Add, Text, x50 y110 w25 h25 0x6 vO1
Gui 1: Add, Text, xp yp w25 h25 0x12
Gui 1: Add, Text, xp yp w25 h25 0x200 center BackgroundTrans vmyBigCheckBox2 gBigCheckBox2
Gui 1: Font, cBlack s16 Normal, Arial
Gui 1: Add, Text, xp+40 yp h25 w200 Left vO2, % "Another choice"
; Button
Gui 1: Add, Button, x200 yp+50 h40 w100 +Center vButtOK disabled gButtonOK, OK
Gui 1:Show, x100 y100 h250 w%Wide%, TextBox test - 2020
WinWaitActive ;If all window parameters are blank or omitted, the "Last Found Window" will be used.
WinWaitClose ;Same as above
Return % Result
1GuiClose: ; Indicate that the script should exit automatically when the window is closed.
ButtonOK:
; Resultat
; Gui 1: Submit, NoHide
MsgBox ,, Rad.: %A_LineNumber% -> %A_ScriptName%, % "GUI exit! `n`nCheckbox 1 .: " myBigCheckBox1 "`nCheckBox 2 .: " myBigCheckBox2
Gui, Destroy ;'Close' the GUI window and 'free' GUI variables
Return
BigCheckBox1:
GuiControl 1:, myBigCheckBox1, % ( myBigCheckBox1 := !myBigCheckBox1 ) ? Chr(252) : ""
Gui 1:Font, cBlue s16 Bold, Arial
GuiControl 1: Font, U2
GuiControl 1:, myBigCheckBox2, % ( myBigCheckBox2 := False ) ? Chr(252) : ""
Gui 1:Font, cBlack s16 Normal, Arial
GuiControl 1: Font, O2
If !myBigCheckBox1 and !myBigCheckBox2
{ Gui 1:Font, cBlack s16 Normal, Arial
GuiControl 1: Font, U2
GuiControl 1: Font, O2
GuiControl 1: Disable, ButtOK
}
else
GuiControl 1: Enable, ButtOK
Result := "`nCheckbox 1 .: " myBigCheckBox1 "`nCheckBox 2 .: " myBigCheckBox2
; MsgBox ,, Row.: %A_LineNumber%, % "Checkbox 1 .: " myBigCheckBox1 "`nCheckBox 2 .: " myBigCheckBox2
ToolTip % "Row .: " A_lineNumber "`nCheckbox 1 .: " myBigCheckBox1 "`nCheckBox 2 .: " myBigCheckBox2
Return
BigCheckBox2:
GuiControl 1:, myBigCheckBox2, % ( myBigCheckBox2 := !myBigCheckBox2 ) ? Chr(252) : ""
Gui 1:Font, cBlue s16 Bold, Arial
GuiControl 1: Font, O2
GuiControl 1:, myBigCheckBox1, % ( myBigCheckBox1 := False ) ? Chr(252) : ""
Gui 1:Font, cBlack s16 Normal, Arial
GuiControl 1: Font, U2
If !myBigCheckBox1 and !myBigCheckBox2
{ Gui 1:Font, cBlack s16 Normal, Arial
GuiControl 1: Font, U2
GuiControl 1: Font, O2
GuiControl 1: Disable, ButtOK
}
else
GuiControl 1: Enable, ButtOK
Result := "`nCheckbox 1 .: " myBigCheckBox1 "`nCheckBox 2 .: " myBigCheckBox2
; MsgBox ,, Row.: %A_LineNumber%, % "Checkbox 1 .: " myBigCheckBox1 "`nCheckBox 2 .: " myBigCheckBox2
ToolTip % "Row .: " A_lineNumber "`nCheckbox 1 .: " myBigCheckBox1 "`nCheckBox 2 .: " myBigCheckBox2
Return
}
ESC::
{ ; MsgBox ,,, This program ends!, 1
ExitApp
}
One way to solve this is to change all variables in the function from Static
Code: Select all
Static Header
, U1, U2, O1, O2
, myBigCheckBox1, myBigCheckBox2
, ButtOK
Code: Select all
Global Header
, U1, U2, O1, O2
, myBigCheckBox1, myBigCheckBox2
, ButtOK
Is it possible to solve another way?