Jump to content

GUI Sizing Problem


BrettF
 Share

Recommended Posts

Problem:

Ok, I'm creating a simple Username/Password input box, and I cannot for my life work out why the GUI is default height! I added error checking in my script, yet it still doesn't work... what am I missing. Please help. :)

Code:

$ret = _LoginBox("Enter Credentials", "Please enter you username and password", "user", "pass", -1, -1, -1, -1, 2000)
MsgBox(0, "Returned", "Returned: " & $ret & @CRLF & "Error Code: " & @error & @CRLF & "Extended: " & @extended)
If Not $ret = 1 Then
    MsgBox(0, "Credentails Returned", "Username: " & $ret[0] & @CRLF & "Password: " & $ret[1])
EndIf
;===============================================================================
;
; Function Name:        _LoginBox
; Description::         Create a basic login box with Username, Password, and a prompt.
; Parameter(s):         Title       - [Required]
;                                       - The title of the Form
;                       Prompt      - [Required]
;                                       - The prompt for the user
;                       uDefault    - [Optional] - Default Value = ""
;                                       - The default vaue for the Username Input
;                       pDefault    - [Optional] - Default Value = ""
;                                       - The default vaue for the Password Input
;                       Width       - [Optional] - Default Value = 250
;                                       - The width of the Login Box
;                       Height      - [Optional] - Default Value = 130
;                                       - The height of the Login Box
;                       Left        - [Optional] - Default Value = Auto Center Screen
;                                       - The positioning (Left) of the Login Box
;                       Top         -  [Optional] - Default Value = Auto Center Screen
;                                       - The positioning (Top) of the Login Box
;                       Timeout     - [Optional] - Default Value = -1 (No Timeout)
;                                       - The timeout of the Login Box
; Requirement(s):       none
; Return Value(s):      Success:
;                           - Sets @error to 1
;                           - Returns a 1D array with the following
;                               - [0] = Username
;                               - [1] = Password
;                       Failure
;                           - Sets @error to 0
;                           - Sets @extended to:
;                               - 1 - The Cancel or Exit Button was Pressed
;                               - 2 - The Login Box Timed Out.
; Author(s):            Brett Francis (exodus.is.me@hotmail.com)
; Note(s):               none
;
;===============================================================================

Func _LoginBox($title, $prompt, $uDefault = "", $pDefault = "", $width = 250, $height = 130, $left = 0, $top = 0, $timeout = -1)
    #include <GUIConstants.au3>
    Select
        Case $uDefault = -1
            $uDefault = ""
        Case $pDefault = -1
            $pDefault = ""
        Case $width = -1
            $width = 250
        Case $height = -1
            $height = 130
        Case $left = -1
            $left = (@DesktopWidth / 2) - ($width / 2)
        Case $top = -1
            $top = (@DesktopHeight / 2) - ($height / 2)
    EndSelect
    
    Local $retarr[2]
    $gui = GUICreate($title, $width, $height, $left, $top)
    $username = GUICtrlCreateInput($uDefault, 72, 42, 173, 21)
    $password = GUICtrlCreateInput($pDefault, 72, 70, 173, 21, $ES_PASSWORD)
    $okbtn = GUICtrlCreateButton("&OK", 90, 96, 75, 25, 0)
    $cancelbtn = GUICtrlCreateButton("&Cancel", 171, 96, 75, 25, 0)
    $Label1 = GUICtrlCreateLabel("Password:", 4, 72, 62, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Label1 = GUICtrlCreateLabel("Username:", 4, 44, 64, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Label2 = GUICtrlCreateLabel($prompt, 4, 4, 201, 17)
    GUISetState(@SW_SHOW)
    $time = TimerInit()
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                $case = 0
                ExitLoop
            Case $msg = $okbtn
                $case = 1
                ExitLoop
            Case $msg = $cancelbtn
                $case = 0
                ExitLoop
            Case TimerDiff($time) > $timeout And $timeout <> -1
                $case = 2
                ExitLoop
        EndSelect
    WEnd
    
    If $case = 0 Then;Cancel/Exit Button Pressed
        GUIDelete($gui)
        Return SetError(0, 1)
    ElseIf $case = 2 Then;Timed Out
        GUIDelete($gui)
        Return SetError(0, 2)
    ElseIf $case = 1 Then;Ok Pressed
        SetError(1)
        $retarr[0] = GUICtrlRead($username)
        $retarr[1] = GUICtrlRead($password)
        GUIDelete($gui)
        Return $retarr
    EndIf
EndFunc  ;==>_LoginBox

Thankyou.

Link to comment
Share on other sites

Your select case is the problem...

Atm your case gets to the first true case then it ends and your function continues on it's way...

Add ContinueCase to each case...

eg:

Select
        Case $uDefault = -1
            $uDefault = ""
            ContinueCase
        Case $pDefault = -1
            $pDefault = ""
            ContinueCase
        Case $width = -1
            $width = 250
            ContinueCase
        Case $height = -1
            $height = 130
            ContinueCase
        Case $left = -1
            $left = (@DesktopWidth / 2) - ($width / 2)
            ContinueCase
        Case $top = -1
            $top = (@DesktopHeight / 2) - ($height / 2)
    EndSelect

Cheers

Edited by smashly
Link to comment
Share on other sites

Your select case is the problem...

Atm your case gets to the first true case then it ends and your function continues on it's way...

Add ContinueCase to each case...

eg:

Select
        Case $uDefault = -1
            $uDefault = ""
            ContinueCase
        Case $pDefault = -1
            $pDefault = ""
            ContinueCase
        Case $width = -1
            $width = 250
            ContinueCase
        Case $height = -1
            $height = 130
            ContinueCase
        Case $left = -1
            $left = (@DesktopWidth / 2) - ($width / 2)
            ContinueCase
        Case $top = -1
            $top = (@DesktopHeight / 2) - ($height / 2)
    EndSelect

Cheers

*Hits head in idiotcy...* THANKYOU! Argh! So simple... meh. Knew it was 2cm in front of my face!

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...