Trở về
Tham gia nhóm m Autoit đ đưc hưng dn và gii đáp trc tiếp : http://fb.com/groups/autoitscript
Tin tức công nghệ  -  Thủ thuật lập trình

Friday, October 18, 2013

Hướng dẫn tạo Splash Image (Khung giới thiệu phần mềm) bằng Autoit


Toàn màn hìnhIn bài viết

Screenshot:


Bước 1 : Các bạn tải 3 file swf này về giải nén ra thư mục splash


Bước 2 : Save UDF với tên : ModernSplash.au3

#include <GUIConstantsEx.au3>
#include <SendMessage.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
;By Max Reble (GtaSpider)
;V 1.3
;ModernSplash by Max Reble is provided under the terms of the create commons public license.
;http://creativecommons.org/licenses/by/3.0/us/
;http://creativecommons.org/licenses/by/3.0/de/
;You are free to Share and to Remix
;But you must attribute the work in the manner specified by the author or licensor (Max Reble)
;...

Global $b_Opt_GuiOnEventMode = 0
Global $bModernSplash_Created = False
Global $bModernSplash_Initiated = False
Global $PI = 3.14159265358979

Global $oModernSplash_Flash

Global $iModernSplash_CopyrightTrans = 120 ;Never ever under 100 please!

Global $sModernSplash_Movie

Global $hModernSplash_Parent, $hModernSplash_ClientText, $hModernSplash_ClientText_Label, $hModernSplash_ClientTitle, _
        $hModernSplash_ClientTitle_Label, $hModernSplash_ClientTitle_Label_Build, $hModernSplash_Parent_Vid,$hModernSplash_Dummy, _
        $hModernSplash_ClientClose,$hModernSplash_CallBack_Exit = "", $hModernSplash_ClientProgress, $hModernSplash_ClientProgress_Prog, $hModernSplash_ClientCopyright

