Dialog.au3

Last modified:   Sunday, 8 March 2009

;*******************************************************************************
;
;   Function List
;         _CtrlEnumStates()
;         _GUI_ChildSize()
;         _GUI_CreateImageRect()
;         _GUI_CreateRect()
;         _GUI_FromTray()
;         _GUI_Line_H()
;         _GUI_Line_V()
;         _GUI_NoIcon()
;         _Gui_RoundCorners()
;         _GUI_ToTray()
;         _GUICreateAbout()
;         _GUICreateLogin()
;         _RefreshSystemTray()
;         _SysTrayGetHeight()
;         _Win_Center()
;         _Win_Fade()
;         _Win_Plode()
;         _Win_SlideIn()
;         _Win_SlideOut()
;         _WinChildList()
;         _WinGetChildren()
;         _WinGetChildSizes()
;         _WinGetParent()
;         _WinGetState()
;         _WinRestoreState()
;
;*******************************************************************************

#include-once

;===============================================================================
; Function Name:   _Chart_CreateBar()
; Description:   Create a new bar for bar charts
; Syntax:   _Chart_CreateBar($bar_x, $bar_y, $Bar_Val, $bar_Clr [, $Bar_w = 30 [, $bRatio = 1 [, $bOrient = 1]]])
; Parameter(s):   $Bar_x - Top left horizontal starting point of the bar
;                           $Bar_y - Top left vertical starting point of the bar
;                           $Bar_Val - length of the bar
;                           $bar_Clr - color of the bar
;                           $Bar_w - width of the bar (default is 30 pixels)
;                           $bRatio - not yet implemented
;                           $bOrient - Orientation of the bar ( 1 = vertical bar)
;                           $bTxt - Label text for the bar. Not valid for a vertical bar and will not display well on a short bar
; Requirement(s):
; Return Value(s):   Generates a new bar of the specified color for the bar chart
; Author(s):   George (GEOSoft) Gedye
; Modification(s):
; Note(s):
; Example(s):
;===============================================================================

Func _Chart_CreateBar($bar_x, $bar_y, $Bar_Val, $bar_Clr, $Bar_w = 30, $bRatio = 1, $bOrient = 1, $bTxt = "")
  Local $sp
  If $bOrient = 1 Then
    $bTxt = ""
    $sp = $bar_y
    If $Bar_Val > 0 Then $sp = $bar_y - $Bar_Val
    $Bar_Val = StringReplace($Bar_Val, "-", "")
    GUICtrlCreateLabel("", $bar_x, $sp, $Bar_w, $Bar_Val / $bRatio)
  Else
    $sp = $bar_x
    If $Bar_Val > 0 Then $sp = $bar_x - $Bar_Val
    GUICtrlCreateLabel($bTxt, $sp, $bar_y, $Bar_w, $Bar_Val / $bRatio)
  EndIf
  GUICtrlSetBkColor(-1, $bar_Clr)
  GUICtrlSetState(-1, 144)
EndFunc   ;==>_Chart_CreateBar

;===============================================================================
; Function Name:   _CtrlEnumStates()
; Description:     Enumerate a list of controls to get the current state so that they
;                    may be reset to the current states later.
; Syntax:          
; Parameter(s):    
; Requirement(s):  
; Return Value(s): - Success - an array where [n][0] is the control handle and [n][1] is the state.
;                  - Failure 
; Author(s):       George (GEOSoft) Gedye
; Modification(s): 
; Note(s):    
; Example(s):   
#cs

#ce
;===============================================================================

Func _CtrlEnumStates($iStart, $iEnd, $iText = 2)
  If $iText <> 2 Then $iText = 3
  Local $aDim = ($iEnd-$iStart)+1
  Local $sArray[$aDim][$iText]
  Local $cType
  Local $J = 0
  For $I = $iStart To $iEnd
    $Chk_State = 0
    $sArray[$J][0] = $I;GUICtrlGetHandle($I)
    Local $State = GUICtrlGetState($I)
    Local $sText = GUICtrlRead($I)
    If $iText = 3 Then
      $cType = DllCall("User32.dll", "int", "GetClassName", "hwnd", $I, "str", "", "int", 4096)
      ;If $cType[2] = "button" AND StringRegExp(GUICtrlRead($I), "(?i).*[a-z]+.*(?:\z)") = 0 Then
      If $cType[2] = "button" AND StringRegExp(GUICtrlRead($I), "\d(?:\z)") Then
        #cs
        If ControlCommand ( "Test", "", $I, "IsChecked", "") Then
          $State += 1
          $sText = ""
        EndIf
        If ControlCommand ( "Test", "", $I, "IsChecked", "") <> 1 Then
          $State += 4
          $sText = ""
        EndIf
        #ce
        $sText = ""
        $State += GUICtrlRead($i)
      EndIf
      $sArray[$J][2] = $sText
    EndIf
    $sArray[$J][1] = $State
    $J += 1
  Next
  Return $sArray
EndFunc   ;<==> _CtrlEnumStates()

;===============================================================================
; Function Name:   _GUI_ChildSize()
; Description:     Set the dimension of a window by referencing the size of another window
; Syntax:          
; Parameter(s):    $hWnd - Window to reference
;                  $iDim - If 0 (default) then returns the width else returns the height
;                  $iCurr - Add to the dimmension value (Default = 0).
;                           For use when you need to add the dimensions of 2 forms together
; Requirement(s):  
; Return Value(s): - Success - Returns the dimension specified by $iDim 
;                  - Failure 
; Author(s):       George (GEOSoft) Gedye
; Modification(s): 
; Note(s):    
; Example(s):   Below
#cs
   #include <WindowsConstants.au3>
   Opt ("GUICoordMode", 2)
   $Parent = GUICreate("Parent window", 400, 250)
   GUISetState()
   $W = _GUI_ChildSize($Parent)
   $H = _GUI_ChildSize($Parent, 1)
   $Child = GUICreate("Child Window", $W, $H -210, 0, 0, $WS_CHILD + $WS_DLGFRAME, -1, $Parent)
   GUISetBkColor(0xFF0000)
   $Y = _GUI_ChildSize($Child,1)
   $H -= $Y
   $Child2 = GUICreate("Child Window 2", $W, $H, 0, $Y, $WS_CHILD + $WS_DLGFRAME, -1, $Parent)
   GUISetBKColor(0x0000FF)
   GUISetState(@SW_SHOW, $Child)
   GUISetState(@SW_SHOW, $Child2)
   While 1
      If GUIGetMsg() = -3 Then Exit
   Wend
#ce
;===============================================================================

