Jump to content

UDF: _SplashProgressImage.au3


Carlo84
 Share

Recommended Posts

This UDF ccreates a customizable image popup window with a progress bar and status text.

Functions:

_SplashProgressImageOff


_SplashProgressImageOn
_SplashProgressImageSet


Example:

#include "_SplashProgressImage.au3"
_Example()
Func _Example()
    Local $i, $sImage = RegRead('HKLM\SOFTWARE\AutoIt v3\AutoIt', 'InstallDir') & '\Examples\GUI\msoobe.jpg'
    If Not FileExists($sImage) Then
        MsgBox(262160, 'Autoit.', 'Image does not exist, try this function with a diffrent image path.')
        Exit
    EndIf
    _SplashProgressImageOn('Loading', $sImage, 'Loading script...', 0xFFFFFF, 256, 200, -1, -1, 1)
    For $i = 0 To 100 Step 10
        _SplashProgressImageSet($i, 'Loading resources ' & $i & '%')
        Sleep(Random(10, 1000, 1))
    Next
    Sleep(1000)
    _SplashProgressImageOff()
EndFunc   ;==>_Example


Script:

_SplashProgressImage.au3

#include-once
Global $a_SplashProgressImage[4]
#Region _SplashProgressImageOff
; #FUNCTION# ;===============================================================================
;
; Name...........: _SplashProgressImageOff
; Description ...: Turns SplashProgressImage off.
; Syntax.........: _SplashProgressImageOff()
; Parameters ....: None
; Return values .: Success - Returns 1.
;                  Failure - Returns 0
;
; Author ........: Carlo Westmaas
; Modified.......:
; Remarks .......:
; Related .......: _SplashProgressImageOn, _SplashProgressImageSet
; Link ..........; http://www.autoitscript.com/forum/topic/128197-udf-splashprogressimageau3/
; Example .......; No
;
; ;==========================================================================================
Func _SplashProgressImageOff()
    Dim $a_SplashProgressImage
    If Not IsArray($a_SplashProgressImage) Then Return 0
    If Not IsHWnd($a_SplashProgressImage[0]) Then Return 0
    Local $i = GUIDelete($a_SplashProgressImage[0])
    Dim $a_SplashProgressImage[4] = [0, 0, 0, 0]
    Return $i
EndFunc   ;==>_SplashProgressImageOff
#EndRegion _SplashProgressImageOff

