Jump to content

problem with input and checkbox


CWorks
 Share

Recommended Posts

so here's the problem I have

it works fine as long as checkbox is chosen before entering input otherwise checkbox2 is used every time

every time i fix one thing i seem to break another

also i tend to forget things so all the "don't forget to remove" comments are meant for me :P

#include <guiconstants.au3>
#include <string.au3>
$dog = "dog"

; work damn it
; don't forget to remove
Pass()

#comments-start
$PassWord = IniRead("ScreenLock.ini", "Password", "key", "")
;MsgBox(0, "IniRead Result", $PassWord)
If $PassWord = "" Then
    $PassWord = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Andy\ScreenLock", "Password")
EndIf
If $PassWord <> "" Then
    $PassWord = _StringEncrypt(0, $PassWord, "4471")

                              ; don't forget to remove
                              MsgBox(0, "decrypt Result", $PassWord)
Else
    Pass()
EndIf
#comments-end

Func Pass()
    GUICreate("ScreenLock", 309, 99, -1, -1)
    $PassInput = GUICtrlCreateInput("Password", 8, 32, 153, 21, -1, $WS_EX_CLIENTEDGE)
    $Checkbox1 = GUICtrlCreateCheckbox("Write to ScreenLock.ini", 176, 8, 129, 17)
    $Button1 = GUICtrlCreateButton("OK", 48, 64, 89, 25)
    $Button2 = GUICtrlCreateButton("Cancel", 176, 64, 89, 25)
    GUICtrlCreateLabel("Enter Password", 24, 8, 78, 17)
    $Checkbox2 = GUICtrlCreateCheckbox("Write to Registry", 176, 32, 105, 17)
    GUICtrlSetState(-1, $GUI_CHECKED)
    GUISetState(@SW_SHOW)
    
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE Or $msg = $Button2
                ExitLoop
                
             Case $msg = $Button1 And $dog = "cat"
                ;If GUICtrlRead($Checkbox1) = $GUI_UNCHECKED Or GUICtrlRead($Checkbox2) = $GUI_UNCHECKED Then
                ;   MsgBox(16, "error", "Need to select something.")
                Exit
    
            Case $msg = $PassInput
                $PassWord = GUICtrlRead($PassInput)
                ;   If GUICtrlRead($PassWord)  = "" Then
                If $PassWord = "" Then
                    MsgBox(16, "error", "Invalid password.")
                    
                                    ; don't forget to remove
                                    ;MsgBox(0, "crap", $PassWord)
                    Pass()
                Else
                    
                    If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
                        ;$PassWord = _StringEncrypt(1, $PassWord, "4471")
                        ;IniWrite("ScreenLock.ini", "Password", "key", $PassWord)
                        $dog = "cat"
                                    ; don't forget to remove
                                    MsgBox(0, "ini selected", $PassWord)
                                    Exit
                Else
                    ;If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then ; does nothing
                        ;RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Andy\ScreenLock", "Password", "REG_SZ", _StringEncrypt(1, $PassWord, "4471"))
                        $dog = "cat"
                                    ; don't forget to remove
                                    MsgBox(0, "reg selected", $PassWord)
                                    Exit
                    EndIf
                EndIf
;EndIf              
            Case $msg = $Checkbox2
                If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then
                    GUICtrlSetState($Checkbox1, $GUI_UNCHECKED)
                EndIf
            Case $msg = $Checkbox1
                If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
                    GUICtrlSetState($Checkbox2, $GUI_UNCHECKED)
                EndIf
                
        EndSelect
    WEnd
    Exit
EndFunc
Edited by CWorks
Link to comment
Share on other sites

I don't understand what's wrong. What is it doing, versus what is it supposed to be doing?

Also, you might want to go with Radio buttons instead of checkboxes. That's usually what is used if you want to indicate to the user that it's meant to toggle between multiple choices.

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Link to comment
Share on other sites

it's good to go now :P

and you were right about using radio buttons since only one can be selected I just liked checkboxes but not anymore

also shotened my code by getting rid of an unneeded Case and just put it under $Button1

#include <guiconstants.au3>
#include <string.au3>
Dim $PassWord

GUICreate("ScreenLock", 310, 99, 481, 371)
$PassInput = GUICtrlCreateInput("Password", 8, 32, 153, 21, -1, $WS_EX_CLIENTEDGE)
$Button1 = GUICtrlCreateButton("OK", 48, 64, 89, 25)
GUICtrlCreateLabel("Enter Password", 24, 8, 78, 17)
$Button2 = GUICtrlCreateButton("Cancel", 176, 64, 89, 25)
$Radio1 = GUICtrlCreateRadio("Write to ScreenLock.ini", 176, 8, 129, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$Radio2 = GUICtrlCreateRadio("Write to Registry", 176, 32, 97, 17)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Button2
            ExitLoop
            
        Case $msg = $Button1 And $PassWord <> ""
            If GUICtrlRead($Radio1) = $GUI_CHECKED Then
                $PassWord = _StringEncrypt(1, $PassWord, "4471")
                ;IniWrite("ScreenLock.ini", "Password", "key", $PassWord)
                ; don't forget to remove
                MsgBox(0, "ini selected", $PassWord)
                Exit
            Else
                ;RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Andy\ScreenLock", "Password", "REG_SZ", _StringEncrypt(1, $PassWord, "4471"))
                ; don't forget to remove
                MsgBox(0, "reg selected", $PassWord)
                Exit
            EndIf
        Case $msg = $PassInput
            $PassWord = GUICtrlRead($PassInput)
            If $PassWord = "" Then
                MsgBox(16, "error", "Invalid password.")
            EndIf
    EndSelect
WEnd
Exit
Edited by CWorks
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...