Func _ModernSplash_Create($sTitle, $sBuild = "", $bProgress = False, $sCallBack_Exit = "",$iCorners = 20, $sMovieFile = "", $iTextColor = 0x000000, $sFont = "Arial")
    $oModernSplash_Flash = ObjCreate("ShockwaveFlash.ShockwaveFlash")
    If Not IsObj($oModernSplash_Flash) Then Return SetError(1,0,0)
    If $iCorners Then
        If $iCorners > 20 Then $iCorners = 20
        If $iCorners < 0 Then $iCorners = 0
    EndIf
    If Not $sMovieFile Then $sMovieFile = @ScriptDir & "\back.swf"
    If $sCallBack_Exit Then $hModernSplash_CallBack_Exit = $sCallBack_Exit
    $sModernSplash_Movie = $sMovieFile
    $hModernSplash_Parent = GUICreate($sTitle, 500, 300, -1, -1, $WS_POPUP)
    If $iCorners Then __GuiRoundCorners($hModernSplash_Parent, $iCorners, $iCorners, $iCorners, $iCorners)
    GUISetOnEvent(-3, "_ModernSplash_ExitGui")
    $FlashCtrl = GUICtrlCreateObj($oModernSplash_Flash, 0, 0, 500, 300)


    $hModernSplash_ClientText = GUICreate("ClientText", 400, 60, 60, 200, $WS_POPUP, BitOR($WS_EX_MDICHILD, $WS_EX_LAYERED), $hModernSplash_Parent)
    GUISetOnEvent(-3, "_ModernSplash_ExitGui")
    GUISetBkColor(0x333333)
    $hModernSplash_ClientText_Label = GUICtrlCreateLabel("", 0, 40, 400, 40)
    GUICtrlSetColor(-1,$iTextColor)
    GUICtrlSetFont(-1, 10, 400, 0, $sFont,4);ANTIALIASED_QUALITY = AA = 4
    GUICtrlSetBkColor(-1, -2)

    #region Copyright by Max Reble - If you remove this Region, you have to name me otherwise in your script or you incur a penatly!
    $hModernSplash_ClientCopyright = GUICreate("C",177,20,(500/2)-(177/2),21,$WS_POPUP, BitOR($WS_EX_MDICHILD, $WS_EX_LAYERED), $hModernSplash_Parent)
    __GuiRoundCorners($hModernSplash_ClientCopyright,2,2,2,2)
    GUISetOnEvent(-3, "_ModernSplash_ExitGui")
    GUISetBkColor(0x333333)
    GUICtrlCreateLabel("Loading-Screen by Max Reble",0,0,177,20,2);SS_RIGHT
    GUICtrlSetOnEvent(-1,"__MaxRebleHP")
    GUICtrlSetBkColor(-1,0xffffff)
    GUICtrlSetColor(-1,0x0044CC);Microsoft's 80-million-dollar-blue ;-)
    GUICtrlSetFont(-1,10,400,4,$sFont,4);AA
    GUICtrlSetCursor(-1,0)
    _WinAPI_SetLayeredWindowAttributes($hModernSplash_ClientCopyright, 0x333333, 0)
    #endregion

    $hModernSplash_ClientTitle = GUICreate("ClientTitle", 300, 110, 60, 90, $WS_POPUP, BitOR($WS_EX_MDICHILD, $WS_EX_LAYERED), $hModernSplash_Parent)
    GUISetBkColor(0x333333)
    GUISetOnEvent(-3, "_ModernSplash_ExitGui")
    $hModernSplash_ClientTitle_Label = GUICtrlCreateLabel($sTitle, 0, 0, 300, 49)
    GUICtrlSetColor(-1,$iTextColor)
    GUICtrlSetFont(-1, 32,400,0,$sFont,4);AA
    $hModernSplash_ClientTitle_Label_Build = GUICtrlCreateLabel($sBuild, 20, 69, 300, 60)
    GUICtrlSetColor(-1,$iTextColor)
    GUICtrlSetFont(-1, 16,400,0,$sFont,4);AA

    $hModernSplash_Dummy = GUICreate("Dummy", 500, 300, 0, 0, $WS_POPUP, BitOR($WS_EX_MDICHILD, $WS_EX_LAYERED), $hModernSplash_Parent)
    GUISetBkColor(0x333333)
    GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "__PrimaryDown")
    _WinAPI_SetLayeredWindowAttributes($hModernSplash_ClientTitle, 0x333333, 0)


    $hModernSplash_ClientProgress = GUICreate("ClientProgress", 497, 30, 4+($iCorners/20), 273, $WS_POPUP, BitOR($WS_EX_MDICHILD, $WS_EX_LAYERED), $hModernSplash_Parent)
    GUISetOnEvent(-3, "_ModernSplash_ExitGui")
    $hModernSplash_ClientProgress_Prog = GUICtrlCreateProgress(0,20,497,10)
    GUISetBkColor(0x333333)
    _WinAPI_SetLayeredWindowAttributes($hModernSplash_ClientProgress, 0x333333, 200)
    If $iCorners Then __GuiRoundCorners($hModernSplash_ClientProgress, $iCorners,$iCorners,$iCorners,$iCorners)

;~     $hModernSplash_ClientClose = GUICreate("Close", 40, 40, 450, 40, $WS_POPUP, BitOR($WS_EX_MDICHILD, $WS_EX_LAYERED), $hModernSplash_Parent)
;~     GUISetBkColor(0x333333)
;~     _WinAPI_SetLayeredWindowAttributes($hModernSplash_ClientClose, 0x333333, 255)
;~     GUICtrlCreateLabel("X",0,0,40,40)
;~     GUICtrlSetColor(-1,$iTextColor)
;~     GUICtrlSetOnEvent(-1,"_ModernSplash_ExitGui")
;~     GUICtrlSetFont(-1,32,400,0,$sFont,4);AA

    Global $bModernSplash_Created = True
    Return $hModernSplash_Parent
EndFunc   ;==>_ModernSplash_Create