Func _GUI_ChildSize($hWnd,$iDim = 0,$iCurr = 0)
   If NOT IsHWnd($hWnd) Then Return SetError(1)
   If $iDim <> 1 Then $iDim = 0
   Local $sArray = WinGetClientSize($hWnd)
   If $iDim = 0 Then Return $sArray[0] + $iCurr
   Return $sArray[1] + $iCurr
EndFunc   ;<==> _GUI_ChildSize()

;===============================================================================
; Function Name:   _GUI_CreateImageRect()
; Description:   Create a bordered rectangle that is filled with an image
; Syntax:   _GUI_CreateImageRect($xStart, $yStart, $bWidth, $bHeight [, $bThick = 1 [, $cLine = 0x000000 ]])
; Parameter(s):   $xStart - Top left horizontal start point
;                           $yStart - Top left vertical start point
;                           $bWidth - Width of the rectangle
;                           $bHeight - Height of the rectangle
;                           $bImage - Image to use for filling the rectangle
;                           $bThick - Thickness of the borders (default = 1 pixel)
;                           $cLine - Color (hex) of the borders (default = black)
; Requirement(s):
; Return Value(s):   Creates a bordered image using label controls
; Author(s):   George (GEOSoft) Gedye
; Modification(s):
; Note(s):   Great for creating checkerboard patterns
; Example(s):
;===============================================================================

Func _GUI_CreateImageRect($xStart, $yStart, $bWidth, $bHeight, $bImage, $bThick = 1, $cLine = 0x000000)
  Local $I, $Left, $Top, $Bottom, $Right
  If Not FileExists($bImage) Then Return SetError(1)
  GUICtrlCreatePic($bImage, $xStart, $yStart, $bWidth, $bHeight)
  GUICtrlSetState(-1, 144)
  $Left = GUICtrlCreateLabel("", $xStart, $yStart, $bThick, $bHeight + $bThick)
  $Top = GUICtrlCreateLabel("", $xStart, $yStart, $bWidth, $bThick)
  $Bottom = GUICtrlCreateLabel("", $xStart, $yStart + $bHeight, $bWidth, $bThick)
  $Right = GUICtrlCreateLabel("", $xStart + $bWidth, $yStart, $bThick, $bHeight + $bThick)
  For $I = $Left To $Right
    GUICtrlSetBkColor($I, $cLine)
    GUICtrlSetState($I, 144)
  Next
EndFunc   ;==>_GUI_CreateImageRect

;===============================================================================
; Function Name:   _GUI_CreateRect()
; Description:   Create a bordered rectangle
; Syntax:   _GUI_CreateRect($xStart, $yStart, $bWidth, $bHeight [, $bThick = 1 [, $cFill = default [, $cLine = 0x000000 ]]])
; Parameter(s):   $xStart - Top left horizontal start point
;                           $yStart - Top left vertical start point
;                           $bWidth - Width of the rectangle
;                           $bHeight - Height of the rectangle
;                           $bThick - Thickness of the borders (default = 1 pixel)
;                           $cFill - Fill color of the rectangle ( default = no fill)
;                           $cLine - Color (hex) of the borders (default = black)
; Requirement(s):
; Return Value(s):   Draws a filled or unfilled rectangle using label controls
; Author(s):   George (GEOSoft) Gedye
; Modification(s):
; Note(s):   Multi purpose, but this function was created for use in displaying bordered line chart.
; Example(s):
; GUICreate("Test GUI")
; _GUI_CreateRect(25, 40, 350, 200, 3, 0xff0000)
; GUISetState()
; While 1
; If GUIGetMsg() = -3 Then Exit
; Wend
;===============================================================================

Func _GUI_CreateRect($xStart, $yStart, $bWidth, $bHeight, $bThick = 1, $cFill = default, $cLine = 0x000000)
  Local $Fill, $Left, $Top, $Bottom, $Right, $I
  If $cFill <> default Then
    $Fill = GUICtrlCreateLabel("", $xStart, $yStart, $bWidth, $bHeight)
    GUICtrlSetBkColor($Fill, $cFill)
    GUICtrlSetState($Fill, 144)
  EndIf
  $Left = GUICtrlCreateLabel("", $xStart, $yStart, $bThick, $bHeight + $bThick)
  $Top = GUICtrlCreateLabel("", $xStart, $yStart, $bWidth, $bThick)
  $Bottom = GUICtrlCreateLabel("", $xStart, $yStart + $bHeight, $bWidth, $bThick)
  $Right = GUICtrlCreateLabel("", $xStart + $bWidth, $yStart, $bThick, $bHeight + $bThick)
  For $I = $Left to $Right
    GUICtrlSetBkColor($I, $cLine)
    GUICtrlSetState($I, 144)
  Next
EndFunc   ;==>_GUI_CreateRect

;===============================================================================
; Function Name:   _GUI_FromTray()
; Description:   Restore the GUI From the system tray
; Syntax:
; Parameter(s):   $hWin -  Form to restore
; Requirement(s):
; Return Value(s):
; Author(s):   Gary Frost
; Note(s):     Only valid handles from _GUI_ToTray() can be used
;===============================================================================

Func _GUI_FromTray()
  Local $hWin = $hRest
  $sTIH = Opt("TrayIconHide")
  GUISetState(@SW_Show, $hWin)
  WinActivate($hWin)
  TraySetState(2)
  Opt("TrayIconHide", $sTIH)
  $hRest = ""
EndFunc   ;==>_GUI_FromTray

;===============================================================================
; Function Name:   _GUI_Line_H()
; Description:   Create a horizontal line using a label control
; Syntax:   _GUI_Line_H($Line_x, $Line_y, $Line_l [, $Line_t = 1 [, $cLine = 0x000000]])
; Parameter(s):   $Line_x - Top left horizontal starting point of the line
;                           $Line_y - Top left vertical starting point of the line
;                           $Line_l - Line length
;                           $Line_t - Thickness if the line (default is 1 pixel)
;                           $cLine - Color (hex) to use for creating the line (default is black)
; Requirement(s):
; Return Value(s):   Generates a horizontal line
; Author(s):   George (GEOSoft) Gedye
; Modification(s):
; Note(s):
; Example(s):
;===============================================================================

Func _GUI_Line_H($Line_x, $Line_y, $Line_l, $Line_t = 1, $cLine = 0x000000)
  GUICtrlCreateLabel("", $Line_x, $Line_y, $Line_l, $Line_t)
  GUICtrlSetBkColor(-1, $cLine)
  GUICtrlSetState(-1, 144)
