Sign in to follow this  
Followers 0
Luigi

a little help to show/close a gui with fade

3 posts in this topic

Hello forum, I need little help with this code.

This is simple, show a gui with fade, and close-it with fade too.

Not abrupt, apear or disapear.

The code works, but sometimes I need click on Gui to get up.
Sometimes it does not appear.

Maybe I miss a bit code?

Br, Detefon

#AutoIt3Wrapper_AU3Check_Parameters= -q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
#Tidy_Parameters=/sf

#include-once
#include <Array.au3>
#include <Misc.au3>
#include <GUIConstantsEx.au3>

OnAutoItExitRegister("_on_exit")

Opt("GUIOnEventMode", 1)
Opt("GUIEventOptions", 1)
Opt("MustDeclareVars", 1)
Opt("WinWaitDelay", 25)

Global Const $g_iTRANSITION = 7
Global $aGuiSize[2] = [800, 600]
Global $sGuiTitle = "GuiTitle"
Global $hGui

$hGui = GUICreate($sGuiTitle, $aGuiSize[0], $aGuiSize[1])
GUISetOnEvent($GUI_EVENT_CLOSE, "_quit")

WinSetTrans($hGui, $sGuiTitle, 0)
GUISetState(@SW_SHOWNORMAL, $hGui)
For $ii = 0 To 255 Step $g_iTRANSITION
    WinSetTrans($hGui, $sGuiTitle, $ii)
Next

If Not WinActive($hGui, $sGuiTitle) Then WinActivate($hGui, $sGuiTitle)

GUISetState(@SW_SHOW, $hGui)

While Sleep(10)
WEnd

Func _on_exit()
    For $ii = 255 To 0 Step -$g_iTRANSITION
        WinSetTrans($hGui, "", $ii)
    Next
    GUISetState($hGui, @SW_HIDE)
    GUIDelete($hGui)
EndFunc   ;==>_on_exit

Func _quit()
    Exit
EndFunc   ;==>_quit

Visit my repository

Share this post


Link to post
Share on other sites



Here is a rough and dirty to give you an idea, take a look at WinSetTrans in the help file.:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

GUICreate("Test", 300, 300)
GUISetState(@SW_SHOW)

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

GUIDelete()

Func _quit()

$sTrans = 255

    For $i = $sTrans To 0 Step -50
        WinSetTrans("Test", "", $sTrans)
        Sleep(500)
        $sTrans -= 50
    Next

Exit
EndFunc

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Just been going through some old code.

This fades, but stops if you click it while fading.

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WinAPIEx.au3>
;#include <Memory.au3>

_GDIPlus_Startup()

Local $Base64String
$Base64String &= 'iVBORw0KGgoAAAANSUhEUgAAADwAAAAtCAMAAADFqPh+AAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAYNQTFRFAAAK/fnu7+vj1dPPxMPOq6usp6enm5ucpaWk6+jg6ebfn5+glZWYf36ESklkJiYzHR0pBQUPAAAJGxsnJiYxi4uPr6+w4d7Ze3qFFxckSUl2W1u9ZWXGbGzncXHvXl69ray2RERlcHDtExMf9fHoTExrSkmIaGjhdHTmkZHeoKDlqqrrsLDtiYnao6Oi+vbskJCUOjprZ2fXwcHsISEu+fXrSEiauLjvTEy9V1fAnJzjr6/sl5fgUFC+pqbooaGhQkKqZWXNQkK1MzOWRUW4c3PKe3vSMzOdNzdz0M7PhISJJCQwNTWGMTGqjo3VLi6q//vw5OHcyMfPKyuolJPPCgoUIyOeJSWgc3PD29nVHh6YnZ3FGBiUHByWMTGkERGPExORIiKbCQmJDAyLFRWTAABpBgaGAAB2AABkPz9nAAB/AABwAABdAABRAAB6AABHDQ0XAABFFRUmAAA3AAAyAAA9AABWAAAvAABSAAAtAAAnEBAaAAAhAAAbAAAVAAARAAAKMwwy/wAAAAF0Uk5TAEDm2GYAAAABYktHRACIBR1IAAAACXBIWXMAAABIAAAASABGyWs+AAADUklEQVRIx5XW61/SUBgH8DHGNmEbm8BpA4zVFC8FAoENyzBCUzFFS0uNtAsZicGYRGaXf71tXISxzfV9yX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lYXRlZCB3aXRoIENoaW1wbHkuY29tIiIEkkgAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTQtMDQtMDlUMDc6MDM6NDgt'
$Base64String &= 'MDQ6MDBqEUZ/AAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE0LTA0LTA5VDA3OjAzOjQ4LTA0OjAwG0z+wwAAAABJRU5ErkJggg=='

$hHBITMAP = _GDIPlus_BitmapCreateFromMemory(Binary(_Base64Decode($Base64String)), True)
$aDim = _WinAPI_BitmapGetDim($hHBITMAP)
Local $iH = $aDim[0]
Local $iW = $aDim[1]


Global Const $hGUI = GUICreate("Test", 300, 200), $STM_SETIMAGE = 0x0172
GUISetBkColor(0xfffbf0)
Global Const $iPic = GUICtrlCreatePic("", 10, 10, $iW, $iH)
_WinAPI_DeleteObject(GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBITMAP))

DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hGUI, "int", 1000, "long", BitOR(0x00040000, 0x00000008))


GUISetState(@SW_SHOWNOACTIVATE, $hGUI)

Do
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _ExitQ()
        Case $iPic
            _ExitQ()
            ;MsgBox(0, "Test", "Button was pressed")
    EndSwitch
Until False

Func _ExitQ()
    For $i = 255 To 0 Step - 1
        WinSetTrans($hGUI, '', $i)
        Sleep(10)
        If GUIGetMsg() = $GUI_EVENT_PRIMARYDOWN Then
            WinSetTrans($hGUI, '', 255)
            Return
        EndIf

    Next
    _WinAPI_DeleteObject($hHBITMAP)
    _GDIPlus_Shutdown()
    ;DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hGUI, "int", 1000, "long", BitOR(0x00080000, 0x00010000))
    ;Sleep(1000)


    Sleep(100)
    Exit
EndFunc   ;==>_Exit

Func _WinAPI_BitmapGetDim($hHBitmap)
    Local $tDim = DllStructCreate($tagBITMAP)
    DllCall("gdi32.dll", "int", "GetObject", "int", $hHBitmap, "int", DllStructGetSize($tDim), "struct*", $tDim)
    If @error Then Return SetError(1, 0, 0)
    Local $aDim[2] = [$tDim.bmWidth, $tDim.bmHeight]
    Return $aDim
EndFunc

Func _Base64Decode($sB64String)
    Local $struct = DllStructCreate("int")
    Local $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", "str", $sB64String, "int", 0, "int", 1, "ptr", 0, "ptr", DllStructGetPtr($struct, 1), "ptr", 0, "ptr", 0)
    If @error Or Not $a_Call[0] Then Return SetError(1, 0, "")
    Local $a = DllStructCreate("byte[" & DllStructGetData($struct, 1) & "]")
    $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", "str", $sB64String, "int", 0, "int", 1, "ptr", DllStructGetPtr($a), "ptr", DllStructGetPtr($struct, 1), "ptr", 0, "ptr", 0)
    If @error Or Not $a_Call[0] Then Return SetError(2, 0, "")
    Return DllStructGetData($a, 1)
EndFunc   ;==>_Base64Decode

What a co-inky-dink

EDIT:

$Base64String is just an icon button, embedded.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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  
Followers 0