#Region _SplashProgressImageOn
; #FUNCTION# ;===============================================================================
;
; Name...........: _SplashProgressImageOn
; Description ...: Creates a customizable image popup window with a progress bar
; Syntax.........: _SplashProgressImageOn($sTitle, $sFile [, $sText = "" [, $iColor = -1 [, $iWidth = -1 [, $iHeight = -1 [, $iLeft = -1 [, $iTop = -1 [, $iFlag = -1]]]]]]] )
; Parameters ....: $sTitle - Title for splash window.
;                  $sFile - full path\filename of image (BMP, GIF, or JPG)
;                  $sText - [optional] text for label. (default is blank)
;                  $iColor - [optional] text color of splash label.
;                  $iWidth - [optional] width of window in pixels. (default is 500)
;                  $iHeight - [optional] height of window in pixels. (default is 400)
;                  $iLeft - [optional] position from left (in pixels) of splash window. (default is centered)
;                  $iTop - [optional] position from top (in pixels) of splash window. (default is centered)
;                  $iFlag - [optional] Add up the options you want. Default is 'always on top/with title'
;                   |1 = Thin bordered titleless window
;                   |2 = Without "always on top" attribute
;                   |16 = Window can be moved
;
; Return values .: Success - Returns 1.
;                  Failure - Returns 0.
;
; Author ........: Carlo Westmaas
; Modified.......:
; Remarks .......:
; Related .......: _SplashProgressImageOff, _SplashProgressImageSet
; Link ..........; http://www.autoitscript.com/forum/topic/128197-udf-splashprogressimageau3/
; Example .......; No
;
; ;==========================================================================================
Func _SplashProgressImageOn($sTitle, $sFile, $sText = "", $iColor = -1, $iWidth = -1, $iHeight = -1, $iLeft = -1, $iTop = -1, $iFlag = -1)
    Dim $a_SplashProgressImage
    If Not IsArray($a_SplashProgressImage) Then Return 0
    If IsHWnd($a_SplashProgressImage[0]) Then Return 0
    Local $aStyle[2] = [0x00800000, 0x08000000], $iExStyle[2] = [0x00000008, 0x00000080]
    If $iWidth = -1 Or $iHeight = -1 Then $iWidth = 500
    If $iWidth = -1 Or $iHeight = -1 Then $iHeight = 400
    If $iFlag <> -1 Then
        If BitAND($iFlag, 1) Then $aStyle[0] = 0x80880000
        If BitAND($iFlag, 2) Then $iExStyle[0] = 0
        If BitAND($iFlag, 16) Then $aStyle[1] = 0
    EndIf
    If Not StringRegExp($sText, '\n') Then $sText = @LF & $sText
    Local $hWnd = GUICreate($sTitle, $iWidth, $iHeight, $iLeft, $iTop, BitOR($aStyle[0], $aStyle[1]), BitOR($iExStyle[0], $iExStyle[1]))
    Local $aSize = WinGetClientSize($hWnd)
    Local $hImg = GUICtrlCreatePic($sFile, 0, 0, $aSize[0], $aSize[1], 0x08000000)
    $sText = GUICtrlCreateLabel($sText, 5, $aSize[1] - 50, $aSize[0] - 10, 30, 0x0C)
    GUICtrlSetBkColor(-1, -2)
    If $iColor <> -1 Then GUICtrlSetColor(-1, $iColor)
    Local $hProgress = GUICtrlCreateProgress(5, $aSize[1] - 20, $aSize[0] - 10, 15)
    GUISetState(@SW_SHOW, $hWnd)
    Dim $a_SplashProgressImage[4] = [$hWnd, $sText, $hProgress, $hImg]
    Return 1
EndFunc   ;==>_SplashProgressImageOn
#EndRegion _SplashProgressImageOn

#Region _SplashProgressImageSet
; #FUNCTION# ;===============================================================================
;
; Name...........: _SplashProgressImageSet
; Description ...: Creates a customizable image popup window with a progress bar
; Syntax.........: _SplashProgressImageSet($iPercent [, $sText = -1 [, $iColor = -1 [, $sFile = -1]]] )
; Parameters ....: $iPercent - Percentage (value between 0. and 100.) to set the progress bar at.
;                  $sText - [optional] Set the text for the Splash label.
;                  $iColor - [optional] Set the text color for the Splash label.
;                  $sFile - [optional] full path\filename of image (BMP, GIF, or JPG)
;
; Return values .: Success - Returns 1.
;                  Failure - Returns 0.
;
; Author ........: Carlo Westmaas
; Modified.......:
; Remarks .......:
; Related .......: _SplashProgressImageOff, _SplashProgressImageOff
; Link ..........; http://www.autoitscript.com/forum/topic/128197-udf-splashprogressimageau3/
; Example .......; No
;
; ;==========================================================================================
Func _SplashProgressImageSet($iPercent, $sText = -1, $iColor = -1, $sFile = -1)
    If Not IsArray($a_SplashProgressImage) Then Return 0
    If Not IsHWnd($a_SplashProgressImage[0]) Then Return 0
    GUICtrlSetData($a_SplashProgressImage[2], $iPercent)
    If $sText <> -1 Then
        If Not StringRegExp($sText, '\n') Then $sText = @LF & $sText
        GUICtrlSetData($a_SplashProgressImage[1], $sText)
    EndIf
    If $iColor <> -1 Then GUICtrlSetColor($a_SplashProgressImage[1], $iColor)
    If $sFile <> -1 Then
        GUICtrlSetImage($a_SplashProgressImage[3], $sFile)
    EndIf
    Return 1
EndFunc   ;==>_SplashProgressImageSet
#EndRegion _SplashProgressImageSet


[Edit] Corrected the flag options for SplashProgressImageOn in the commented description.

Edited by Carlo84
Link to comment
Share on other sites

  • 11 months later...

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