EndFunc   ;==>_GUI_Line_H

;===============================================================================
; Function Name:   _GUI_Line_V()
; Description:   Create a vertical line using a label control
; Syntax:   _GUI_Line_V($Line_x, $Line_y, $Line_l [, $Line_t = 1 [, $cLine = 0x000000]])
; Parameter(s):   $Line_x - Top left horizontal starting point of the line
;                           $Line_y - Top left vertical starting point of the line
;                           $Line_l - Line length
;                           $Line_t - Thickness if the line (default is 1 pixel)
;                           $cLine - Color (hex) to use for creating the line (default is black)
; Requirement(s):
; Return Value(s):   Generates a vertical line
; Author(s):   George (GEOSoft) Gedye
; Modification(s):
; Note(s):
; Example(s):
;===============================================================================

Func _GUI_Line_V($Line_x, $Line_y, $Line_l, $Line_t = 1, $cLine = 0x000000)
  GUICtrlCreateLabel("", $Line_x, $Line_y, $Line_t, $Line_l)
  GUICtrlSetBkColor(-1, $cLine)
  GUICtrlSetState(-1, 144)
EndFunc   ;==>_GUI_Line_V

;===============================================================================
; Function Name:   _GUI_NoIcon()
; Description:     
; Syntax:          
; Parameter(s):    $sTitle = text to appear in the title bar
;                  $iWidth = Window width
;                  $iHeight = Window height
;                  $iXpos = Left position of window on desktop
;                  $iYpos = Top position of window on desktop
; Requirement(s):  
; Return Value(s): - Success - Creates a GUI window with no icon
;                  - Failure 
; Author(s):       @rover - code converted to function by GEOSoft
; Modification(s): 
; Note(s):    From code in this post:
;             http://www.autoitscript.com/forum/index.php?showtopic=90630&view=findpost&p=653595
; Example(s):   
#cs
   #include <GUIConstantsEX.au3>
   #include <WindowsConstants.au3>
   $hGUI = _GUI_NoIcon("Test Window", 300, 200)
   GUISetState()

   Do
   Until GUIGetMsg() = $GUI_EVENT_CLOSE
#ce
;===============================================================================

Func _GUI_NoIcon($sTitle, $iWidth = -1, $iHeight = -1, $iXpos = -1, $iYpos = -1)
   Local $GCL_HICONSM = -34, $GCL_HICON = -14
   Local $hWnd = GUICreate($sTitle, $iWidth, $iHeight, $iXpos, $iYpos, _
         BitOR($WS_CAPTION, $WS_SYSMENU), $WS_EX_DLGMODALFRAME)
   Local $hIcon = GetClassLong($hWnd, $GCL_HICON)
   DllCall("User32.dll", "int", "DestroyIcon", "hwnd", $hIcon)
   SetClassLong($hWnd, $GCL_HICON, 0)
   SetClassLong($hWnd, $GCL_HICONSM, 0)
   Return $hWnd
EndFunc   ;<==> _GUI_NoIcon()

;===============================================================================
; Function Name:   _Gui_RoundCorners()
; Description:   Round the corners of a GUI window
; Syntax:
; Parameter(s):   $h_win -  Form to work with
; Requirement(s):
; Return Value(s):
; Author(s):   Gary Frost (I just renamed the function)
; Example :   _Gui_RoundCorners(WinGetHandle("My Window"), 0, 0, 30, 30)
;===============================================================================

Func _Gui_RoundCorners($h_win, $i_x1, $i_y1, $i_x3, $i_y3)
  Local $XS_pos, $XS_ret, $XS_ret2
  $XS_pos = WinGetPos($h_win)
  $XS_ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $i_x1, "long", $i_y1, "long", $XS_pos[2], "long", $XS_pos[3], "long", $i_x3, "long", $i_y3)
  If $XS_ret[0]Then
    $XS_ret2 = DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $XS_ret[0], "int", 1)
  EndIf
EndFunc   ;==>_Gui_RoundCorners

;===============================================================================
; Function Name:   _GUI_ToTray()
; Description:   Minimize the GUI to the system tray
; Syntax:
; Parameter(s):   $hWin -  Form to hide
;                 $sLeftFunc - (optional) Not Used yet
;                 $iRight - (optional) Use Right-click function (Default is use Right-click)
;                 $sRightFunc - (optional) Function to be called from right click (default is _exitall())
;                 $sRight - (optional) Tip Text for Right-click
; Requirement(s):   Opt ("TrayOnEventMode", 1), Opt ("TrayMenuMode", 1), Opt ("TrayAutoPause", 0)
; Return Value(s):
; Author(s):   Gary Frost <==> Modified by George (GEOSoft) Gedye
;===============================================================================

Func _GUI_ToTray($hWin, $sLftFunc = "_GUI_FromTray", $iRight = 1, $sRghtFunc = "_exitall", $sRight = "Right click to Exit")
  Global $Tr_Disp = 1
  Global $hRest = $hWin
  GUISetState(@SW_HIDE, $hWin)
  $sTray = "Left click to restore"
  If $iRight = 1 Then
   $sTray &= @CRLF & $sRight
   TraySetOnEvent(-10, $sRghtFunc) ;;<<== You can play with this to show tray menus
  EndIf
  TrayTip(' ',$sTray, 5, 1) ;; Do what you want here.
  TraySetOnEvent(-8, "_GUI_FromTray")
  Opt("TrayIconHide", 0)
EndFunc   ;==>_GUI_ToTray

;===============================================================================
; Function Name:    _GUICreateAbout()
; Description:      Create an "About" dialog
; Syntax:           _GUICreateAbout([$aTtl[, $aTxt[,$cTxt[, $aGw[, $aGh[, $xPos[, $yPos[, $aStyle[, $aExStyle[, $hWin[ $aBg_Color[,$Bold[,$Center]]]]]]]]]]]]]])
; Parameter(s):     $aTtl -- the text that will appear on the title bar (default = "")
;                   $aTxt -- text to appear in the main label (default = "")
;                   $cTxt -- text to appear in the copyright label (default = "")
;                   $aGw -- The width of the window (default = 450)
;                   $aGh -- The height of the window (default = 200)
;                   $xPos -- Left position of window. (default = centered)
;                   $yPos -- Top position of window. (default = centered)
;                   $aStyle -- Window Style. (default = 0x00400000)
;                   $aExStyle -- Window extended style (default -1)
;                   $hWin -- Name of the window to switch to on close. (default = last used window)
;                   $aBg_Color -- The background color to use for the window (default = 0xfcfcfe)
;                   $Bold - 0 = Use standard font weight. 1 = Use bold (size 9, 500) font (default)
;                   $Center - 0 = $aTxt is aligned left (default). 1 = Center $aTxt
; Requirements:
; Return Value(s):  Success - Creates the About dialog
; Author(s):        George (GEOSoft) Gedye.  Thanks to gafrost for his input on the hyperlink.
; Notes:            All Parameters are optional but the dialog is kind of useless without at least $aTxt
;                   The copyright text will be prefixed with 'Copyright ' and suffixed with the current year
;                   To use the copyright with a date span then $Copy_Txt = 'GEOSoft 2003 -' would display
;                   Copyright GEOSoft 2003 - 2007
;                   You can modify the link text and URL but remember that you should give credit where due
;                   In a future version I may add the ability to include more links.
; Modifications:    June 11 / 2007 - Added a new label for copyright notice and added $Bold param
;===============================================================================

