Jump to content
Sign in to follow this  
Armand

_AdvancedSplashScreen UDF.

Recommended Posts

Well... that was made out of different UDFs gathered in the forum for my own use... i thought it might help some others in that specific format.

All credits are as was when i found the UDFs.

_AdvancedSplashScreen.au3:

;===============================================================================
;
; UDF Name:    _AdvancedSplashScreen
; Description:      Manipulates IE to show 'JPEG, TIFF, BMP, PNG and GIF' images inside AU3 GUIs.
; Function(s):     _AdvancedSplashScreenON                      Creates the image as a splash screen.
;                       _AdvancedSplashScreenOFF                Closes the splash screen.
;                  _GUICtrlCreatePIC                            Creates a picture control inside your GUI.
;                       _GUICtrlStopGIF                         Stop the picture control animation [GIF only]
;                       _GUICtrlResumeGIF                       Resumes the picture control animation [GIF only]
;                  _ImageGetSize                                Retrieves ove of the above file types image size.

; Requirement(s):   #include <IE.au3>, #include <GUIConstants.au3>, #include <WindowsConstants.au3>
; Collected and composed by:    Armand.
;===============================================================================
#include-once
#include <IE.au3>
#include <GUIConstants.au3>
#include <WindowsConstants.au3>

Global $_LastAdvancedSplashScreenCreated = 0
;===============================================================================
;
; Function Name:    _AdvancedSplashScreenON($ImagePath, $Image_Width = 0, $Image_Height = 0, $Tile = 1)
; Description:      Creates a splash screen.
; Parameter(s):     $ImagePath                [required]         path and filename of the picture.
;                   $Image_Width              [optional]         splashscreen Width.
;                   $Image_Height             [optional]         splashscreen Height.
;                   $Tile                     [optional]         0=repeat, 1=no-repeat, 2=repeat-x, 3=repeat-y

; Requirement(s):   #include <IE.au3>, #include <GUIConstants.au3>, #include <WindowsConstants.au3>
; Return Value(s): 
;               controlID of the SplashScreen created [GUI handle]
; Author(s):    Armand.
;===============================================================================
Func _AdvancedSplashScreenON($ImagePath, $Image_Width = 0, $Image_Height = 0, $Tile = 1)
    #Region ### START Koda GUI section ### Form=
    Local $aSize
    $aSize = _ImageGetSize($ImagePath)
    If @error = 1 Then
        ConsoleWrite("_GUICtrlCreatePIC:: Can't find image size." & @CRLF)
    Else
        If $aSize[0] > $Image_Width Then $Image_Width = $aSize[0]
        If $aSize[1] > $Image_Height Then $Image_Height = $aSize[1]
    EndIf

    $_LastAdvancedSplashScreenCreated = GUICreate("Splash", $Image_Width, $Image_Height, -1, -1, BitOR($WS_SYSMENU, $WS_POPUP, $WS_CLIPSIBLINGS), BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_WINDOWEDGE, $GUI_WS_EX_PARENTDRAG))
    WinSetOnTop($_LastAdvancedSplashScreenCreated, "", 1)
    _GUICtrlCreatePIC($ImagePath, 0, 0, 1, $Image_Width, $Image_Height, $Tile)
    GUISetState(@SW_SHOW)
    #EndRegion ### START Koda GUI section ### Form=
    Return $_LastAdvancedSplashScreenCreated
EndFunc

Func _AdvancedSplashScreenOFF($SplashScreenID = $_LastAdvancedSplashScreenCreated)
    GUIDelete($SplashScreenID)
EndFunc

;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;#################################################################################################################################
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@  Ctrl Create Pic  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;#################################################################################################################################
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;===============================================================================
;
; Function Name:    _GUICtrlCreatePIC()
; Description:      Create a picture control
; Parameter(s):     $pic        [required]        path and filename of the animated GIF
;                   $x          [optional]        x pos of the top-left corner
;                   $y          [optional]        y pos of the top-left corner
;                   $border     [optional]        0 = no border
;                   $pwidth     [optional]        0 = use pic width.
;                   $pheight    [optional]        0 = use pic height.
;                   $tile       [optional]        0 = repeat, 1 = no-repeat, 2 = repeat-x, 3 = repeat-y.
;                                    any other = sunken border
; Requirement(s):   #include <IE.au3>
; Return Value(s): 
;               controlID of the control created
; Author(s):    elgabionline, gafrost, Ed_Maximized
; Editted by:   Armand.
; MSDN BODY::: http://msdn.microsoft.com/en-us/library/ms535205(VS.85).aspx
;===============================================================================
Func _GUICtrlCreatePIC($pic,$x=0,$y=0,$border=0, $pwidth = 0, $pheight = 0, $tile = 0)
    Dim $aTile[4] = ["repeat", "no-repeat", "repeat-x", "repeat-y"]
    Local $oPicIE, $aSize
    If $pwidth = 0 Or $pheight = 0 Then 
        $aSize = _ImageGetSize($pic)
        If @error = 1 Then 
            ConsoleWrite("_GUICtrlCreatePIC:: Can't find image size."&@CRLF)
        Else
            If $pwidth = 0 Then $pwidth = $aSize[0]
            If $pheight = 0 Then $pheight = $aSize[1]
        EndIf
    EndIf
    $oPicIE = ObjCreate("Shell.Explorer.2")
    $_AnimatedGif_GUIActiveX = GUICtrlCreateObj($oPicIE, $x, $y, $pwidth, $pheight)
    $oPicIE.navigate ("about:blank")
    While _IEPropertyGet($oPicIE, "busy")
        Sleep(100)
    WEnd
    $oPicIE.document.body.background = $pic
    $oPicIE.document.body.scroll = "no" 
    $oPicIE.document.body.style.backgroundRepeat = $aTile[$tile]
    if $border=0 then $oPicIE.document.body.style.border = "0px groove"
    SetExtended($_AnimatedGif_GUIActiveX, $oPicIE)
    Return $oPicIE
