Jump to content

Simple (but dynamic) step-by-step GUI


Skrip
 Share

Recommended Posts

Hey guys, I was playing around with the sexy glass functions and came up with this:

Posted Image

(without glass)

Posted Image

#include <GUIConstants.au3>
#include <EditConstants.au3>
#include <GuiEdit.au3>
#include <ButtonConstants.au3>

Global $MyArea[4] = [5, 5, 50, 30], $MyGUI[4] = [550, 150, -1, -1], $Step = 1, $LstStep = 3

$GUI = GUICreate("Windows Installer", $MyGUI[0], $MyGUI[1])
$iTextBox = GUICtrlCreateEdit("", $MyArea[0] - 2, $MyArea[3] + 18, $MyGUI[0] - $MyArea[1] - $MyArea[0] + 4, $MyGUI[1] - $MyArea[2] - $MyArea[3] + 4, BitOR($ES_MULTILINE, $ES_READONLY, $ES_NOHIDESEL))
$Credit = GUICtrlCreateLabel("Trigate Productions", 8, $MyGUI[1] - 20)
$Next = GUICtrlCreateButton("   Next   ", $MyGUI[0] - 60, $MyGUI[1] - 25, -1, -1)
$Back = GUICtrlCreateButton("   Back   ", $MyGUI[0] - 110, $MyGUI[1] - 25)
$Progress = GUICtrlCreateProgress(8, 3, $MyGUI[0] - 15)
$Status = GUICtrlCreateLabel("Status: Waiting", 8, 30, $MyGUI[0] - 25)
GUISetState()
If @OSVersion == "WIN_VISTA" Then; Windows 7 will also return WIN_VISTA
    _Apply()
EndIf

_Step($Progress, $Step, $LstStep, $Status); Set to the first step
_StepText($Step, $iTextBox, $Next, $Back); Set text for first step

While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Next
            If GUICtrlRead($Next) = "Finish" Then
                Exit
            Else
                $Step += 1
                If $Step > $LstStep Then
                    $Step = $LstStep
                EndIf
                _Step($Progress, $Step, $LstStep, $Status, 0)
                _StepText($Step, $iTextBox, $Next, $Back)
            EndIf
        Case $Back
            If GUICtrlRead($Back) = "Decline" Then
                _Step($Progress, 0, $LstStep, $Status, "Terms Not Accepted", 0xFF0000)
                _StepText(0, $iTextBox, $Next, $Back)
                While 1
                    $iMsg = GUIGetMsg()
                    If $iMsg = $GUI_EVENT_CLOSE Or $iMsg = $Next Then
                        Exit
                    ElseIf $iMsg = $Back Then
                        $Step = 2
                        _Step($Progress, $Step, $LstStep, $Status)
                        _StepText($Step, $iTextBox, $Next, $Back)
                        ExitLoop
                    EndIf
                WEnd
            Else
                $Step -= 1
                If $Step < 1 Then
                    $Step = 1
                EndIf
                _Step($Progress, $Step, $LstStep, $Status)
                _StepText($Step, $iTextBox, $Next, $Back)
            EndIf
    EndSwitch
WEnd

Func _Apply()
    _Vista_ApplyGlassArea($GUI, $MyArea)
    GUICtrlSetColor($Next, 0xFFFFFF)
    GUICtrlSetBkColor($Next, 0x005500)
    GUICtrlSetColor($Back, 0xFFFFFF)
    GUICtrlSetBkColor($Back, 0x000000)
    GUICtrlSetBkColor($iTextBox, 0x000000)
    GUICtrlSetColor($iTextBox, 0xFFFFFF)
    GUICtrlSetColor($Credit, 0xFFFFFF)
    GUICtrlSetColor($Status, 0xFFFFFF)
EndFunc   ;==>_Apply