Func _GUICreateAbout($aTtl = '', $aTxt = '', $cTxt = '', $aGw = 450, $aGh = 300, $xPos = -1, $yPos = -1, _
$aStyle = default, $aExStyle = -1, $hWin = '', $aBg_Color = 0xfcfcfe, $Bold = 1, $Center = 0)
  ;;<<======== This GUI uses relative positioning so get the current value of GUICoordMode and change if required >>
  $sOpt = Opt("GUICoordMode")
  If $sOpt <> 2 Then Opt("GUICoordMode", "2")
  If $Bold <> 1 Then $Bold = 0
  If $Center <> 0 Then $Center = 1
  If $aGw < 370 Then $aGw = 370
  If $aGh < 200 Then $aGh = 200
  If $aStyle = default Then $aStyle = 0x00400000
  If StringInStr($aTtl, 'about ') Then $aTtl = StringReplace($aTtl, 'about ', '')
  Local $Msg, $aIco = @AutoItExe, $mp = $aGw / 2
  ;;<<===========  Create the form  ===========>>
  Local $Frm_Abt = GUICreate('About ' & $aTtl, $aGw, $aGh, $xPos, $yPos, $aStyle, $aExStyle)
  GUISetBkColor($aBg_Color)
  GUICtrlCreateIcon($aIco, -1, 10, 10, 32, 32)
  Local $Abt_Lbl = GUICtrlCreateLabel('', 23, -1, $aGw - 75, $aGh - 130)
  If $Center = 1 Then GUICtrlSetStyle($Abt_Lbl, 0x01)
  If $Bold = 1 Then GUICtrlSetFont($Abt_Lbl, 9, 500)
  GUISetCoord(10, $aGh - 115)
  GUICtrlCreateLabel('', -1, -1, $aGw - 20, 4, 0x12) ;;<<=========  Create a divider line
  If $cTxt <> '' Then
    If NOT StringInStr($cTxt, 'Copyright') Then $cTxt = 'Copyright  ' & $cTxt
    $cTxt &= Chr(32) & @Year
  EndIf
  Local $C_Lbl = GUICtrlCreateLabel('', -1, 5, $aGw - 20, 20, 1)
  GUICtrlSetData($C_Lbl, $cTxt)
  ;;<<===============  Create the two labels for a hyperlink if required  ===============>>
  GUISetCoord($aGw / 2 - 177, $aGh - 80)
  Local $Ai_Lbl = GUICtrlCreateLabel('Written entirely using AutoIt3 script:', -1, -1, 175, 20)
  Local $hLink = GUICtrlCreateLabel('http://www.autoitscript.com/autoit3/', 5, -1, 175, 20)
  GUICtrlSetColor($hLink, 0x0000ff)
  GUICtrlSetCursor($hLink, 0)
  GUICtrlSetTip($hLink, GUICtrlRead($hLink))
  GUISetCoord($mp - 30, $aGh - 60)
  Local $Btn_Close = GUICtrlCreateButton('Close', -1, -1, 60, 30, 1)
  GUICtrlSetData($Abt_Lbl, $aTxt)
  GUISetState()
  While 1
    $Msg = GUIGetMsg()
    Switch $Msg
      Case $Btn_Close
        GUIDelete($Frm_Abt)
        ExitLoop
      Case $hLink
        ;MsgBox(0,'TEST',GUICtrlRead($hLink)) ;;<<==========  For testing only
        ShellExecute(GUICtrlRead($hLink))
    EndSwitch
  Wend
  ;;<< Reset the GUICoordMode option if required >>
  If $sOpt <> 2 Then Opt("GUICoordMode", $sOpt)
  GUISwitch($hWin)
EndFunc   ;==>_GUICreateAbout