EndFunc
;===============================================================================
;
; Function Name:    _GUICtrlStopGIF()
; Description:      stop an Animated GIF control created with _GUICtrlCreateGIF()
; Parameter(s):     $Control    [required]      controlID of the control returned by _GUICtrlCreateGIF()
;                                   
; Requirement(s):   #include <IE.au3>
; Return Value(s): 
;               none
; Author(s):        lod3n, Ed_Maximized
;
;===============================================================================
Func _GUICtrlStopGIF($Control)
    _IEAction ($Control, "stop" ) ; stop
EndFunc
;===============================================================================
;
; Function Name:    _GUICtrlResumeGIF()
; Description:      resume an Animated GIF control created with _GUICtrlCreateGIF()
; Parameter(s):     $Control    [required]      controlID of the control returned by _GUICtrlCreateGIF()
;                                   
; Requirement(s):   #include <IE.au3>
; Return Value(s): 
;               none
; Author(s):        lod3n, Ed_Maximized
;
;===============================================================================
Func _GUICtrlResumeGIF($Control)
    $Control.document.body.background = $Control.document.body.background ;resume
EndFunc


;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;#################################################################################################################################
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@  Image Get Size  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;#################################################################################################################################
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


;===============================================================================
;
; Description:      Return JPEG, TIFF, BMP, PNG and GIF image size.
; Parameter(s):     File name
; Requirement(s):   None special
; Return Value(s):  On Success - array with width and height
;                   On Failure empty string and sets @ERROR:
;                       1 - Not valid image or info not found
; Author(s):        YDY (Lazycat)
; Version:          1.1.00
; Date:             15.03.2005
;
;===============================================================================

Func _ImageGetSize($sFile)
    Local $sHeader = _FileReadAtOffsetHEX($sFile, 1, 24) ; Get header bytes
    Local $asIdent = StringSplit("FFD8 424D 89504E470D0A1A 4749463839 4749463837 4949 4D4D", " ")
    Local $anSize = ""
    For $i = 1 To $asIdent[0]
        If StringInStr($sHeader, $asIdent[$i]) = 1 Then
            Select
                Case $i = 1 ; JPEG
                    $anSize = _ImageGetSizeJPG($sFile)
                    Exitloop
                Case $i = 2 ; BMP
                    $anSize = _ImageGetSizeSimple($sHeader, 19, 23, 0)
                    Exitloop
                Case $i = 3 ; PNG
                    $anSize = _ImageGetSizeSimple($sHeader, 19, 23, 1)
                    Exitloop
                Case ($i = 4) or ($i = 5) ; GIF
                    $anSize = _ImageGetSizeSimple($sHeader, 7, 9, 0)
                    Exitloop
                Case $i = 6 ; TIFF MM
                    $anSize = _ImageGetSizeTIF($sFile, 0)
                    Exitloop
                Case $i = 7 ; TIFF II
                    $anSize = _ImageGetSizeTIF($sFile, 1)
                    Exitloop
            EndSelect
        Endif
    Next
    If not IsArray ($anSize) Then SetError(1)
    Return($anSize)
EndFunc

;===============================================================================
;
; Description:      Get image size at given bytes
; Parameter(s):     File header 
; Return Value(s):  Array with dimension
;
;===============================================================================
Func _ImageGetSizeSimple($sHeader, $nXoff, $nYoff, $nByteOrder)
    Local $anSize[2]
    $anSize[0] = _Dec(StringMid($sHeader, $nXoff*2-1, 4), $nByteOrder)
    $anSize[1] = _Dec(StringMid($sHeader, $nYoff*2-1, 4), $nByteOrder)
    Return ($anSize)
EndFunc