Func _ModernSplash_Initiate($sText)
    If Not IsObj($oModernSplash_Flash) Then Return SetError(1,0,0)
    HotKeySet("{ESC}","_ModernSplash_CheckExitHotKey")
    If Not $bModernSplash_Created Then Return SetError(1, 0, 0)
    Global $b_Opt_GuiOnEventMode = Opt("GuiOnEventMode", 1)
    With $oModernSplash_Flash
        .Movie = $sModernSplash_Movie
        .wmode = "opaque"
        .allowScriptAccess = "Always"
    EndWith
    _WinAPI_SetLayeredWindowAttributes($hModernSplash_ClientTitle, 0x333333, 0)
    _WinAPI_SetLayeredWindowAttributes($hModernSplash_ClientText, 0x333333, 0)
    WinSetTrans($hModernSplash_Parent, "", 0)
    GUISetState(@SW_SHOW, $hModernSplash_Parent)
    GUISetState(@SW_SHOW, $hModernSplash_ClientText)
    GUISetState(@SW_SHOW, $hModernSplash_ClientTitle)
    GUISetState(@SW_SHOW, $hModernSplash_Dummy)
    GUISetState(@SW_SHOW, $hModernSplash_ClientClose)
    GUISetState(@SW_SHOW, $hModernSplash_ClientProgress)
    GUISetState(@SW_SHOW, $hModernSplash_ClientCopyright)
    Local $i

    For $i = 0 To 255 Step 15
        WinSetTrans($hModernSplash_Parent, "", $i)
        ControlMove($hModernSplash_ClientTitle, "", $hModernSplash_ClientTitle_Label, 20 - (20 * $i / 255), 0)
        ControlMove($hModernSplash_ClientTitle, "", $hModernSplash_ClientTitle_Label_Build, 20 - (20 * $i / 255), 50 + (20 - (20 * $i / 255)))
        _WinAPI_SetLayeredWindowAttributes($hModernSplash_ClientTitle, 0x333333, $i)
        If $i < $iModernSplash_CopyrightTrans Then _WinAPI_SetLayeredWindowAttributes($hModernSplash_ClientCopyright, 0x333333, $i)
        Sleep(Sin((90 * $i / 255) * ($PI / 180)) * 30)
    Next
    ControlMove($hModernSplash_ClientTitle, "", $hModernSplash_ClientTitle_Label, 0, 0)
    ControlMove($hModernSplash_ClientTitle, "", $hModernSplash_ClientTitle_Label_Build, 0, 50)
    _WinAPI_SetLayeredWindowAttributes($hModernSplash_ClientTitle, 0x333333, 255)
    Global $bModernSplash_Initiated = True
    _ModernSplash_TextNext($sText, True)
    Return True
EndFunc   ;==>_ModernSplash_Initiate

Func _ModernSplash_CheckExit()
    Switch WinGetHandle("")
        Case $hModernSplash_ClientText, $hModernSplash_ClientTitle, $hModernSplash_ClientClose,$hModernSplash_Dummy,$hModernSplash_Parent, $hModernSplash_ClientProgress
            _ModernSplash_ExitGui()
            Return 1
        Case Else
            Return 0
    EndSwitch
EndFunc

Func _ModernSplash_CheckExitHotKey()
    If Not _ModernSplash_CheckExit() Then
        HotKeySet("{ESC}")
        Send("{esc}")
        HotKeySet("{ESC}","_ModernSplash_CheckExitHotKey")
    EndIf
EndFunc


