Jump to content

GUICtrlCreatePic example 2 with a twist


bootybay
 Share

Recommended Posts

When changing the window transparency, the background transparency is completely lost.

In the base example from the AutoIt Help you can move merlin across the screen without the white box around him since it's transparent.

Now I wanted to add a fade in and fade out function (TransUp, TransDown) to make the example 2 a little more spooky:

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

Global $g_hGui, $g_aGuiPos, $g_hPic, $g_aPicPos, $trans = 0

Example()

Func Example()
    $g_hGui = GUICreate("test transparentpic", 200, 100)
    $g_hPic = GUICreate("", 68, 71, 10, 20, $WS_POPUp, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $g_hGui)
    GUICtrlCreatePic("..\GUI\merlin.gif", 0, 0, 0, 0)

    GUISetState(@SW_SHOW, $g_hPic)
    GUISetState(@SW_SHOW, $g_hGui)

    HotKeySet("{ESC}", "Main")
    HotKeySet("{Left}", "Left")
    HotKeySet("{Right}", "Right")
    HotKeySet("{Down}", "Down")
    HotKeySet("{Up}", "Up")
    HotKeySet("{PGUP}", "TransUp")
    HotKeySet("{PGDN}", "TransDown")
    $g_aPicPos = WinGetPos($g_hPic)
    $g_aGuiPos = WinGetPos($g_hGui)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

        EndSwitch
    WEnd

    HotKeySet("{ESC}")
    HotKeySet("{Left}")
    HotKeySet("{Right}")
    HotKeySet("{Down}")
    HotKeySet("{Up}")
EndFunc   ;==>Example

Func Main()
    $g_aGuiPos = WinGetPos($g_hGui)
    WinMove($g_hGui, "", $g_aGuiPos[0] + 10, $g_aGuiPos[1] + 10)
EndFunc   ;==>Main

Func Left()
    $g_aPicPos = WinGetPos($g_hPic)
    WinMove($g_hPic, "", $g_aPicPos[0] - 10, $g_aPicPos[1])
EndFunc   ;==>Left

Func Right()
    $g_aPicPos = WinGetPos($g_hPic)
    WinMove($g_hPic, "", $g_aPicPos[0] + 10, $g_aPicPos[1])
EndFunc   ;==>Right

Func Down()
    $g_aPicPos = WinGetPos($g_hPic)
    WinMove($g_hPic, "", $g_aPicPos[0], $g_aPicPos[1] + 10)
EndFunc   ;==>Down

Func Up()
    $g_aPicPos = WinGetPos($g_hPic)
    WinMove($g_hPic, "", $g_aPicPos[0], $g_aPicPos[1] - 10)
EndFunc   ;==>Up

Func TransUp()
    $trans -= 15
    If $trans < 15 Then $trans = 15
    If $trans > 255 Then $trans = 255
    WinSetTrans($g_hPic, "", $trans)
EndFunc

Func TransDown()
    $trans += 15
    If $trans < 0 Then $trans = 0
    If $trans > 255 Then $trans = 255
    WinSetTrans($g_hPic, "", $trans)
EndFunc

It fades in and out but now you see the white box around merlin. I sadly can't think of a workaround.

I tried changing $g_hGUI and $g_hPic both and in different orders with no effect.

 

This is very important to me. Please guide me!

Edited by bootybay
Link to comment
Share on other sites

or...

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

;~  gone to
;~  https://www.autoitscript.com/wiki/Snippets_(_GUI_)#Animate_Display
;~  for simplicity

Global $g_hGui, $g_aGuiPos, $g_hPic, $g_aPicPos, $trans = 0, $iPic, $hPic

Example()

