Checkbox failure

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Liaxim
Posts: 35
Joined: 09 Jan 2020, 05:14

Checkbox failure

24 Mar 2020, 10:19

Hey guys, I need some help with this script. I have the problem that this Checkbox should enable or disable the Edit boxes and this should be saved into the ini..
if the checkbox is reopened the checkbox should be enabled or dissabled. I have the problem that the Checkbox var is = 0 but the Checkbox isn´t enabled.
How is this working? Hope anyone know how to fix this..

Code: Select all

Gui, EmailServices: Default
IniRead,WebCheckBox,Settings.ini, Email, WebCheckBox ; Reads if what the Checkbox is (1 or 0)
Gui, Add, CheckBox, x10 y9 w70 h30 vWebCheckBox gWebCheckBox, Webmail ; Don´t change to the Value which is saved.. 
Gui, Add, Edit, x82 y13 w100 h20 disabled vWebEmail, Email ;Edit is activated by clicking on the checkbox..
Gui, Add, Edit, x192 y13 w100 h20 disabled vWebPassword, Password ;Edit is activated by clicking on the checkbox..
Gui, Add, Button, x300 y13 w35 h20 gWebsave, Save

Gui, Show, NA x5 y5 w750 h345
return


WebCheckBox:
guicontrolget, WebCheckBox
if WebCheckBox = 1
{
IniWrite, %WebCheckBox%, Settings.ini, Email, WebCheckBox ;Saves if the Checkbox is set to 1
IniRead, tempWebEmail, Settings.ini, Email, tempWebEmail
IniRead, tempWebPassword, Settings.ini, Email, tempWebPassword
WebEmail := b64Decode(tempWebEmail)
WebPassword := b64Decode(tempWebPassword)
guicontrol, Enable, WebEmail
guicontrol, ,  WebEmail
guicontrol, ,  WebEmail, %WebEmail%
guicontrol, Enable,  WebPassword
guicontrol, +Password,  WebPassword
guicontrol, ,  WebPassword, %WebPassword%
}
else
{
IniWrite, %WebCheckBox%, Settings.ini, Email, WebCheckBox ;Saves if the Checkbox is set to 0
guicontrol, -Password,  WebEmail
guicontrol, Disable,  WebEmail
guicontrol, ,  WebEmail, Email
guicontrol, -Password,  WebPassword
guicontrol, Disable,  WebPassword
guicontrol, ,  WebPassword, Password
}
return
User avatar
Delta Pythagorean
Posts: 628
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: Checkbox failure

24 Mar 2020, 19:00

Hi, Liaxim!

To check a checkbox upon adding the control, you must add the Checked option to the checkbox. To add that into the options, I recommend doing something like this:

Code: Select all

WebCheckBox := 1
Gui, Add, CheckBox, Checked%WebCheckBox%, I'm checked!
WebNotCheckBox := 0
Gui, Add, CheckBox, Checked%WebNotCheckBox%, I'm NOT checked!
For more information on what I just posted, look here and look at the Check option.

Cheers, Delta.

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

Liaxim
Posts: 35
Joined: 09 Jan 2020, 05:14

Re: Checkbox failure

25 Mar 2020, 12:49

Thanks man,
That worked. I have another question ^^...
The Checkbox is now checked if I close and reopen the program, but the problem is that the edit boxes which are enabled and disabled are not working..They are just showing the Text field again if I disable and enable the checkbox. how to fix that?

Code: Select all

Gui, EmailServices: Default
IniRead,WebCheckBox,Settings.ini, Email, WebCheckBox ; Reads if what the Checkbox is (1 or 0)
Gui, Add, CheckBox, x10 y9 w70 h30 vWebCheckBox gWebCheckBox, Webmail ; the gWebCheckBox isn´t working..
Gui, Add, Edit, x82 y13 w100 h20 disabled vWebEmail, Email ;Edit is activated by clicking on the checkbox..
Gui, Add, Edit, x192 y13 w100 h20 disabled vWebPassword, Password ;Edit is activated by clicking on the checkbox..
Gui, Add, Button, x300 y13 w35 h20 gWebsave, Save

Gui, Show, NA x5 y5 w750 h345
return


WebCheckBox:
guicontrolget, WebCheckBox
if WebCheckBox = 1
{
IniWrite, %WebCheckBox%, Settings.ini, Email, WebCheckBox ;Saves if the Checkbox is set to 1
IniRead, tempWebEmail, Settings.ini, Email, tempWebEmail
IniRead, tempWebPassword, Settings.ini, Email, tempWebPassword
WebEmail := b64Decode(tempWebEmail)
WebPassword := b64Decode(tempWebPassword)
guicontrol, Enable, WebEmail
guicontrol, ,  WebEmail
guicontrol, ,  WebEmail, %WebEmail%
guicontrol, Enable,  WebPassword
guicontrol, +Password,  WebPassword
guicontrol, ,  WebPassword, %WebPassword%
}
else
{
IniWrite, %WebCheckBox%, Settings.ini, Email, WebCheckBox ;Saves if the Checkbox is set to 0
guicontrol, -Password,  WebEmail
guicontrol, Disable,  WebEmail
guicontrol, ,  WebEmail, Email
guicontrol, -Password,  WebPassword
guicontrol, Disable,  WebPassword
guicontrol, ,  WebPassword, Password
}
return
User avatar
Delta Pythagorean
Posts: 628
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: Checkbox failure