;===============================================================================
; Function Name:   _GUICreateLogin()
; Description:     Create a basic login box with Username, Password, and a prompt.
; Syntax:
; Parameter(s):    $hTitle - The title of the Form
;                  $hPrompt - The text prompt for the user [Optional] (maximum of 2 lines)
;                  $bBlank - The password or username can be blank. [optional]
;                            Default = False (Blanks are not allowed)
;                  $hWidth - Width of the form [optional] - default = 250
;                  $hHeight - Height of the form [optional] - default = 130
;                  $hLeft - X position [optional] - default = centered
;                  $hTop - Y position [optional] - default = centered
;                  $Timeout - The timeout of the form [optional - default = 0 (no timeout)
;                  $ShowError - Prompts are displayed to the user with timeout [optional]
; Requirement(s):  None
; Return Value(s): Success - Returns an array of 2 elements where
;                                        [0] = UserName
;                                        [1] = Password
;                  Failure - Sets @Error to 1 and
;                                 @Extended - 1 = Cancel/Exit Button Pressed
;                                           - 2 = Timed out
; Author(s):   Brett Francis (exodus.is.me@hotmail.com)
; Modification(s):
; Note(s): If $hPrompt is blank then the GUI height will be reduced by 30
; Example(s):
#cs
Opt ("GUICoordMode"," 2")
$ret = _GUICreateLogin("Enter Credentials", "Enter the username and password", -1, -1, -1, -1, -1, 10000)
If @Error Then 
MsgBox(0, "Error", "Error Returned: " & $Ret & @CRLF & "Error Code: " & @error & @CRLF & "Extended: " & @extended)
Else
  MsgBox(0, "Credentails Returned", "Username: " & $ret[0] & @CRLF & "Password:  " & $ret[1])
EndIf
#ce
;===============================================================================

Func _GUICreateLogin($hTitle, $hPrompt = "", $bBlank = False, _
    $hWidth = -1, $hHeight = -1, $hLeft = -1, $hTop = -1, $timeout = 0, $ShowError = 0)
  If NOT $hTitle Then $hTitle = "Login"
  $iGCM = Opt ("GUICoordMode", 2) ;; Get the current value of GUICoordMode and set it to 2
  If StringRegExp($bBlank, "(?i)\s|default|-1") Then $bBlank = False
  If StringRegExp($hWidth, "(?i)\s|default|-1") Then $hWidth = 250
  If StringRegExp($hHeight, "(?i)\s|default|-1") Then $hHeight = 130
  If StringRegExp($hLeft, "(?i)\s|default|-1") Then $hLeft = (@DesktopWidth / 2) - ($hWidth / 2)
  If StringRegExp($hTop, "(?i)\s|default|-1") Then $hTop = (@DesktopHeight / 2) - ($hHeight / 2)
  If NOT $hPrompt Then $hHeight -= 30 ;If $hPrompt is blank then resize the GUI.
  Local $retarr[2] = ["",""], $Time = 0
  
  Local $gui = GUICreate($hTitle, $hWidth, $hHeight, $hLeft, $hTop)
  GUISetCoord(4,0)
  If $hPrompt Then Local $Lbl_Prompt = GUICtrlCreateLabel($hPrompt, -1, 4, 201, 30)
  Local $Lbl_User = GUICtrlCreateLabel("Username:", -1, 4, 64, 17);44, 64, 17)
  GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
  Local $username = GUICtrlCreateInput('', 8, -1, $hWidth-81, 21)
  GUICtrlCreateLabel("Password:", -($hWidth-8), 4, 65, 17)
  GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
  Local $password = GUICtrlCreateInput('', 8, -1, $hWidth-81, 21, 32);, $ES_PASSWORD)
  GUISetCoord(($hWidth/2)-85, $hHeight -34)
  Local $Btn_OK = GUICtrlCreateButton("&OK", -1, -1, 75, 25)
  Local $Btn_Cancel = GUICtrlCreateButton("&Cancel", 20, -1, 75, 25)
  GUICtrlSetState($Btn_OK, 512)
  GUISetState()
  If $Timeout Then $time = TimerInit()
  While 1
    $Msg = GUIGetMsg()
    Local $sUser = GUICtrlRead($username)
    Local $sPass = GUICtrlRead($password)
    If ($Time AND TimerDiff($time) >= $timeout) AND ($sUser = "" AND $sPass = "") Then
      $Status = 2
      ExitLoop
    EndIf
    Select
      Case $Msg = -3
        $Status = 0
        ExitLoop
      Case $Msg = $Btn_OK
        If $bBlank AND ($sUser = "" OR $sPass = "") Then
          $Status = 1
          ExitLoop
        Else
          If $sUser <> "" And $sPass <> "" Then
            $status = 1
            ExitLoop
          Else
            Select
              Case $sUser = "" And $sPass = ""
                If $ShowError = 1 Then MsgBox(16, "Error!", "Username and Password cannot be blank!")
              Case $sPass = ""
                If $ShowError = 1 Then MsgBox(16, "Error!", "Password cannot be blank!")
                GUICtrlSetState($password, 256)
              Case $sUser = ""
                If $ShowError = 1 Then MsgBox(16, "Error!", "Username cannot be blank!")
                GUICtrlSetState($username, 256)
            EndSelect
          EndIf
        EndIf
      Case $Msg = $Btn_Cancel
        $status = 0
        ExitLoop
      Case $Timeout AND TimerDiff($time) >= $timeout; And $timeout
        If $bBlank AND ($sUser = "" OR $sPass = "") Then
          $status = 2
          ExitLoop
        Else
          ;$time = TimerInit()
          Select
            Case $sUser = "" And $sPass = ""
              If $timeout Then $time = TimerInit()
              If $ShowError = 1 Then MsgBox(16, "Error!", "Username and Password cannot be blank!")
            Case $sPass = ""
              If $timeout Then $time = TimerInit()
              If $ShowError = 1 Then
                MsgBox(16, "Error!", "Password cannot be blank!")
                GUICtrlSetState($password, 256)
              EndIf
            Case $sUser = ""
              $time = TimerInit()
              If $ShowError = 1 Then
                MsgBox(16, "Error!", "Username cannot be blank!")
                GUICtrlSetState($username, 256)
              EndIf
            ;Case ($Timeout AND TimerDiff($time) >= $timeout) AND ($sUser = "" OR $sPass = "")
               ;$status = 2
               ;ExitLoop
            Case Else
              If $sUser <> "" And $sPass <> "" Then
                $status = 3
                ;If $Timeout AND TimerDiff($time) >= $timeout Then $Status = 2
                ExitLoop
              EndIf
          EndSelect
        EndIf
    EndSelect
  WEnd
  Local $eMsg = ""
  Switch $Status
    Case 0, 2
      $err = 1;0
      $ext = 1 ;Cancel/Exit Button Pressed
      $eMsg = "Cancel/Exit Button Pressed"
      If $Status = 2 Then $ext = 2 ;Timed Out
      If $ext = 2 Then $eMsg = "Timed Out"
    Case Else ;1, 3
      $retarr[0] = $sUser
      $retarr[1] = $sPass
      $err = 0;1
      $Ext = 0
      If $Status = 3 Then $Ext = 1 ;Username Fields Not Blank, Timeout reached
  EndSwitch
  GUIDelete($gui)
  Opt ("GUICoordMode", $iGCM) ;Reset the GUICoordMode to what it started as.
  If $eMsg Then Return SetError($Err, $Ext, $eMsg)
  Return $retarr
EndFunc   ;<==> _GUICreateLogin()

;===============================================================================
; Function Name:   _RefreshSystemTray()
; Description:   Clear inactive icons from the system tray
; Syntax:
; Parameter(s):   $nDelay - the time to wait for the icons to be closed befpr proceeding in milliseconds (Default = 1 Second)
; Requirement(s):
; Return Value(s):
; Author(s):   Valik  modified by GEOSoft
; Modification(s):
; Note(s):
; Example(s):
;===============================================================================

