#Include <GUIConstantsEx.au3>
Global Const $REG_KEY_NAME = 'HKCU\SOFTWARE\MyProgram'
$cParam1 = 1 ; Checkbox1
$cParam2 = 0 ; Checkbox2
$cParam3 = 0 ; Checkbox3
$cParam4 = 1 ; Checkbox4
$cParam5 = 0 ; 0 - Radio1; 1 - Radio2; 2 - Radio3; etc
$cParam6 = 'Simple Text' ; Input
_ReadRegistry()
GUICreate('MyGUI', 400, 400)
$Checkbox1 = GUICtrlCreateCheckbox('Checkbox 1', 10, 10, 100, 20)
GUICtrlSetState(-1, BitOR($GUI_CHECKED * $cParam1, $GUI_UNCHECKED * (Not $cParam1)))
$Checkbox2 = GUICtrlCreateCheckbox('Checkbox 2', 10, 32, 100, 20)
GUICtrlSetState(-1, BitOR($GUI_CHECKED * $cParam2, $GUI_UNCHECKED * (Not $cParam2)))
$Checkbox3 = GUICtrlCreateCheckbox('Checkbox 3', 10, 54, 100, 20)
GUICtrlSetState(-1, BitOR($GUI_CHECKED * $cParam3, $GUI_UNCHECKED * (Not $cParam3)))
$Checkbox4 = GUICtrlCreateCheckbox('Checkbox 4', 10, 76, 100, 20)
GUICtrlSetState(-1, BitOR($GUI_CHECKED * $cParam4, $GUI_UNCHECKED * (Not $cParam4)))
GUIStartGroup()
$Radio1 = GUICtrlCreateRadio('Radio 1', 150, 10, 100, 20)
GUICtrlSetState(-1, BitOR($GUI_CHECKED * ($cParam5 = 0), $GUI_UNCHECKED * ($cParam5 <> 0)))
$Radio2 = GUICtrlCreateRadio('Radio 2', 150, 32, 100, 20)
GUICtrlSetState(-1, BitOR($GUI_CHECKED * ($cParam5 = 1), $GUI_UNCHECKED * ($cParam5 <> 1)))
$Radio3 = GUICtrlCreateRadio('Radio 3', 150, 54, 100, 20)
GUICtrlSetState(-1, BitOR($GUI_CHECKED * ($cParam5 = 2), $GUI_UNCHECKED * ($cParam5 <> 2)))
$ButtonSave = GUICtrlCreateButton('Save && Exit', 155, 368, 90, 23)
GUiSetState()
$Input = GUICtrlCreateInput($cParam6, 10, 110, 240, 20)
While 1
$Msg = GUIGetMsg()
Switch $Msg
Case $GUI_EVENT_CLOSE
ExitLoop
Case $ButtonSave
$cParam1 = (GUICtrlRead($Checkbox1) = $GUI_CHECKED)
$cParam2 = (GUICtrlRead($Checkbox2) = $GUI_CHECKED)
$cParam3 = (GUICtrlRead($Checkbox3) = $GUI_CHECKED)
$cParam4 = (GUICtrlRead($Checkbox4) = $GUI_CHECKED)
$cParam5 = BitOR((GUICtrlRead($Radio2) = $GUI_CHECKED) * 1, (GUICtrlRead($Radio3) = $GUI_CHECKED) * 2)
$cParam6 = GUICtrlRead($Input)
_WriteRegistry()
ExitLoop
EndSwitch
WEnd
Func _ReadRegistry()
$cParam1 = _ValueCheck(_RegRead($REG_KEY_NAME, 'Param1', 'REG_DWORD', $cParam1), 0, 1)
$cParam2 = _ValueCheck(_RegRead($REG_KEY_NAME, 'Param2', 'REG_DWORD', $cParam2), 0, 1)
$cParam3 = _ValueCheck(_RegRead($REG_KEY_NAME, 'Param3', 'REG_DWORD', $cParam3), 0, 1)
$cParam4 = _ValueCheck(_RegRead($REG_KEY_NAME, 'Param4', 'REG_DWORD', $cParam4), 0, 1)
$cParam5 = _ValueCheck(_RegRead($REG_KEY_NAME, 'Param5', 'REG_DWORD', $cParam5), 0, 2)
$cParam6 = _RegRead($REG_KEY_NAME, 'Param6', 'REG_SZ', $cParam6)
EndFunc ;==>_ReadRegistry
Func _RegRead($Key, $Value, $Type, $Default)
Local $Val = RegRead($Key, $Value)
If @error Then
RegWrite($Key, $Value, $Type, $Default)
Return $Default
EndIf
Switch StringUpper($Type)
Case 'REG_SZ', 'REG_MULTI_SZ', 'REG_EXPAND_SZ'
If Not IsString($Val) Then
Return SetError(1, 0, $Default)
EndIf
Case 'REG_BINARY'
If Not IsBinary($Val) Then
Return SetError(1, 0, $Default)
EndIf
Case 'REG_DWORD'
If Not IsInt($Val) Then
Return SetError(1, 0, $Default)
EndIf
Case Else
Return SetError(1, 0, $Default)
EndSwitch
Return $Val
EndFunc ;==>_RegRead
Func _ValueCheck($iValue, $iMin, $iMax)
If $iValue < $iMin Then
Return $iMin
EndIf
If $iValue > $iMax Then
Return $iMax
EndIf
Return $iValue
EndFunc ;==>_ValueCheck
Func _WriteRegistry()
RegWrite($REG_KEY_NAME, 'Param1', 'REG_DWORD', $cParam1)
RegWrite($REG_KEY_NAME, 'Param2', 'REG_DWORD', $cParam2)
RegWrite($REG_KEY_NAME, 'Param3', 'REG_DWORD', $cParam3)
RegWrite($REG_KEY_NAME, 'Param4', 'REG_DWORD', $cParam4)
RegWrite($REG_KEY_NAME, 'Param5', 'REG_DWORD', $cParam5)
RegWrite($REG_KEY_NAME, 'Param6', 'REG_SZ', $cParam6)
EndFunc ;==>_WriteRegistry