Func Example()
    $g_hGui = GUICreate("test Animate Display", 200, 100)
    WinSetTrans($g_hGui, "", 150) ; i know, not needed.
    $g_hPic = GUICreate("", 68, 71, 10, 20, $WS_POPUp, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $g_hGui)
    $iPic = GUICtrlCreatePic(StringLeft(@AutoItExe,StringInStr(@AutoItExe,"\", 0, -1)) & "Examples\GUI\merlin.gif",0,0,0,0)
    $hPic = GUICtrlGetHandle($iPic)

    GUISetState(@SW_SHOW, $g_hPic)
    GUISetState(@SW_SHOW, $g_hGui)

    HotKeySet("{ESC}", "Main")
    HotKeySet("{Left}", "Left")
    HotKeySet("{Right}", "Right")
    HotKeySet("{Down}", "Down")
    HotKeySet("{Up}", "Up")
    HotKeySet("{PGUP}", "TransUp")
    HotKeySet("{PGDN}", "TransDown")
    $g_aPicPos = WinGetPos($g_hPic)
    $g_aGuiPos = WinGetPos($g_hGui)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIDelete($g_hPic)
                GUIDelete($g_hGui)
                ExitLoop

        EndSwitch
    WEnd

    HotKeySet("{ESC}")
    HotKeySet("{Left}")
    HotKeySet("{Right}")
    HotKeySet("{Down}")
    HotKeySet("{Up}")
EndFunc   ;==>Example

Func Main()
    $g_aGuiPos = WinGetPos($g_hGui)
    WinMove($g_hGui, "", $g_aGuiPos[0] + 10, $g_aGuiPos[1] + 10)
EndFunc   ;==>Main

Func Left()
    $g_aPicPos = WinGetPos($g_hPic)
    WinMove($g_hPic, "", $g_aPicPos[0] - 10, $g_aPicPos[1])
EndFunc   ;==>Left

Func Right()
    $g_aPicPos = WinGetPos($g_hPic)
    WinMove($g_hPic, "", $g_aPicPos[0] + 10, $g_aPicPos[1])
EndFunc   ;==>Right

Func Down()
    $g_aPicPos = WinGetPos($g_hPic)
    WinMove($g_hPic, "", $g_aPicPos[0], $g_aPicPos[1] + 10)
EndFunc   ;==>Down

Func Up()
    $g_aPicPos = WinGetPos($g_hPic)
    WinMove($g_hPic, "", $g_aPicPos[0], $g_aPicPos[1] - 10)
EndFunc   ;==>Up

Func TransUp()
;~     $trans -= 15
;~     If $trans < 15 Then $trans = 15
;~     If $trans > 255 Then $trans = 255
;~     WinSetTrans($g_hPic, "", $trans)
    DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $g_hPic, "int", 1000, "long", 0x00050010) ; fade-in
EndFunc

Func TransDown()
;~     $trans += 15
;~     If $trans < 0 Then $trans = 0
;~     If $trans > 255 Then $trans = 255
;~     WinSetTrans($g_hPic, "", $trans)
    DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $g_hPic, "int", 1000, "long", 0x00040010) ; fade-out
EndFunc

 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Extended @argumentum example with drag/mouse movement 

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

;~  gone to
;~  https://www.autoitscript.com/wiki/Snippets_(_GUI_)#Animate_Display
;~  for simplicity

Global $g_hGui, $g_aGuiPos, $g_hPic, $g_aPicPos, $trans = 0, $iPic, $hPic

Example()

Func Example()
    local $dragMerlin=false
    
    $g_hGui = GUICreate("test Animate Display", 200, 100)
    WinSetTrans($g_hGui, "", 150) ; i know, not needed.
    $g_hPic = GUICreate("", 68, 71, 10, 20, $WS_POPUp, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $g_hGui)
    $iPic = GUICtrlCreatePic(StringLeft(@AutoItExe,StringInStr(@AutoItExe,"\", 0, -1)) & "Examples\GUI\merlin.gif",0,0,0,0)
    $hPic = GUICtrlGetHandle($iPic)

    GUISetState(@SW_SHOW, $g_hPic)
    GUISetState(@SW_SHOW, $g_hGui)

    HotKeySet("{ESC}", "Main")
    HotKeySet("{Left}", "Left")
    HotKeySet("{Right}", "Right")
    HotKeySet("{Down}", "Down")
    HotKeySet("{Up}", "Up")
    HotKeySet("{PGUP}", "TransUp")
    HotKeySet("{PGDN}", "TransDown")
    $g_aPicPos = WinGetPos($g_hPic)
    $g_aGuiPos = WinGetPos($g_hGui)

    ; Loop until the user exits.
    While 1
;~      consolewrite(@autoitexe)
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIDelete($g_hPic)
                GUIDelete($g_hGui)
                ExitLoop

            case $GUI_EVENT_PRIMARYDOWN
                $dragMerlin=True
                
            case $GUI_EVENT_MOUSEMOVE
                if $dragMerlin then 
                    winmove($g_hPic, "", mousegetpos(0)-32,mousegetpos(1))
                EndIf

            case $GUI_EVENT_PRIMARYUP
                $dragMerlin=false
        EndSwitch
    WEnd

    HotKeySet("{ESC}")
    HotKeySet("{Left}")
    HotKeySet("{Right}")
    HotKeySet("{Down}")
    HotKeySet("{Up}")
EndFunc   ;==>Example

Func Main()
    $g_aGuiPos = WinGetPos($g_hGui)
    WinMove($g_hGui, "", $g_aGuiPos[0] + 10, $g_aGuiPos[1] + 10)
EndFunc   ;==>Main

Func Left()
    $g_aPicPos = WinGetPos($g_hPic)
    WinMove($g_hPic, "", $g_aPicPos[0] - 10, $g_aPicPos[1])
EndFunc   ;==>Left

Func Right()
    $g_aPicPos = WinGetPos($g_hPic)
    WinMove($g_hPic, "", $g_aPicPos[0] + 10, $g_aPicPos[1])
EndFunc   ;==>Right

Func Down()
    $g_aPicPos = WinGetPos($g_hPic)
    WinMove($g_hPic, "", $g_aPicPos[0], $g_aPicPos[1] + 10)
EndFunc   ;==>Down

Func Up()
    $g_aPicPos = WinGetPos($g_hPic)
    WinMove($g_hPic, "", $g_aPicPos[0], $g_aPicPos[1] - 10)
EndFunc   ;==>Up

Func TransUp()
;~     $trans -= 15
;~     If $trans < 15 Then $trans = 15
;~     If $trans > 255 Then $trans = 255
;~     WinSetTrans($g_hPic, "", $trans)
    DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $g_hPic, "int", 1000, "long", 0x00050010) ; fade-in
EndFunc

Func TransDown()
;~     $trans += 15
;~     If $trans < 0 Then $trans = 0
;~     If $trans > 255 Then $trans = 255
;~     WinSetTrans($g_hPic, "", $trans)
    DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $g_hPic, "int", 1000, "long", 0x00040010) ; fade-out
EndFunc

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...