Func _RefreshSystemTray($nDelay = 1000)
  If @OSVERSION = "WIN_VISTA" OR @OSVERSION = "WIN_XP" Then $nPro = "1"
  If $nPro <> "1" Then Return
  ; Save Opt settings
  Opt("WinTitleMatchMode", 4)
  Opt("WinSearchChildren", 1)
  Local $error = 0
  Do ;; Pseudo loop
    Local $hWnd = WinGetHandle("classname=TrayNotifyWnd")
    If @error Then
      $error = 1
      ExitLoop
    EndIf
    Local $hControl = ControlGetHandle($hWnd, "", "Button1")
    
    ; We're on XP and the Hide Inactive Icons button is there, so expand it
    If $hControl <> "" And ControlCommand($hWnd, "", $hControl, "IsVisible") Then
      ControlClick($hWnd, "", $hControl)
      Sleep($nDelay)
    EndIf
    
    Local $posStart = MouseGetPos()
    Local $posWin = WinGetPos($hWnd)
    Local $y = $posWin[1]
    While $y < $posWin[3] + $posWin[1]
      Local $x = $posWin[0]
      While $x < $posWin[2] + $posWin[0]
        DllCall("user32.dll", "int", "SetCursorPos", "int", $x, "int", $y)
        If @error Then
          $error = 2
          ExitLoop 3; Jump out of While/While/Do
        EndIf
        $x = $x + 8
      WEnd
      $y = $y + 8
    WEnd
    DllCall("user32.dll", "int", "SetCursorPos", "int", $posStart[0], "int", $posStart[1])
    ; We're on XP so we need to hide the inactive icons again.
    If $hControl <> "" And ControlCommand($hWnd, "", $hControl, "IsVisible") Then
      ControlClick($hWnd, "", $hControl)
    EndIf
  Until 1
  
  ; Restore Opt settings
  Opt("WinTitleMatchMode", $oldMatchMode)
  Opt("WinSearchChildren", $oldChildMode)
  
  SetError($error)
EndFunc   ;==>_RefreshSystemTray

;===============================================================================
; Function Name:   _SysTrayGetHeight()
; Description:   Get the height of the System tray for when you set GUI Sizes
; Syntax:
; Parameter(s):   
; Requirement(s):
; Return Value(s):
; Author(s):   George (GEOSoft) Gedye
; Modification(s):
; Note(s):
; Example(s):
;===============================================================================

Func _SysTrayGetHeight()
   Local $hWnd = WinGetHandle("classname=TrayNotifyWnd")
   Local $hDim = WinGetClientSize($hWnd)
   Return $hDim[1]
EndFunc

;===============================================================================
; Function Name:    _Win_Center()
; Description:
; Syntax:
; Parameter(s):   $hwnd = Variable name or hWnd of window to center
; Requirements:
; Return Value(s):  None
; Author(s):        George (GEOSoft) Gedye
; Note(s):
;===============================================================================

Func _Win_Center($hWnd)
  $cPos = WinGetPos($hWnd)
  If WinMove($hWnd, "", (@DesktopWidth / 2) - ($cPos[2] / 2), (@DesktopHeight / 2) - ($cPos[3] / 2)) Then
    Return 1
  Else
    Return 0
  EndIf
EndFunc   ;==>_Win_Center

;===============================================================================
; Function Name:    _Win_Fade()
; Description:      Fade-in, Fade-out GUI effects
; Syntax:           _Win_Fade($hwnd[,$hDir = 1[,$tFade = 2000[,$sState = 5]]])
;
; Parameter(s):     $hwnd = Variable name or hWnd of window to fade
;                   $hDir = 1 - Fade in. Anything else Fade out.
;                   $tFade = Fade in/out time in milliseconds (Default 2000 = 2 seconds)
;                   $sState = The initial display state for the GUI default is @SW_SHOW
; Requirements:
; Return Value(s):  None
; Return Value(s):
; Author(s):        George (GEOSoft) Gedye
; Modification(s):  You now longer have to call GUISetState() or GUIDelete()
;                   they are automaticaly called in the function.
; Note(s):
;===============================================================================

Func _Win_Fade($hWnd, $hDir = 1, $tFade = 2000, $sState = 5)
  Local $Fade = 0x80000
  If $hDir <> 1 Then $Fade = 0x90000
  DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hWnd, "int", $tFade, "long", $Fade)
  If $hDir = 1 Then
    GUISetState($sState, $hWnd)
  Else
    GUIDelete($hWnd)
  EndIf
EndFunc   ;==>_Win_Fade

;===============================================================================
; Function Name:   _Win_Plode()
; Description:   Create an Implode / Explode effect for a window
; Syntax:        _Win_Plode($hWnd [,$pType = 4[,$tDel = 250[,[$aState = 1[,$aExit = 1]]]]])
;
; Parameter(s):   $hWnd - Handle to Window
;                 $pType - Effect type default = 4 (explode), 5 = Implode
;                 $tDel - Time period for the effect to take (default = 250ms)
;                 $aState - If 1 (default)
;                             If $pType = 4 - Set GUI State to @SW_SHOW
;                             If $pType = 5 - Delete the GUI -- GUIDelete()
;                 $aExit - If 1 (default) and $aState = 1 then Exit the script
; Requirement(s):
; Return Value(s):
; Author(s):   George (GEOSoft) Gedye
; Modification(s):
; Note(s):
; Example(s):
;===============================================================================

Func _Win_Plode($hWnd, $pType = 4, $tDel = 250, $aState = 1, $aExit = 1)
  If Not StringInStr("45", $pType) Then $pType = 4
  Local $type = "0x000" & $pType & "0010"
  DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hWnd, "int", $tDel, "long", $type)
  If $aState = 1 Then
    If $pType = 4 Then
      GUISetState(@SW_SHOW, $hWnd)
    Else
      If $aExit = 1 Then Exit
      GUIDelete()
    EndIf
  EndIf
EndFunc   ;==>_Win_Plode

;===============================================================================
; Function Name:   _Win_SlideIn()
; Description:   Create a slide in effect for a window
; Syntax:        _Win_SlideIn($hWnd [,$frm = 1[,$tDel = 1000[,[$aState = 1]]]])
;
; Parameter(s):   $hWnd - Handle to Window
;                 $frm - Slide in from;
;                                 1 = Left
;                                 2 = Right
;                                 4 = Top
;                                 5 = Top-Left
;                                 6 = Top-Right
;                                 8 = Bottom
;                                 9 = Bottom-Left
;                                 a = Bottom-Right
;                 $tDel - Time period for the effect to take (default = 1000ms)
;                 $aState - If 1 (default) - Set GUI State to @SW_SHOW
; Requirement(s):
; Return Value(s):
; Author(s):   George (GEOSoft) Gedye
; Modification(s):
; Note(s):
; Example(s):
;===============================================================================

Func _Win_SlideIn($hWnd, $frm = 1, $tDel = 1000, $aState = 1)
  If Not StringInStr("1245689a", $frm) Then $frm = 1
  Local $Dir = "0x0004000" & $frm
  DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hWnd, "int", $tDel, "long", $Dir)
  If $aState = 1 Then
    GUISetState(@SW_Show, $hWnd)
  EndIf