25 Mar 2020, 19:36

Hi again, Liaxim!

From what I tested, by the code you just provided, your example works on my end. I don't know why it would not work for you.
One recommendation I can give is to use the GuiName in the GuiControl command like so:

Code: Select all

GuiControl, 1:Move, EditControl, w500 h600
GuiControl, Samuel:, EditControl, New text to work with.
GuiControl, 5:Choose, DropDownControl, 4
If you have any further questions, don't be afraid to ask.

Cheers, Delta.

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

Liaxim
Posts: 35
Joined: 09 Jan 2020, 05:14

Re: Checkbox failure

26 Mar 2020, 14:11

I tried this but it just don´t enable the edits again after checking the box..
Sry I am not that good in programming. It´s my first programming language after some tries with c ^^

Code: Select all

Gui, EmailServices: Default
IniRead,WebCheckBox,Settings.ini, Email, WebCheckBox ; Reads if what the Checkbox is (1 or 0)
Gui, Add, CheckBox, x10 y9 w70 h30 vWebCheckBox checked%WebCheckBox% gWebCheckBox, Webmail
Gui, Add, Edit, x82 y13 w100 h20 disabled vWebEmail, Email
Gui, Add, Edit, x192 y13 w100 h20 disabled vWebPassword, Password
Gui, Add, Button, x300 y13 w35 h20 gWebsave, Save

Gui, Show, NA x5 y5 w750 h345
return


WebCheckBox:
guicontrolget, WebCheckBox
if WebCheckBox = 1
{
IniWrite, %WebCheckBox%, Settings.ini, Settings, WebCheckBox
IniRead, tempWebEmail, Settings.ini, Email, tempWebEmail
IniRead, tempWebPassword, Settings.ini, Email, tempWebPassword
WebEmail := b64Decode(tempWebEmail)
WebPassword := b64Decode(tempWebPassword)
guicontrol, Enable, WebEmail
guicontrol, ,  WebEmail
guicontrol, ,  WebEmail, %WebEmail%
guicontrol, Enable,  WebPassword
guicontrol, +Password,  WebPassword
guicontrol, ,  WebPassword, %WebPassword%
}
else
{
IniWrite, %WebCheckBox%, Settings.ini, Settings, WebCheckBox
guicontrol, -Password,  WebEmail
guicontrol, Disable,  WebEmail
guicontrol, ,  WebEmail, Email
guicontrol, -Password,  WebPassword
guicontrol, Disable,  WebPassword
guicontrol, ,  WebPassword, Password
}
return

Websave:
Gui, Submit,NoHide
tempWebEmail := b64Encode(WebEmail)
tempWebPassword := b64Encode(WebPassword)
IniWrite, %tempWebEmail%, Settings.ini, Email, tempWebEmail
IniWrite, %tempWebPassword%, Settings.ini, Email, tempWebPassword
IniRead, tempWebEmail, Settings.ini, Email, tempWebEmail
IniRead, tempWebPassword, Settings.ini, Email, tempWebPassword
Return

b64Encode(string)
{
    VarSetCapacity(bin, StrPut(string, "UTF-8")) && len := StrPut(string, &bin, "UTF-8") - 1 
    if !(DllCall("crypt32\CryptBinaryToString", "ptr", &bin, "uint", len, "uint", 0x1, "ptr", 0, "uint*", size))
        throw Exception("CryptBinaryToString failed", -1)
    VarSetCapacity(buf, size << 1, 0)
    if !(DllCall("crypt32\CryptBinaryToString", "ptr", &bin, "uint", len, "uint", 0x1, "ptr", &buf, "uint*", size))
        throw Exception("CryptBinaryToString failed", -1)
    return StrGet(&buf)
}

b64Decode(string)
{
    if !(DllCall("crypt32\CryptStringToBinary", "ptr", &string, "uint", 0, "uint", 0x1, "ptr", 0, "uint*", size, "ptr", 0, "ptr", 0))
        throw Exception("CryptStringToBinary failed", -1)
    VarSetCapacity(buf, size, 0)
    if !(DllCall("crypt32\CryptStringToBinary", "ptr", &string, "uint", 0, "uint", 0x1, "ptr", &buf, "uint*", size, "ptr", 0, "ptr", 0))
        throw Exception("CryptStringToBinary failed", -1)
    return StrGet(&buf, size, "UTF-8")
}

Return to “Ask for Help (v1)”

Who is online

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