;===============================================================================
;
; Description:      Get JPG image size (may be used standalone with checking)
; Parameter(s):     File name
; Return Value(s):  On Success - array with dimension
;
;===============================================================================
Func _ImageGetSizeJPG($sFile)
    Local $anSize[2], $sData, $sSeg, $nFileSize, $nPos = 3
    $nFileSize = FileGetSize($sFile)
    While $nPos < $nFileSize
        $sData = _FileReadAtOffsetHEX ($sFile, $nPos, 4)
        If StringLeft($sData, 2) = "FF" then ; Valid segment start
            If StringInStr("C0 C2 CA C1 C3 C5 C6 C7 C9 CB CD CE CF", StringMid($sData, 3, 2)) Then ; Segment with size data
               $sSeg = _FileReadAtOffsetHEX ($sFile, $nPos + 5, 4)
               $anSize[1] = Dec(StringLeft($sSeg, 4))
               $anSize[0] = Dec(StringRight($sSeg, 4))
               Return($anSize)
            Else
               $nPos= $nPos + Dec(StringRight($sData, 4)) + 2
            Endif
        Else
            ExitLoop
        Endif
    Wend
    Return("")
EndFunc

;===============================================================================
;
; Description:      Get TIFF image size (may be used standalone with checking)
; Parameter(s):     File name
; Return Value(s):  On Success - array with dimension
;
;===============================================================================
Func _ImageGetSizeTIF($sFile, $nByteOrder)
    Local $anSize[2], $pos = 3
    $nTagsOffset = _Dec(_FileReadAtOffsetHEX($sFile, 5, 4), $nByteOrder) + 1
    $nFieldCount = _Dec(_FileReadAtOffsetHEX($sFile, $nTagsOffset, 2), $nByteOrder)
    For $i = 0 To $nFieldCount - 1
        $sField = _FileReadAtOffsetHEX($sFile, $nTagsOffset + 2 + 12 * $i, 12)
        $sTag = StringLeft($sField, 4)
        If $nByteOrder Then $sTag = StringRight($sTag, 2) & StringLeft($sTag, 2)
        Select
            Case $sTag = "0001"
                $anSize[0] = _Dec(StringRight($sField, 8), $nByteOrder)
            Case $sTag = "0101"
                $anSize[1] = _Dec(StringRight($sField, 8), $nByteOrder)
        EndSelect
    Next
    If ($anSize[0] = 0) or ($anSize[1] = 0) Then Return("")
    Return($anSize)
Endfunc

;===============================================================================
;
; Description:      Basic function that read binary data into HEX-string
; Parameter(s):     File name, Start offset, Number bytes to read
; Return Value(s):  Hex string
;
;===============================================================================
Func _FileReadAtOffsetHEX ($sFile, $nOffset, $nBytes)
    Local $hFile = FileOpen($sFile, 0)
    Local $sTempStr = ""
    FileRead($hFile, $nOffset - 1)
    For $i = $nOffset To $nOffset + $nBytes - 1
        $sTempStr = $sTempStr & Hex(Asc(FileRead($hFile, 1)), 2)
    Next
    FileClose($hFile)
    Return ($sTempStr)
Endfunc

;===============================================================================
;
; Description:      Basic function, similar Dec, but take in account byte order
; Parameter(s):     Hex string, Byte order
; Return Value(s):  Decimal value
;
;===============================================================================
Func _Dec($sHexStr, $nByteOrder)
    If $nByteOrder Then Return(Dec($sHexStr))
    Local $sTempStr = ""
    While StringLen($sHexStr) > 0
        $sTempStr = $sTempStr & StringRight($sHexStr, 2)
        $sHexStr = StringTrimRight($sHexStr, 2)
    WEnd
    Return (Dec($sTempStr))
EndFuncƒoÝŠ÷ ØLZš™^jëhŠ×6#include "_AdvancedSplashScreen.au3"

$image = @ProgramFilesDir & "\AutoIt3\Examples\GUI\Advanced\Images\Button.png"

Example1()
Example2()

Func Example1()
    _AdvancedSplashScreenON($image)
    Sleep(5000)
    _AdvancedSplashScreenOFF()
EndFunc   ;==>Example1

Func Example2()
    #include <ButtonConstants.au3>
    #include <StaticConstants.au3>
    Opt("GUIOnEventMode", 1)
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 277, 230, 193, 125)
    GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
    $Button1 = GUICtrlCreateButton("Exit", 90, 200, 75, 25, 0)
    GUICtrlSetOnEvent(-1, "Button1Click")
    _GUICtrlCreatePIC($image, 30, 0)
    GUISetState(@SW_SHOW)
    #EndRegion ### START Koda GUI section ### Form=

    While 1
        Sleep(100)
    WEnd

EndFunc   ;==>Example2

Func Button1Click()
    Exit
EndFunc   ;==>Button1Click
Func Form1Close()
    Exit
EndFunc   ;==>Form1Close
Edited by Armand

Share this post


Link to post
Share on other sites

ok sorry for the post ,probably i am doing something wrong (and i don't have the strenght to look it right now :) ) , can i use a transparent png with this script ? , because i tried few pngs but it always paints the transparent parts with white color.

Share this post


Link to post
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
Sign in to follow this  

×
×
  • Create New...