EndFunc   ;==>_Win_SlideIn

;===============================================================================
; Function Name:   _Win_SlideOut()
; Description:   Create a slide out effect for a window
; Syntax:        _Win_SlideOut($hWnd [,$frm = 1[,$tDel = 1000[,[$aState = 1[,$aExit = 1]]]])
; Parameter(s):   $hWnd - Handle to Window
;                 $frm - Slide out to;
;                                 1 = Right
;                                 2 = Left
;                                 4 = Bottom
;                                 5 = Bottom-Right
;                                 6 = Bottom-Left
;                                 8 = Top
;                                 9 = Top-Right
;                                 a = Top-Left
;                 $tDel - Time period for the effect to take (default = 1000ms)
;                 $aState - If 1 (default) - Set GUI State to @SW_SHOW
;                 $aExit - If 1 (default) AND $aState = 1 Then Exit the script
; Requirement(s):
; Return Value(s):
; Author(s):   George (GEOSoft) Gedye
; Modification(s):
; Note(s):
; Example(s):
;===============================================================================

Func _Win_SlideOut($hWnd, $frm = 1, $tDel = 1000, $aState = 1, $aExit = 1)
  If Not StringInStr("1245689a", $frm) Then $frm = 1
  Local $Dir = "0x0005000" & $frm
  DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hWnd, "int", $tDel, "long", $Dir)
  If $aState = 1 Then
    If $aExit = 1 Then Exit
    GUIDelete()
  EndIf
EndFunc   ;==>_Win_SlideOut

;===============================================================================
; Function Name:   _WinChildList()
; Description:   
; Syntax:        
; Parameter(s):   $hParent - Hwnd of the parent window (Top Level) to find children of
; Requirement(s):   
; Return Value(s):   success - a 2 dimensional array where element
;                            [0] = Title of child window if any
;                            [1] = HWND of child window
;                    failure - Sets @Error to 1 if no top level child windows found
; Author(s):   George (GEOSoft) Gedye
; Modification(s):   
; Note(s):   Keep in mind this is only going to return top level child windows
;            Needed UDF function: _WinGetParent()
; Example(s):   
;===============================================================================

Func _WinChildList($hWnd)
   Local $wsOpt = Opt("WinSearchChildren",1)
   Local $wArray, $sTitle = "", $sHwnd = "", $Dim
   $wArray = WinList("[CLASS:AutoIt v3 GUI]")
   If IsArray($wArray) Then
      For $I = 1 To Ubound($wArray)-1
         If _WinGetParent($wArray[$i][1]) = $hWnd Then
            $sTitle &= $wArray[$i][0] & Chr(1)
            $sHwnd &= $wArray[$i][1] & Chr(1)
         EndIf
      Next
      Local $aTitle = StringSplit(StringTrimRight($sTitle, 1), Chr(1), 2)
      Local $aHwnd = StringSplit(StringTrimRight($sHwnd, 1), Chr(1), 2)
      Local $aRtn[Ubound($aTitle)][2]
      For $I = 0 To Ubound($aTitle)-1
         $aRtn[$i][0] = $aTitle[$i]
         $aRtn[$i][1] = $aHwnd[$i]
      Next
      Opt("WinSearchChildren",$wsOpt)
      Return $aRtn
   EndIf
   Opt("WinSearchChildren",$wsOpt)
   Return SetError(1)
EndFunc

;===============================================================================
; Function Name:   _WinGetChildren()
; Description:   
; Syntax:        
; Parameter(s):   $hParent - Hwnd of the parent window to find (Top Level) children of
; Requirement(s):   
; Return Value(s):   success - a 2 dimensional array
;                            [0] = Title of child window if any
;                            [1] = HWND of child window
;                    failure - Sets @Error to 1 if no top level child windows found
; Author(s):   Ron Nielsen (SmOke_N)
; Modification(s):   
; Note(s):   Keep in mind this is only going to return top level child windows
;            Needed UDF function: _WinGetParent
;            On some GUIs this function will fail by listing too many windows.
;               In that case use _WinChildList()
; Example(s):   
;===============================================================================

Func _WinGetChildren($hParent)
   Local $optWSC = Opt("WinSearchChildren", 1)
   Local $aWL = WinList()
   Opt("WinSearchChildren", $optWSC)
   Local $sHoldTitle, $sHoldHwnd
   Local $vDelim = Chr(1)
   
   ;~ Loop through and compare parent to found parent win
   ;~ If there is a match, separate for a 2 dim array return
   For $iCC = 1 To $aWL[0][0]
      If $hParent <> $aWL[$iCC][1] And (_WinGetParent($aWL[$iCC][1]) == $hParent) Then
         $sHoldTitle &= $aWL[$iCC][0] & $vDelim
         $sHoldHwnd &= $aWL[$iCC][1] & $vDelim
      EndIf
   Next
   
   If $sHoldHwnd = "" Then Return SetError(1, 0, "")
   
   ;~ Create 2 dimensional array
   Local $aSplitTitle = StringSplit(StringTrimRight($sHoldTitle, StringLen($vDelim)), $vDelim, 1)
   Local $aSplitHwnd = StringSplit(StringTrimRight($sHoldHwnd, StringLen($vDelim)), $vDelim, 1)
   
   ;~ Create 2 dimen array
   Local $avArray[$aSplitHwnd[0] + 1][2]
   $avArray[0][0] = $aSplitHwnd[0]
   $avArray[0][1] = 2

   ;~ Concat arrays to 2 dimensional array
   For $iCC = 1 To $avArray[0][0]
      $avArray[$iCC][0] = $aSplitTitle[$iCC]
      $avArray[$iCC][1] = $aSplitHwnd[$iCC]
   Next

   Return $avArray
EndFunc

;===============================================================================
; Function Name:   _WinGetChildSizes()
; Description:     
; Syntax:          
; Parameter(s):    
; Requirement(s):  An array of the window sizes.
; Return Value(s): - Success 
;                  - Failure 
; Author(s):       George (GEOSoft) Gedye
; Modification(s): 
; Note(s):    
; Example(s):   
;===============================================================================

