Jump to content

How to have a GIF Animation without borders over a PNG with transparency


Go to solution Solved by Andreik,

Recommended Posts

Posted

Hi !

I am trying to show an animated GIF with transparency (Loading animation) over a PNG GUI that has transparency.

With this code, almost everything is nice except that the GIF animation has borders that i want to remove so i only see the gif itself.  I have tried adding some style html code and it did not work.  Anyone has an idea ?  Thank you :)

 

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WinAPIConstants.au3>
#include <WinAPISysWin.au3>
#include <WindowsConstants.au3>

 _GDIPlus_Startup()

Global Const $SC_DRAGMOVE = 0xF012

$hSplashlogo = _GDIPlus_ImageLoadFromFile("SOME_PNG_WITH_TRANSPARENCY.PNG")

$iw = _GDIPlus_ImageGetWidth($hSplashlogo)
$ih = _GDIPlus_ImageGetHeight($hSplashlogo)
$SplashGUIlogo = GUICreate("", $iw, $ih, -1, -1, $WS_POPUP,  $WS_EX_LAYERED)
_SetBitmap($SplashGUIlogo, $hSplashlogo, 255, $iw, $ih)
$hGUI_c = GUICreate("A_GUI", $iw, $ih, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $SplashGUIlogo)
GUISetBkColor(0x123456, $hGUI_c)
_WinAPI_SetLayeredWindowAttributes($hGUI_c, 0x123456)
        $oObj = ObjCreate("Shell.Explorer.2")
        $oObj_ctrl = GUICtrlCreateObj($oObj,($iw/2)-65,($ih/2)-65,130,130)
        $sGIF = @ScriptDir &"\loading.gif"
        $URL = "about:<html><body bgcolor='#123456' scroll='no'><img src='"&$sGIF&"' width='100%' height='100%' border='0'></img></body></html>"
        $oObj.Navigate($URL)
        GUICtrlSetState(-1,$GUI_DISABLE)

GUICtrlSetBkColor(-1, 0x404040)
GUICtrlSetColor(-1, 0x123456)
GUISetState(@SW_SHOWNA, $SplashGUIlogo)
GUISetState(@SW_SHOW, $hGUI_c)
GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

GUIDelete($hGUI_c)
GUIDelete($SplashGUIlogo)
_GDIPlus_ImageDispose($hSplashlogo)
_GDIPlus_Shutdown()
Exit

Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    _SendMessage($SplashGUIlogo, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
EndFunc   ;==>_WM_LBUTTONDOWN

Func _SetBitmap($hGUI, $hImage, $iOpacity, $n_width = 200, $n_height = 200)
    Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend

    $hScrDC = _WinAPI_GetDC(0)
    $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", $n_width)a
    DllStructSetData($tSize, "Y", $n_height)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", 1)
    _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteDC($hMemDC)
EndFunc   ;==>_SetBitmap


Func _WinAPI_BitmapDisplayTransparentInGUI(ByRef $hHBitmap, ByRef $hGUI, $iOpacity = 0xFF, $bReleaseGDI = True)
    If Not BitAND(GUIGetStyle($hGUI)[1], $WS_EX_LAYERED) = $WS_EX_LAYERED Then Return SetError(1, 0, 0)
    Local $tDim = DllStructCreate($tagBITMAP)
    If Not _WinAPI_GetObject($hHBitmap, DllStructGetSize($tDim), DllStructGetPtr($tDim)) Then Return SetError(2, 0, 0)
    Local $tSize = DllStructCreate($tagSIZE), $tSource = DllStructCreate($tagPOINT), $tBlend = DllStructCreate($tagBLENDFUNCTION)
    Local Const $hScrDC = _WinAPI_GetDC(0), $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC), $hOld = _WinAPI_SelectObject($hMemDC, $hHBitmap)
    $tSize.X = $tDim.bmWidth
    $tSize.Y = $tDim.bmHeight
    $tBlend.Alpha = $iOpacity
    $tBlend.Format = 1
    _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, DllStructGetPtr($tSize), $hMemDC, DllStructGetPtr($tSource), 0, DllStructGetPtr($tBlend), $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteDC($hMemDC)
    If $bReleaseGDI Then _WinAPI_DeleteObject($hHBitmap)
    Return True
EndFunc

 

  • Solution
Posted
$URL = "about:<style> body { border: 0;}</style><html><body bgcolor='#123456' scroll='no'><img src='"&$sGIF&"' width='100%' height='100%' border='0'></img></body></html>"

 

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
×
×
  • Create New...