Func _ModernSplash_DeInitiate()
    If Not $bModernSplash_Initiated Then Return SetError(1, 0, 0)
    HotKeySet("{ESC}")
    _ModernSplash_TextNext("", False, True)
    _ModernSplash_ProgressMarquee(False)
    Local $i
    For $i = 255 To 0 Step -15
        WinSetTrans($hModernSplash_Parent, "", $i)
        _WinAPI_SetLayeredWindowAttributes($hModernSplash_ClientTitle, 0x333333, $i)
        _WinAPI_SetLayeredWindowAttributes($hModernSplash_ClientClose, 0x333333, $i)
        _WinAPI_SetLayeredWindowAttributes($hModernSplash_ClientProgress, 0x333333, $i)
        If $i < $iModernSplash_CopyrightTrans Then _WinAPI_SetLayeredWindowAttributes($hModernSplash_ClientCopyright, 0x333333, $i)
        Sleep(10)
    Next
    GUIDelete($hModernSplash_ClientText)
    GUIDelete($hModernSplash_ClientTitle)
    GUIDelete($hModernSplash_Parent)
    Global $bModernSplash_Created = False
    Global $bModernSplash_Initiated = False
    Opt("GuiOnEventMode", $b_Opt_GuiOnEventMode)

EndFunc   ;==>_ModernSplash_DeInitiate

Func _ModernSplash_ExitGui()
    _ModernSplash_DeInitiate()
    ConsoleWrite($hModernSplash_CallBack_Exit & @CRLF)
    If $hModernSplash_CallBack_Exit Then Call($hModernSplash_CallBack_Exit)
EndFunc


Func _ModernSplash_TextNext($sText, $bFirst = False, $bLast = False)
    Local $i
    If Not $bModernSplash_Initiated Then Return SetError(1, 0, 0)
    If Not $bFirst Then
        For $i = 255 To 0 Step -20
            _WinAPI_SetLayeredWindowAttributes($hModernSplash_ClientText, 0x333333, $i)
            ControlMove($hModernSplash_ClientText, "", $hModernSplash_ClientText_Label, 0, 20 - (20 - (20 * $i / 255)))
            Sleep(Sin((90 * $i / 255) * ($PI / 180)) * 10)
        Next
        _WinAPI_SetLayeredWindowAttributes($hModernSplash_ClientText, 0x333333, 0)
    EndIf
    If Not $bLast Then
        GUICtrlSetData($hModernSplash_ClientText_Label, $sText)
        For $i = 0 To 255 Step 15
            _WinAPI_SetLayeredWindowAttributes($hModernSplash_ClientText, 0x333333, $i)
            ControlMove($hModernSplash_ClientText, "", $hModernSplash_ClientText_Label, 0, 40 - (20 * $i / 255))
            Sleep(Sin((90 * $i / 255) * ($PI / 180)) * 30)
        Next
        _WinAPI_SetLayeredWindowAttributes($hModernSplash_ClientText, 0x333333, 255)
    EndIf
EndFunc   ;==>_ModernSplash_TextNext

Func _ModernSplash_TextChange($sText)
    GUICtrlSetData($hModernSplash_ClientText_Label,$sText)
EndFunc

Func _ModernSplash_ProgressUpdate($iPercentage)
    GUICtrlSetData($hModernSplash_ClientProgress_Prog,$iPercentage)
EndFunc

Func _ModernSplash_ProgressMarquee($iMarquee) ;False/true
    If $iMarquee Then
        GUICtrlSetStyle($hModernSplash_ClientProgress_Prog,0x040A)
        _SendMessage(GUICtrlGetHandle($hModernSplash_ClientProgress_Prog), 0x040A, True, $iMarquee) ;0x040A = PBS_MARQUEE
    Else
        GUICtrlSetStyle($hModernSplash_ClientProgress_Prog,0)
        _SendMessage(GUICtrlGetHandle($hModernSplash_ClientProgress_Prog), 0x040A, False, 0) ;0x040A = PBS_MARQUEE
    EndIf
EndFunc

Func _ModernSplash_ProgressColor($iState); 1 = Normal(green), 2 = Error(red) 3 = Pause(yellow)
    If @OSBuild < 6000 Then Return SetError(1,0,0);only works on vista/server08 or higher
    _SendMessage(GUICtrlGetHandle($hModernSplash_ClientProgress_Prog),0x400 + 16,$iState,0); $PBM_SETSTATE (WM_USER + 16)
EndFunc

Func __GuiRoundCorners($h_win, $i_x1, $i_y1, $i_x3, $i_y3) ; thanks gafrost
    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   ;==>__GuiRoundCorners