Func _WinGetChildSizes($hWnd)
   Local $wsOpt = Opt("WinSearchChildren",1)
  Local $wStr = "", $sStr = "", $hStr = "", $I
  ;Local $wArray = WinList("[CLASS:AutoIt v3 GUI]")
  Local $wArray = _WinChildList($hWnd)
  If IsArray($wArray) Then
    For $I = 0 To Ubound($wArray)-1
      ;If _WinGetParent($wArray[$i][1]) = $hWnd Then
         $wStr &= $wArray[$i][1] & Chr(1)
         $dim = WinGetPos ( $wArray[$I][0])
         $hStr &= $dim[2] & Chr(1)
         $sStr &= $dim[3] & Chr(1)
      ;EndIf
   Next
   $wStr = StringSplit(StringTrimRight($wStr,1), Chr(1), 2);; Window handle
   $sStr = StringSplit(StringTrimRight($sStr,1), Chr(1), 2);; Width
   $hStr = StringSplit(StringTrimRight($hStr,1), Chr(1), 2);; Height
   Local $sArray[Ubound($wStr)][3]
   For $I = 0 To Ubound($wStr)-1
      $sArray[$i][0] = $wStr[$i]
      $sArray[$i][1] = $hStr[$i]
      $sArray[$i][2] = $sStr[$i]
   Next
   Opt("WinSearchChildren",$wsOpt)
    Return $sArray
   EndIf
   Return SetError(1)
EndFunc

;===============================================================================
; Function Name:   _WinGetParent()
; Description:   
; Syntax:        
; Parameter(s):   $hWnd - Hwnd of the window to find the parent of
; Requirement(s):   
; Return Value(s):   success - hWnd of the parent
;                    failure - Sets @Error to 1 if there is no parent window
; Author(s):   Ron Nielsen (SmOke_N)
; Modification(s):   
; Note(s):   
; Example(s):   
;===============================================================================

Func _WinGetParent($hWnd)
    Local $aResult = DllCall("User32.dll", "hwnd", "GetParent", "hwnd", $hWnd)
    If IsArray($aResult) = 0 Then Return SetError(1, 0, '')
    Return $aResult[0]
EndFunc

;===============================================================================
; Function Name:   _WinGetState()
; Description:     
; Syntax:          
; Parameter(s):    
; Requirement(s):  
; Return Value(s): - Success - An 0 based Array of the window states where
;                                     [n][0] = Window Title
;                                     [n][1] = State
;                                     [n][2] = Window Handle
;                  - Failure - None
; Author(s):       George (GEOSoft) Gedye
; Modification(s): 
; Note(s):    
; Example(s):   
#cs
  Local $sArray = _WinGetState($Frm_Main)
  For $I = 0 To Ubound($sArray)-1
    If $sArray[$I][1] = 7 Then GUISetState(@SW_Hide, $sArray[$i][2])
  Next
#ce
;===============================================================================

Func _WinGetState($hWnd)
  Local $iOpt = Opt("WinSearchChildren",1)
  Local $tStr = "", $sStr = "", $hStr = "", $I
  Local $wArray = WinList("[CLASS:AutoIt v3 GUI]")
  ;Local $wArray = _WinChildList($hWnd)
  If IsArray($wArray) Then
    For $I = 0 To Ubound($wArray)-1
      If _WinGetParent($wArray[$i][1]) = $hWnd Then
        $tStr &= $wArray[$i][0] & Chr(1)
        $sStr &= WinGetState($wArray[$i][0]) & Chr(1)
        $hStr &= $wArray[$i][1] & Chr(1)
      EndIf
    Next
    $tStr = StringSplit(StringTrimRight($tStr,1), Chr(1), 2)
    $sStr = StringSplit(StringTrimRight($sStr,1), Chr(1), 2)
    $hStr = StringSplit(StringTrimRight($hStr,1), Chr(1), 2)
    Local $sArray[Ubound($tStr)][3]
    For $I = 0 To Ubound($tStr)-1
      $sArray[$i][0] = $tStr[$I]
      $sArray[$i][1] = $sStr[$I]
      $sArray[$I][2] = $hStr[$I]
    Next
    Opt("WinSearchChildren",$iOpt)
    Return $sArray
  EndIf
  Return SetError(1)
EndFunc    ;<===> _WinGetState()

;===============================================================================
; Function Name:   _WinRestoreState()
; Description:     Restore Windows to the states contained in the array created
;                  by _WinGetState()
; Syntax:          
; Parameter(s):    
; Requirement(s):  
; Return Value(s): - Success - Resets window states contained in an array
;                  - Failure - Sets @Error to 1 if $aStates is not an array.
; Author(s):       George (GEOSoft) Gedye
; Modification(s): 
; Note(s):    
; Example(s):   
#cs
   _WinRestoreState($sArray)
#ce
;===============================================================================

Func _WinRestoreState($aStates)
  Local $iOpt = Opt("WinSearchChildren",1)
  If IsArray($aStates) Then
    Local $I, $State
    For $I = 0 To Ubound($aStates) -1
      $State = $aStates[$I][1]
      If $State = 7 Then
        GUISetState(@SW_SHOW, $aStates[$I][2])
      ElseIf $State = 5 Then
        GUISetState(@SW_HIDE, $aStates[$I][2])
      EndIf
    Next
    Opt("WinSearchChildren",$iOpt)
  EndIf
  Return SetError(1)
EndFunc    ;<===> _WinRestoreState()

;; <===> Private Functions <===>

Func _Exitall()
   Exit
EndFunc

Func _WinAPI_GetClientRect($hWnd)
   Local $tRect, $aResult
   $tRect = DLLStructCreate("int Left;int Top;int Right;int Bottom")
   ;$tRect = DllStructCreate($tagRECT)
   $aResult = DllCall("User32.dll", "int", "GetClientRect", "hwnd", $hWnd, "ptr", DllStructGetPtr($tRect))
   ;_WinAPI_Check("_WinAPI_GetClientRect", ($aResult[0] = 0), 0, True)
   Return $tRect
EndFunc   ;==>_WinAPI_GetClientRect

Func GetClassLong($hWnd, $nIndex)
   Local $hResult = DllCall("user32.dll", "dword", "GetClassLong", "hwnd", $hWnd, "int", $nIndex)
   Return $hResult[0]
EndFunc   ;<==> GetClassLong()

Func Restore_GUI($hGUI)
   GuiSetState(@SW_Show,$Frm_Main )
   WinActivate ($Frm_Main)
   TraySetState ( 2 )
   Opt("TrayIconHide", 1)
EndFunc    ;<===> Restore_GUI()

Func SetClassLong($hWnd, $nIndex, $dwNewLong)
   Local $hResult = DllCall("user32.dll", "dword", "SetClassLong", "hwnd", $hWnd, "int", $nIndex, "long", $dwNewLong)
   Return $hResult[0]
EndFunc   ;<==> SetClassLong()