Func _StepText($CurStep, $hWnd, $CurBut1, $CurBut2)
    If $CurStep = 1 Then
        GUICtrlSetData($iTextBox, "Welcome to the Trigate Vista installer." & @CRLF & "Please continue to the next step for further instructions.")
        GUICtrlSetData($CurBut1, "Next")
        GUICtrlSetData($CurBut2, "Back")
    ElseIf $CurStep = 2 Then
        GUICtrlSetData($iTextBox, "Welcome to step 2! :D" & @CRLF & "Please accept to continue.")
        GUICtrlSetData($CurBut1, "Accept")
        GUICtrlSetData($CurBut2, "Decline")
    ElseIf $CurStep = 3 Then
        GUICtrlSetData($iTextBox, "Thanks for Accepting!")
        GUICtrlSetData($CurBut1, "Finish")
        GUICtrlSetData($CurBut2, "Back")
    ElseIf $CurStep = 0 Then; Quiting
        GUICtrlSetData($iTextBox, "Sorry, you did not accept the terms of use. Please exit the program or go back.")
        GUICtrlSetData($CurBut1, "Exit")
        GUICtrlSetData($CurBut2, "Back")
    Else
        GUICtrlSetData($iTextBox, "Undefined step :(")
        GUICtrlSetData($CurBut1, "Next")
        GUICtrlSetData($CurBut2, "Back")
    EndIf
    _HeightCheck($MyGUI[1])
EndFunc   ;==>_StepText

Func _Step($hWnd, $CurStep, $LstStep, $hWnd2 = 0, $Info = False, $sColor = 0xFFFFFF); Handle for progress bar, Current Step, Last Step, Handle for Status Label, Info for label
    If Not @OSVersion == "WIN_VISTA" Then
        If $sColor = 0xFFFFFF Then $sColor = 0x000000
    EndIf
    GUICtrlSetData($hWnd, $CurStep / $LstStep * 100)
    If Not $hWnd2 = 0 Then
        If $Info = False Then
            $Info = "Step " & $CurStep & " of " & $LstStep
        EndIf
        GUICtrlSetData($hWnd2, "Status: " & $Info)
        GUICtrlSetColor($hWnd2, $sColor)
    EndIf
EndFunc   ;==>_Step

Func _HeightCheck($HCoord)
    $LCount = _GUICtrlEdit_GetLineCount($iTextBox)
    $LHeight = 10 * $LCount - 10
    If $HCoord < 100 + $LHeight Then
        MsgBox(0, "Warning", "Window is too small (height) to see all the text.. Minimum of " & $LHeight + 100 & " - Currently: " & $HCoord)
    EndIf
EndFunc   ;==>_HeightCheck

; #FUNCTION#;===============================================================================
;
; Name...........: _Vista_ApplyGlassArea
; Description ...: Applys glass effect to a window area
; Syntax.........: _Vista_ApplyGlassArea($hWnd, $Area, [$bColor)
; Parameters ....: $hWnd - Window handle:
;                   $Area - Array containing area points
;                  $bColor  - Background color
; Return values .: Success - No return
;                  Failure - Returns 0
; Author ........: James Brooks
; Modified.......:
; Remarks .......: Thanks to monoceres!
; Related .......:
; Link ..........;
; Example .......; Yes
;
;;==========================================================================================
Func _Vista_ApplyGlassArea($hWnd, $Area, $bColor = 0x000000)
    $Struct = DllStructCreate("int cxLeftWidth;int cxRightWidth;int cyTopHeight;int cyBottomHeight;")
    $sStruct = DllStructCreate("dword;int;ptr;int")
    If @OSVersion <> "WIN_VISTA" Then
        MsgBox(16, "_Vista_ApplyGlass", "You are not running Vista!")
        Exit
    Else
        If IsArray($Area) Then
            DllStructSetData($Struct, "cxLeftWidth", $Area[0])
            DllStructSetData($Struct, "cxRightWidth", $Area[1])
            DllStructSetData($Struct, "cyTopHeight", $Area[2])
            DllStructSetData($Struct, "cyBottomHeight", $Area[3])
            GUISetBkColor($bColor); Must be here!
            $Ret = DllCall("dwmapi.dll", "long*", "DwmExtendFrameIntoClientArea", "hwnd", $hWnd, "ptr", DllStructGetPtr($Struct))
            If @error Then
                Return 0
            Else
                Return $Ret
            EndIf
        Else
            MsgBox(16, "_Vista_ApplyGlassArea", "Area specified is not an array!")
        EndIf
    EndIf
EndFunc   ;==>_Vista_ApplyGlassArea

This could easily be modified to be a simple installer or step-by-step GUI for automation. Just modify the variables ($MyGUI[4] = [550, 150, -1, -1], $Step = 1, $LstStep = 3) and modify the Main While loop and the _StepText(...) function. Simple stuff, but useful stuff :D

It's controlled pretty dynamically, allowing for as many steps as needed,and the GUI controls will always line up perfectly for any size given :D and automatically checks to make sure that all text in the dialog box is showing..

Edited by Skrip

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

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