Func __MaxRebleHP()
    ShellExecute("http://www.maxreble.de/")
EndFunc


Func __PrimaryDown()
    _SendMessage($hModernSplash_Parent, $WM_SYSCOMMAND, 0xF012, 0);SC_DRAGMOVE
EndFunc   ;==>__PrimaryDown

Bước 3 : Và lưu code mẫu với tên tùy ý *.au3

#include "ModernSplash.au3"

;                    $sTitle,             $sBuild = "",                $bProgress = False,    $sCallBack_Exit = "",    $iCorners = 20, $sMovieFile = "", $sFont = "Arial"
$hWnd = _ModernSplash_Create(    "ModernSplash",    "v1.3 ("&FileGetTime(@ScriptFullPath,0,1)&")",    True,            "",                20,@ScriptDir&"\splash\back_orange.swf");Warning, changed now...

_ModernSplash_Initiate("Load...");First initiate. Stat with Text: "Load..."

;Progress Marquee. As higher the number (10) as slower the marquee!
_ModernSplash_ProgressMarquee(10)
_ModernSplash_TextNext("Loading resources...")
Sleep(100);do smth
_ModernSplash_TextNext("This is a quite long text to test how quite long textes looks like on this splash and i think it looks quite nice, doesn't it?")
Sleep(500);do smth
_ModernSplash_DeInitiate()

$hWnd = _ModernSplash_Create(    "ModernSplash",    "v1.3 ("&FileGetTime(@ScriptFullPath,0,1)&")",    True,            "_exit",                20,@ScriptDir&"\splash\back_blue.swf",0xffffff);Warning, changed now...
_ModernSplash_Initiate("Max rox! Also with blue background!")

MsgBox(0,"","You can try to exit the Splash by clicking on the X on the right or push esc"&@CRLF&"It will close then after this messagebox dissappears",0,$hWnd)
_ModernSplash_DeInitiate()
$hWnd = _ModernSplash_Create(    "ModernSplash",    "v1.3 ("&FileGetTime(@ScriptFullPath,0,1)&")",    True,            "_exit",                20,@ScriptDir&"\splash\back_orange.swf");Warning, changed now...
_ModernSplash_Initiate("...and orange again!")
;Stop Marquee
_ModernSplash_ProgressMarquee(False)
$ms = 0
For $i = 1 To 10
    _ModernSplash_TextChange("Ping Google"&@CRLF&$i&"/10");Update text without animation
    $ms += Ping("www.google.de")
    _ModernSplash_ProgressUpdate($i*10);Update Progress
    If $i = 6 Then
        _ModernSplash_ProgressColor(3);Make Progress Yellow (only vista/server08 or higher)
        MsgBox(0,"","Yellow Progress Color",0,$hWnd)
    EndIf
    If $i = 9 Then _ModernSplash_ProgressColor(1);Reset Progress to green
    Sleep(200)
Next
_ModernSplash_ProgressColor(2);Make Progess Red (only vista/server08 or higher)
_ModernSplash_TextNext("Roundtrip: "&Round($ms/10)&"ms")
Sleep(500)
_ModernSplash_DeInitiate()
$hWnd = _ModernSplash_Create(    "ModernSplash",    "v1.3 ("&FileGetTime(@ScriptFullPath,0,1)&")",    True,            "_exit",                20,@ScriptDir&"\splash\back_green.swf",0x00ff00);Warning, changed now...
_ModernSplash_Initiate("What do you think about green?")
_ModernSplash_TextNext("Mesagebox")
MsgBox(0,"","Click ok to continue or watch this beautiful animation. Hope you have enough time, its endless ;-)",0,$hWnd)

MsgBox(0,"","Programm succesfull loaded :)")
Func _exit()
    MsgBox(0,"","You abborted loading...script exit now!")
    Exit
EndFunc

Bước 4 : Các bạn thay đổi thông số trong code mẫu và kiểm nghiệm thành quả của mình ^^