Jump to content
timmy2

Smooth display of PNGs with transparency, fade-in/out and AOT

Recommended Posts

timmy2

l93c.png

After UEZ helped me with the Countdown Timer his techniques seemed perfect for displaying individual images with transparency. One thing led to another and here's the resulting script.

Download the attached zip file and place the 5 PNG files in the same folder as this script. I did not embed the images in the script, to make the script easier to read and so you can see the actual images used.

In my opinion the ultimate next step would be to add the ability to play animated GIFs, still with transparency if that's possible.

Enjoy! (with much gratitude to UEZ for his help)

; Functions coded by UEZ 2013-10-29
; Updated to address issues 2013-10-31
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#NoTrayIcon

_GDIPlus_Startup() ;initiate GDI+

#region
; timmy2's simple demonstration of UEZ's code
;
; display blank chalkboard (there will be no fade-in so use default $iAlpha value of 255)
$aRes1 = DisplayImage( "Wood-framed-chalkboard.png", -1, -1 )
Sleep (500)

; add first two steps
$aRes2 = DisplayImage("step-1.png", -1, -1 )
Sleep(2000)
$aRes3 = DisplayImage("step-2.png", -1, -1 )

; fade in handdrawn circle (therefore start with $iAlpha = 0)
$aPos = WinGetPos($aRes1[0]) ;required because the chalkboard is displayed at screen center, which varies based on resolution (doh!)
$aRes4 = DisplayImage("circle.png",  $aPos[0] + 290, $aPos[1] + 75, 0)
sleep (500)
_Fader($aRes4)
sleep(1000)
_Fader($aRes4, False)
ReleaseResources($aRes4)
sleep(500)


; add third step
$aRes5 = DisplayImage("step-3.png", -1, -1 )
Sleep(2000)

; fade the three steps out in reverse order (faster than defaults)
_Fader($aRes5, False, 255, 5, 5)
ReleaseResources($aRes5)
_Fader($aRes3, False, 255, 5, 5)
ReleaseResources($aRes3)
_Fader($aRes2, False, 255, 5, 5)
ReleaseResources($aRes2)

Sleep(500)

; fade out chockboard
_Fader($aRes1, False, 255, 10, 5)
ReleaseResources($aRes1)
#endregion

_GDIPlus_Shutdown()

Exit

; Display the image at center unless otherwise specified. If Fader will not be used then $iAlpha's default of 0xFF is good.
; If Fader will be used then start with $iAlpha equal to zero.  Option to make this image "Always on top" is also available.
Func DisplayImage($sFile, $iPosX = -1, $iPosY = -1, $iAlpha = 0xFF, $bTopmost = True)
    Local Const $hBmp_Background = _GDIPlus_BitmapCreateFromFile($sFile) ;load the image
    If @error Then Return SetError(1, 0, 0) ;image cannot be loaded
    Local Const $iW = _GDIPlus_ImageGetWidth($hBmp_Background), $iH = _GDIPlus_ImageGetHeight($hBmp_Background) ;get the dimension of the background image
    Local Const $hGUI = GUICreate("", $iW, $iH, $iPosX, $iPosY, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST * $bTopmost, $WS_EX_TOOLWINDOW)) ;create GUI with appropriate styles and extented style (borderless transparent GUI)
    GUICtrlCreateLabel("", 0, 0, $iW, $iH, Default, $GUI_WS_EX_PARENTDRAG) ;create a hidden label for GUI dragging
    GUISetState(@SW_SHOW, $hGUI) ;show GUI

    Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) ;define an empty bitmap where all the gfx stuff will copied to
    Local Const $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap) ;get the context to the bitmap to be able to copy / draw to the bitmap
    _GDIPlus_GraphicsDrawImageRect($hGfx, $hBmp_Background, 0, 0, $iW, $iH) ;draw background image to the empty bitmap

    ;display GDI+ with transparency on desktop
    Local Const $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) ;convert GDI+ image to GDI to display it on the screen using GDI functions
    Local Const $hScrDC = _WinAPI_GetDC($hGUI) ;get the device context (dc) handle of the GUI
    Local Const $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC) ;create a compatible dc handle
    Local Const $hOld = _WinAPI_SelectObject($hMemDC, $hHBitmap) ;selects the GDI bitmap object into the specified device context
    Local Const $tSize = DllStructCreate($tagSIZE) ;create a $tagSIZE struct (x = width, y = height)
    DllStructSetData($tSize, "X", $iW) ;set data for width
    DllStructSetData($tSize, "Y", $iH) ;set data for height
    Local $tSource = DllStructCreate($tagPOINT) ;create a $tagPOINT struct (x = x position, y = y position)
    Local $tBlend = DllStructCreate($tagBLENDFUNCTION) ;create $tagBLENDFUNCTION struct -> see help file for more info
    DllStructSetData($tBlend, "Alpha", $iAlpha) ;set the alpha channel of the GUI -> 255 = opaque, 0 = transparent
    DllStructSetData($tBlend, "Format", 1) ;set the format to 1 -> bitmap has alpha channels
    DllCall("user32.dll", "bool", "UpdateLayeredWindow", "hwnd", $hGUI, "handle", $hScrDC, "ptr", 0, "struct*", $tSize, "handle", $hMemDC, "struct*", $tSource, "dword", 0, "struct*", $tBlend, "dword", $ULW_ALPHA) ;display bitmap on screen

    ;release resources otherwise memory will filled up (memory leak)
    _GDIPlus_GraphicsDispose($hGfx)
    _GDIPlus_BitmapDispose($hBitmap)
    Local $aResource[7] = [$hGUI, $hScrDC, $hHBitmap, $hMemDC, $tBlend, $tSize, $tSource] ;return the handle to release it later
    Return $aResource
EndFunc   ;==>DisplayImage

; This function releases the resources of a specific image and closes it
Func ReleaseResources(ByRef $aResource)
    If Not IsArray($aResource) Then Return SetError(1, 0, 0)
    If UBound($aResource) <> 7 Then Return SetError(2, 0, 0)
    _WinAPI_ReleaseDC($aResource[0], $aResource[1])
    _WinAPI_DeleteDC($aResource[3])
    _WinAPI_DeleteObject($aResource[2])
    GUIDelete($aResource[0])
EndFunc   ;==>ReleaseResources

; To fade in an image leave $bIn at default (True); to fade out specify False.
; There are also options to set the ending transparency level (0 transparent, 255 opaque), speed and delay.
; If you change the speed or delay be sure to specify $bIn and $iTrans, otherwise you'll wonder why the fade-in or out isn't what you hoped for.
; The default values are specified in the function below.
Func _Fader($res1, $bIn = True, $iTrans = 255, $speed = 3, $delay = 10  )
    If Not IsArray($res1) Then Return SetError(1, 0, 0)
    If UBound($res1) <> 7 Then Return SetError(2, 0, 0)
    Switch $bIn
        Case True
            For $a = 0 To $iTrans Step $speed
                DllStructSetData($res1[4], "Alpha", $a)
                DllCall("user32.dll", "bool", "UpdateLayeredWindow", "hwnd", $res1[0], "handle", $res1[1], "ptr", 0, "struct*", $res1[5], "handle", $res1[3], "struct*", $res1[6], "dword", 0, "struct*", $res1[4], "dword", $ULW_ALPHA) ;display bitmap on screen
                Sleep($delay)
            Next
        Case Else
            For $a = $iTrans To 0 Step -$speed
                DllStructSetData($res1[4], "Alpha", $a)
                DllCall("user32.dll", "bool", "UpdateLayeredWindow", "hwnd", $res1[0], "handle", $res1[1], "ptr", 0, "struct*", $res1[5], "handle", $res1[3], "struct*", $res1[6], "dword", 0, "struct*", $res1[4], "dword", $ULW_ALPHA) ;display bitmap on screen
                Sleep($delay)
            Next
    EndSwitch
EndFunc   ;==>_FadeIn



#region GDI and GDI+ functions
Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iPixelFormat = $GDIP_PXF32ARGB, $iStride = 0, $pScan0 = 0)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "handle*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0] Then Return SetError(10, $aResult[0], 0)
    Return $aResult[6]
EndFunc   ;==>_GDIPlus_BitmapCreateFromScan0
#endregion GDI and GDI+ functions

images.zip

Edited by timmy2
  • Like 2

Share this post


Link to post
Share on other sites
UEZ

Seems to be that an image wasn't loaded properly.

 

Try this function and check error code please:

Func _Fader($res1, $bIn = True, $iTrans = 255, $speed = 3, $delay = 10  )
    If Not IsArray($res1) Then Return SetError(1, 0, 0)
    If UBound($res1) <> 7 Then Return SetError(2, 0, 0)
    Switch $bIn
        Case True
            For $a = 0 To $iTrans Step $speed
                DllStructSetData($res1[4], "Alpha", $a)
                DllCall("user32.dll", "bool", "UpdateLayeredWindow", "hwnd", $res1[0], "handle", $res1[1], "ptr", 0, "struct*", $res1[5], "handle", $res1[3], "struct*", $res1[6], "dword", 0, "struct*", $res1[4], "dword", $ULW_ALPHA) ;display bitmap on screen
                Sleep($delay)
            Next
        Case Else
            For $a = $iTrans To 0 Step -$speed
                DllStructSetData($res1[4], "Alpha", $a)
                DllCall("user32.dll", "bool", "UpdateLayeredWindow", "hwnd", $res1[0], "handle", $res1[1], "ptr", 0, "struct*", $res1[5], "handle", $res1[3], "struct*", $res1[6], "dword", 0, "struct*", $res1[4], "dword", $ULW_ALPHA) ;display bitmap on screen
                Sleep($delay)
            Next
    EndSwitch
EndFunc   ;==>_FadeIn
Br,

UEZ

Edited by UEZ
  • Like 1

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
UEZ

Further, due to different screen resolutions the circle is only placed properly when the screen resolution is the same as yours.

Try this instead:

; fade in handdrawn circle (therefore start with $iAlpha = 0)
$aPos = WinGetPos($aRes1[0])
$aRes4 = DisplayImage("circle.png",  $aPos[0] + 290, $aPos[1] + 75, 0)
sleep (500)
_Fader($aRes4)
sleep(1000)
_Fader($aRes4, False)
ReleaseResources($aRes4)
sleep(500)

; add third step

Br,

UEZ

  • Like 1

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
mesale0077

line 26 error

$aPos = WinGetPos($aRes1[0])

Share this post


Link to post
Share on other sites
UEZ

Replace these lines and post the result:

$aRes1 = DisplayImage( "Wood-framed-chalkboard.png", -1, -1 )
If @error Then Exit MsgBox(0, "", @error)

Further test with 

$aRes1 = DisplayImage( @ScriptDir & "\Wood-framed-chalkboard.png", -1, -1 )

Be sure that the images are in the same folder as the script!

Br,

UEZ

Edited by UEZ
  • Like 1

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
dmob

Very nice, I think of a few uses for this.

Share this post


Link to post
Share on other sites
timmy2

Your main function...

$aRes1 = DisplayImage("step-1.png")

...returns an array in $aRes1.  To use WinMove with this image the correct instruction is:

WinMove($aRes1[0], "", 500, 600)

So, the first element in the array at index zero is a handle useable by WinMove. That leaves 7 other elements in the array, correct?

(If UBound($aResource) <> 7 Then Return SetError(2, 0, 0))

I'm curious. What is stored in these other elements?

Share this post


Link to post
Share on other sites
dmob

I'm curious. What is stored in these other elements?

Check the bottom of the DisplayImage() function.

Share this post


Link to post
Share on other sites
UEZ

Your main function...

$aRes1 = DisplayImage("step-1.png")

...returns an array in $aRes1.  To use WinMove with this image the correct instruction is:

WinMove($aRes1[0], "", 500, 600)

So, the first element in the array at index zero is a handle useable by WinMove. That leaves 7 other elements in the array, correct?

(If UBound($aResource) <> 7 Then Return SetError(2, 0, 0))

I'm curious. What is stored in these other elements?

 

Here more information about the returned array:

Local $aResource[7] = [$hGUI, _ ;GUI handle
                           $hScrDC, _ ;device context (dc) handle of the GUI (GDI)
                           $hHBitmap, _ ;GDI bitmap handle of the displayed image
                           $hMemDC, _ ;compatible dc handle from $hScrDC
                           $tBlend, _ ;tBlend struct (source blend oper., flags, alpha value, format) -> see help file for description
                           $tSize, _ ;tSize struct (width and height of the window / image)
                           $tSource] ;tSource struct for x / y position of the GUI
    Return $aResource ;returns the handles to release it later or to use it for fading effects

Here the complete code:

; Functions coded by UEZ 2013-11-02
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#NoTrayIcon

_GDIPlus_Startup() ;initiate GDI+

#region
; timmy2's simple demonstration of UEZ's code
;
; display blank chalkboard (there will be no fade-in so use default $iAlpha value of 255)
$aRes1 = DisplayImage( "Wood-framed-chalkboard.png", -1, -1 )
If @error Then
    ConsoleWrite( "Error " & @error & " has occured." & @LF )
    _GDIPlus_Shutdown()
    Exit
EndIf

Sleep (500)

; add first two steps
$aRes2 = DisplayImage("step-1.png", -1, -1 )
Sleep(2000)
$aRes3 = DisplayImage("step-2.png", -1, -1 )

; fade in handdrawn circle (therefore start with $iAlpha = 0)
$aPos = WinGetPos($aRes1[0])
$aRes4 = DisplayImage("circle.png",  $aPos[0] + 290, $aPos[1] + 75, 0)
sleep (500)
_Fader($aRes4)
sleep(1000)
_Fader($aRes4, False)
ReleaseResources($aRes4)
sleep(500)

; add third step
$aRes5 = DisplayImage("step-3.png", -1, -1 )
Sleep(2000)

; fade the three steps out in reverse order (faster than defaults)
_Fader($aRes5, False, 255, 5, 5)
ReleaseResources($aRes5)
_Fader($aRes3, False, 255, 5, 5)
ReleaseResources($aRes3)
_Fader($aRes2, False, 255, 5, 5)
ReleaseResources($aRes2)

Sleep(500)

; fade out chockboard
_Fader($aRes1, False, 255, 10, 5)
ReleaseResources($aRes1)
#endregion

_GDIPlus_Shutdown()

Exit

; Display the image at center unless otherwise specified. If Fader will not be used then $iAlpha's default of 0xFF is good.
; If Fader will be used then start with $iAlpha equal to zero.  Option to make this image "Always on top" is also available.
Func DisplayImage($sFile, $iPosX = -1, $iPosY = -1, $iAlpha = 0xFF, $bTopmost = True)
    Local Const $hBmp_Background = _GDIPlus_BitmapCreateFromFile($sFile) ;load the image
    If @error Then Return SetError(1, 0, 0) ;image cannot be loaded
    Local Const $iW = _GDIPlus_ImageGetWidth($hBmp_Background), $iH = _GDIPlus_ImageGetHeight($hBmp_Background) ;get the dimension of the background image
    Local Const $hGUI = GUICreate("", $iW, $iH, $iPosX, $iPosY, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST * $bTopmost, $WS_EX_TOOLWINDOW)) ;create GUI with appropriate styles and extented style (borderless transparent GUI)
    GUICtrlCreateLabel("", 0, 0, $iW, $iH, Default, $GUI_WS_EX_PARENTDRAG) ;create a hidden label for GUI dragging
    GUISetState(@SW_SHOW, $hGUI) ;show GUI

    Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) ;define an empty bitmap where all the gfx stuff will copied to
    Local Const $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap) ;get the context to the bitmap to be able to copy / draw to the bitmap
    _GDIPlus_GraphicsDrawImageRect($hGfx, $hBmp_Background, 0, 0, $iW, $iH) ;draw background image to the empty bitmap

    ;display GDI+ with transparency on desktop
    Local Const $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) ;convert GDI+ image to GDI to display it on the screen using GDI functions
    Local Const $hScrDC = _WinAPI_GetDC($hGUI) ;get the device context (dc) handle of the GUI
    Local Const $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC) ;create a compatible dc handle
    Local Const $hOld = _WinAPI_SelectObject($hMemDC, $hHBitmap) ;selects the GDI bitmap object into the specified device context
    Local Const $tSize = DllStructCreate($tagSIZE) ;create a $tagSIZE struct (x = width, y = height)
    DllStructSetData($tSize, "X", $iW) ;set data for width
    DllStructSetData($tSize, "Y", $iH) ;set data for height
    Local $tSource = DllStructCreate($tagPOINT) ;create a $tagPOINT struct (x = x position, y = y position)
    Local $tBlend = DllStructCreate($tagBLENDFUNCTION) ;create $tagBLENDFUNCTION struct -> see help file for more info
    DllStructSetData($tBlend, "Alpha", $iAlpha) ;set the alpha channel of the GUI -> 255 = opaque, 0 = transparent
    DllStructSetData($tBlend, "Format", 1) ;set the format to 1 -> bitmap has alpha channels
    DllCall("user32.dll", "bool", "UpdateLayeredWindow", "hwnd", $hGUI, "handle", $hScrDC, "ptr", 0, "struct*", $tSize, "handle", $hMemDC, "struct*", $tSource, "dword", 0, "struct*", $tBlend, "dword", $ULW_ALPHA) ;display bitmap on screen

    ;release resources otherwise memory will filled up (memory leak)
    _GDIPlus_GraphicsDispose($hGfx)
    _GDIPlus_BitmapDispose($hBitmap)
    Local $aResource[7] = [$hGUI, _ ;GUI handle
                           $hScrDC, _ ;device context (dc) handle of the GUI (GDI)
                           $hHBitmap, _ ;GDI bitmap handle of the displayed image
                           $hMemDC, _ ;compatible dc handle from $hScrDC
                           $tBlend, _ ;tBlend struct (source blend oper., flags, alpha value, format) -> see help file for description
                           $tSize, _ ;tSize struct (width and height of the window / image)
                           $tSource] ;tSource struct for x / y position of the GUI
    Return $aResource ;returns the handles to release it later or to use it for fading effects
EndFunc   ;==>DisplayImage

; This function releases the resources of a specific image and closes it
Func ReleaseResources(ByRef $aResource)
    If Not IsArray($aResource) Then Return SetError(1, 0, 0)
    If UBound($aResource) <> 7 Then Return SetError(2, 0, 0)
    _WinAPI_ReleaseDC($aResource[0], $aResource[1])
    _WinAPI_DeleteDC($aResource[3])
    _WinAPI_DeleteObject($aResource[2])
    GUIDelete($aResource[0])
EndFunc   ;==>ReleaseResources

; To fade in an image leave $bIn at default (True); to fade out specify False.
; There are also options to set the ending transparency level (0 transparent, 255 opaque), speed and delay.
; If you change the speed or delay be sure to specify $bIn and $iTrans, otherwise you'll wonder why the fade-in or out isn't what you hoped for.
; The default values are specified in the function below.
Func _Fader($res1, $bIn = True, $iTrans = 255, $speed = 3, $delay = 10  )
    If Not IsArray($res1) Then Return SetError(1, 0, 0)
    If UBound($res1) <> 7 Then Return SetError(2, 0, 0)
    Switch $bIn
        Case True
            For $a = 0 To $iTrans Step $speed
                DllStructSetData($res1[4], "Alpha", $a)
                DllCall("user32.dll", "bool", "UpdateLayeredWindow", "hwnd", $res1[0], "handle", $res1[1], "ptr", 0, "struct*", $res1[5], "handle", $res1[3], "struct*", $res1[6], "dword", 0, "struct*", $res1[4], "dword", $ULW_ALPHA) ;display bitmap on screen
                Sleep($delay)
            Next
        Case Else
            For $a = $iTrans To 0 Step -$speed
                DllStructSetData($res1[4], "Alpha", $a)
                DllCall("user32.dll", "bool", "UpdateLayeredWindow", "hwnd", $res1[0], "handle", $res1[1], "ptr", 0, "struct*", $res1[5], "handle", $res1[3], "struct*", $res1[6], "dword", 0, "struct*", $res1[4], "dword", $ULW_ALPHA) ;display bitmap on screen
                Sleep($delay)
            Next
    EndSwitch
EndFunc   ;==>_FadeIn

#region GDI and GDI+ functions
Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iPixelFormat = $GDIP_PXF32ARGB, $iStride = 0, $pScan0 = 0)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "handle*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0] Then Return SetError(10, $aResult[0], 0)
    Return $aResult[6]
EndFunc   ;==>_GDIPlus_BitmapCreateFromScan0
#endregion GDI and GDI+ functions

Br,

UEZ

Edited by UEZ
  • Like 1

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
timmy2

Can GUISetAccelerators be used with your code?  If not, what is the best way to add the ability to wait for some specific keys to be pressed without passing them through? 

8lcx.jpg

The only methods for waiting for keystrokes that I'm somewhat conversant with are _IsPressed and HotKeySet. The former allows all keystrokes to be passed through; the latter allows all keys other than the hotkeys to pass through. I don't want any keystrokes to pass through and want the "hotkeys" valid only when the graphic is displayed.

Edited by timmy2

Share this post


Link to post
Share on other sites
timmy2

For another project I'm working on I came up with the following script. It has no relationship with UEZ's DisplayImage function but it'll serve as a solution until something better comes along. When the GUI is active it does not pass keystrokes through, but only when the GUI is active. In a separate thread I'm trying to chase down whether the BlockInputEX UDF can be used to truly isolate input to this form only.

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

$form = GUICreate("test", 0, 0,-1,-1,BitOR($WS_SYSMENU,$WS_POPUP))

$sHelp = GUICtrlCreateDummy()
$sRepeat = GUICtrlCreateDummy()
$sQuit = GUICtrlCreateDummy()
Dim $AccelKeys[3][2] = [["h", $sHelp],["r", $sRepeat],["q", $SQuit]]
GUISetAccelerators($AccelKeys)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $sHelp
            ConsoleWrite("help" & @CRLF)
        Case $sRepeat
            ConsoleWrite("repeat" & @CRLF)
        Case $SQuit
            ConsoleWrite("quit" & @CRLF)
    EndSwitch
WEnd
Edited by timmy2

Share this post


Link to post
Share on other sites
UEZ

You can use something like this here:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test")
GUISetState()
Global $aKeyboardState

Do
    If WinActive($hGUI) Then
        $aKeyboardState = _WinAPI_GetKeyboardState()
        If BitAND($aKeyboardState[0x48], 0xF0) > 0 Then
            ConsoleWrite("H key was pressed" & @LF)
        ElseIf BitAND($aKeyboardState[0x51], 0xF0) > 0 Then
            ConsoleWrite("Q key was pressed" & @LF)
        ElseIf BitAND($aKeyboardState[0x52], 0xF0) > 0 Then
            ConsoleWrite("R key was pressed" & @LF)
        EndIf
    EndIf
Until GUIGetMsg() = $GUI_EVENT_CLOSE


; #FUNCTION# ====================================================================================================================
; Name...........:  _WinAPI_GetKeyboardState
; Description ...:  Returns the status of the 256 virtual keys
; Syntax.........:  _WinAPI_GetKeyboardState($iFlag=0)
; Parameters ....:  $iFlag   - Return Type
;                   0 Returns an array[256]
;                   1 Returns a string
; Return values .:  Success  - Array[256] or String containing status of 256 virtual keys
;                   Failure  - False
; Author ........:  Eukalyptus
; Modified.......:
; Remarks .......:  If the high-order bit is 1, the key is down; otherwise, it is up.
;                   If the key is a toggle key, for example CAPS LOCK, then the low-order bit is 1
;                   when the key is toggled and is 0 if the key is untoggled
; Related .......:  _IsPressed
; Link ..........;
; Example .......;
; ===============================================================================================================================
Func _WinAPI_GetKeyboardState($iFlag = 0)
    Local $aDllRet, $lpKeyState = DllStructCreate("byte[256]")
    $aDllRet = DllCall("User32.dll", "int", "GetKeyboardState", "ptr", DllStructGetPtr($lpKeyState))
    If @error Then Return SetError(@error, 0, 0)
    If $aDllRet[0] = 0 Then
        Return SetError(1, 0, 0)
    Else
        Switch $iFlag
            Case 0
                Local $aReturn[256]
                For $i = 1 To 256
                    $aReturn[$i - 1] = DllStructGetData($lpKeyState, 1, $i)
                Next
                Return $aReturn
            Case Else
                Return DllStructGetData($lpKeyState, 1)
        EndSwitch
    EndIf
EndFunc   ;==>_WinAPI_GetKeyboardState

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
DHL

Hi. Thanks for a nice code example. I'm having some issues getting it to work properly:

When I try running this example, nothing appears. I get no error messages in console, but still nothing is displayed.

The images are located in the same folder as the script. I also tried adding @ScriptDir, but without any luck.

I tried removing the styles from GUICreate, just to see if the windows appeared on my desktop, and that worked, but the window contents were just gray (no image/content) and no image faded in/out.

_GDIPlus_ImageGetWidth, etc. reports the correct values, so it seems to be an issue with displaying the images on the Gui.

I'm running Autoit 3.3.6.1 on Win 8.1.

I'm using UEZs code "Complete Code"-example, Posted 02 November 2013 - 01:49 PM:

; Functions coded by UEZ 2013-11-02
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#NoTrayIcon

_GDIPlus_Startup() ;initiate GDI+

#region
; timmy2's simple demonstration of UEZ's code
;
; display blank chalkboard (there will be no fade-in so use default $iAlpha value of 255)
$aRes1 = DisplayImage( "Wood-framed-chalkboard.png", -1, -1 )
If @error Then
    ConsoleWrite( "Error " & @error & " has occured." & @LF )
    _GDIPlus_Shutdown()
    Exit
EndIf

Sleep (500)

; add first two steps
$aRes2 = DisplayImage("step-1.png", -1, -1 )
Sleep(2000)
$aRes3 = DisplayImage("step-2.png", -1, -1 )

; fade in handdrawn circle (therefore start with $iAlpha = 0)
$aPos = WinGetPos($aRes1[0])
$aRes4 = DisplayImage("circle.png",  $aPos[0] + 290, $aPos[1] + 75, 0)
sleep (500)
_Fader($aRes4)
sleep(1000)
_Fader($aRes4, False)
ReleaseResources($aRes4)
sleep(500)

; add third step
$aRes5 = DisplayImage("step-3.png", -1, -1 )
Sleep(2000)

; fade the three steps out in reverse order (faster than defaults)
_Fader($aRes5, False, 255, 5, 5)
ReleaseResources($aRes5)
_Fader($aRes3, False, 255, 5, 5)
ReleaseResources($aRes3)
_Fader($aRes2, False, 255, 5, 5)
ReleaseResources($aRes2)

Sleep(500)

; fade out chockboard
_Fader($aRes1, False, 255, 10, 5)
ReleaseResources($aRes1)
#endregion

_GDIPlus_Shutdown()

Exit

; Display the image at center unless otherwise specified. If Fader will not be used then $iAlpha's default of 0xFF is good.
; If Fader will be used then start with $iAlpha equal to zero.  Option to make this image "Always on top" is also available.
Func DisplayImage($sFile, $iPosX = -1, $iPosY = -1, $iAlpha = 0xFF, $bTopmost = True)
    Local Const $hBmp_Background = _GDIPlus_BitmapCreateFromFile($sFile) ;load the image
    If @error Then Return SetError(1, 0, 0) ;image cannot be loaded
    Local Const $iW = _GDIPlus_ImageGetWidth($hBmp_Background), $iH = _GDIPlus_ImageGetHeight($hBmp_Background) ;get the dimension of the background image
    Local Const $hGUI = GUICreate("", $iW, $iH, $iPosX, $iPosY, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST * $bTopmost, $WS_EX_TOOLWINDOW)) ;create GUI with appropriate styles and extented style (borderless transparent GUI)
    GUICtrlCreateLabel("", 0, 0, $iW, $iH, Default, $GUI_WS_EX_PARENTDRAG) ;create a hidden label for GUI dragging
    GUISetState(@SW_SHOW, $hGUI) ;show GUI

    Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) ;define an empty bitmap where all the gfx stuff will copied to
    Local Const $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap) ;get the context to the bitmap to be able to copy / draw to the bitmap
    _GDIPlus_GraphicsDrawImageRect($hGfx, $hBmp_Background, 0, 0, $iW, $iH) ;draw background image to the empty bitmap

    ;display GDI+ with transparency on desktop
    Local Const $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) ;convert GDI+ image to GDI to display it on the screen using GDI functions
    Local Const $hScrDC = _WinAPI_GetDC($hGUI) ;get the device context (dc) handle of the GUI
    Local Const $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC) ;create a compatible dc handle
    Local Const $hOld = _WinAPI_SelectObject($hMemDC, $hHBitmap) ;selects the GDI bitmap object into the specified device context
    Local Const $tSize = DllStructCreate($tagSIZE) ;create a $tagSIZE struct (x = width, y = height)
    DllStructSetData($tSize, "X", $iW) ;set data for width
    DllStructSetData($tSize, "Y", $iH) ;set data for height
    Local $tSource = DllStructCreate($tagPOINT) ;create a $tagPOINT struct (x = x position, y = y position)
    Local $tBlend = DllStructCreate($tagBLENDFUNCTION) ;create $tagBLENDFUNCTION struct -> see help file for more info
    DllStructSetData($tBlend, "Alpha", $iAlpha) ;set the alpha channel of the GUI -> 255 = opaque, 0 = transparent
    DllStructSetData($tBlend, "Format", 1) ;set the format to 1 -> bitmap has alpha channels
    DllCall("user32.dll", "bool", "UpdateLayeredWindow", "hwnd", $hGUI, "handle", $hScrDC, "ptr", 0, "struct*", $tSize, "handle", $hMemDC, "struct*", $tSource, "dword", 0, "struct*", $tBlend, "dword", $ULW_ALPHA) ;display bitmap on screen

    ;release resources otherwise memory will filled up (memory leak)
    _GDIPlus_GraphicsDispose($hGfx)
    _GDIPlus_BitmapDispose($hBitmap)
    Local $aResource[7] = [$hGUI, _ ;GUI handle
                           $hScrDC, _ ;device context (dc) handle of the GUI (GDI)
                           $hHBitmap, _ ;GDI bitmap handle of the displayed image
                           $hMemDC, _ ;compatible dc handle from $hScrDC
                           $tBlend, _ ;tBlend struct (source blend oper., flags, alpha value, format) -> see help file for description
                           $tSize, _ ;tSize struct (width and height of the window / image)
                           $tSource] ;tSource struct for x / y position of the GUI
    Return $aResource ;returns the handles to release it later or to use it for fading effects
EndFunc   ;==>DisplayImage

; This function releases the resources of a specific image and closes it
Func ReleaseResources(ByRef $aResource)
    If Not IsArray($aResource) Then Return SetError(1, 0, 0)
    If UBound($aResource) <> 7 Then Return SetError(2, 0, 0)
    _WinAPI_ReleaseDC($aResource[0], $aResource[1])
    _WinAPI_DeleteDC($aResource[3])
    _WinAPI_DeleteObject($aResource[2])
    GUIDelete($aResource[0])
EndFunc   ;==>ReleaseResources

; To fade in an image leave $bIn at default (True); to fade out specify False.
; There are also options to set the ending transparency level (0 transparent, 255 opaque), speed and delay.
; If you change the speed or delay be sure to specify $bIn and $iTrans, otherwise you'll wonder why the fade-in or out isn't what you hoped for.
; The default values are specified in the function below.
Func _Fader($res1, $bIn = True, $iTrans = 255, $speed = 3, $delay = 10  )
    If Not IsArray($res1) Then Return SetError(1, 0, 0)
    If UBound($res1) <> 7 Then Return SetError(2, 0, 0)
    Switch $bIn
        Case True
            For $a = 0 To $iTrans Step $speed
                DllStructSetData($res1[4], "Alpha", $a)
                DllCall("user32.dll", "bool", "UpdateLayeredWindow", "hwnd", $res1[0], "handle", $res1[1], "ptr", 0, "struct*", $res1[5], "handle", $res1[3], "struct*", $res1[6], "dword", 0, "struct*", $res1[4], "dword", $ULW_ALPHA) ;display bitmap on screen
                Sleep($delay)
            Next
        Case Else
            For $a = $iTrans To 0 Step -$speed
                DllStructSetData($res1[4], "Alpha", $a)
                DllCall("user32.dll", "bool", "UpdateLayeredWindow", "hwnd", $res1[0], "handle", $res1[1], "ptr", 0, "struct*", $res1[5], "handle", $res1[3], "struct*", $res1[6], "dword", 0, "struct*", $res1[4], "dword", $ULW_ALPHA) ;display bitmap on screen
                Sleep($delay)
            Next
    EndSwitch
EndFunc   ;==>_FadeIn

#region GDI and GDI+ functions
Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iPixelFormat = $GDIP_PXF32ARGB, $iStride = 0, $pScan0 = 0)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "handle*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0] Then Return SetError(10, $aResult[0], 0)
    Return $aResult[6]
EndFunc   ;==>_GDIPlus_BitmapCreateFromScan0
#endregion GDI and GDI+ functions

Share this post


Link to post
Share on other sites
UEZ

Works properly on Win8.1. Update to the latest AutoIt version and removed the _GDIPlus_BitmapCreateFromScan0 function because it is already included.

Try again.

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
qwert

This chalkboard example has great potential for a variety of uses ... if one aspect could be changed:

How can all the displayed elements be set so that when the chalkboard is dragged, those elements move with it? ... yet, have each element remain positionable on the chalkboard.

Each element is enabled with:

    GUICtrlCreateLabel("", 0, 0, $iW, $iH, Default, $GUI_WS_EX_PARENTDRAG) ;create a hidden label for GUI dragging
 

But the coordinates are absolute, not relative to the chalkboard.  Would this involve the GUICoordMode setting?  Is it even practical to consider this?

Thanks in advance for any suggestions/ideas.

Share this post


Link to post
Share on other sites
timmy2
On 5/19/2014 at 5:27 PM, qwert said:

This chalkboard example has great potential for a variety of uses ... if one aspect could be changed:

How can all the displayed elements be set so that when the chalkboard is dragged, those elements move with it? ... yet, have each element remain positionable on the chalkboard.

Each element is enabled with:

    GUICtrlCreateLabel("", 0, 0, $iW, $iH, Default, $GUI_WS_EX_PARENTDRAG) ;create a hidden label for GUI dragging
 

But the coordinates are absolute, not relative to the chalkboard.  Would this involve the GUICoordMode setting?  Is it even practical to consider this?

Thanks in advance for any suggestions/ideas.

Great idea! Any luck finding a solution?

Share this post


Link to post
Share on other sites
timmy2

I just tried compiling the script I posted as well as @UEZ's full version and get the following error message. It used to compile fine! :> 

What is the fix? (please)

 

new compiler error.png

Share this post


Link to post
Share on other sites
UEZ

Your break was too long I think. ;)

 

Replace $ghGDIPDLL with $__g_hGDIPDll and it should or use latest AutoIt version.


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
timmy2

I suppose I should change my username to Rip Van Winkle.

Before resuming my use of AutoIt after the long sleep I downloaded the production version v3.3.14.2.  The beta version appears to predate it.  What version do you recommend?

FYI, I replaced $ghGDIPDLL with $__g_hGDIPDll and that fixed the "undeclared global variable" error, but I'm still getting the "already defined" error -- with v3.3.14.2.

 

Am glad to see you're still active after lo these many years.

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

  • Similar Content

    • Chimp
      By Chimp
      If you set within a window, a given color as transparent, every area of that window painted with that color, act as an hole through wich you can see what's behind, and click on what's behind as well.
      What's funny is that if you embed a browser control within that window, the "transparent" color works even within the browser! This allow some interesting effects by simply opening any of the many javascript animations, or css effects or whatever within a browser control embedded into a GUI:
      Here, for example, is a simple effect of fishes swimming around on the screen.
      For lazyness I have embedded an ready made swf flash by a link to the web, but is of course possible embed any web page with javascripts css or whatever.....
      Have fun
      #include <WinAPI.au3> #include <WindowsConstants.au3> #include <Misc.au3> ; for _IsPressed (23 END key) Local $hDLL = DllOpen("user32.dll"), $oIE = ObjCreate("Shell.Explorer.2") Local $hBackground = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUPWINDOW, $WS_EX_LAYERED + $WS_EX_TOPMOST) Local $AlphaKey = 0xF0F7FF ; everything with color $AlphaKey within this window will be transparent ; even if within an embedded browser control!..... _WinAPI_SetLayeredWindowAttributes($hBackground, $AlphaKey, 0, $LWA_COLORKEY) GUISetState(@SW_SHOW, $hBackground) $hIE = GUICtrlCreateObj($oIE, 0, 0, @DesktopWidth, @DesktopHeight) ; <- embedd $oIE in the AutoIt GUI GUISetBkColor($AlphaKey, $hBackground) ; $AlphaKey $hBackground transparent $oIE.navigate('http://cdn.abowman.com/widgets/fish/fish.swf') ; $oIE.navigate('http://cdn.abowman.com/widgets/spider/spider.swf') ; a spider goes around on the screen .... ; !! to use the spider.swf, you need to set $AlphaKey = 0xffffff on line 7 "! While True If _IsPressed("23", $hDLL) Then ExitLoop ; END key was pressed Sleep(250) WEnd $oIE = "" $hDLL = "" GUIDelete($hBackground)  
    • timmy2
      By timmy2
      The following demo script, drawn largely from examples by @UEZ, lets me display colored text over a transparent background using my choice of font, type size, etc.  It is a single function (out of many) in the project I'm scripting, but it is crucial to my goal of displaying messages in an interesting way (IMHO).  
      (For the purpose of this forum post it displays a single string variable; my actual project script reads a number of  possible messages from a text file into an array and then chooses the messages to be displayed based on stuff that happens in the course of someone using my program.)
      Note that I am seeking help only to overcome my inability to figure out how to display this text atop a PNG graphic, and make the result a draggable object.
       
      #cs Display a message one character at a time with the goal of adding a PNG graphic overlay #ce ;~ #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <GUIConstants.au3> Global $sMessage Global $iString = 0 Global $aInfo Global Const $SC_DRAGMOVE = 0xF012 HotKeySet("{Esc}","Close") ; in my actual script I read in a file containing all the text to be displayed Global $sText = _ "Lorem ipsum dolor sit amet, consectetur" & @CRLF & _ "elit, sed do eiusmod tempor incididunt ut" & @CRLF & _ @CRLF & _ "Et dolore magna aliqua. Ut enim ad minim," & @CRLF & _ "quis nostrud exercitation ullamco laboris nisi" & @CRLF & _ "aliquip ex ea commodo consequat." & @CRLF & _ @CRLF & _ "Duis aute irure dolor in reprehenderit in" & @CRLF & _ "voluptate velit esse cillum dolore eu fugiat" & @CRLF & _ "nulla pariatur." & @CRLF ; Create GUI Global $hGUI = GUICreate("", 450, 340, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST)) GUISetBkColor(0xFF000000) ; will change background color, which UEZ doesn't use in his example, but then he doesn't want a BG GUISetState(@SW_SHOW) ; Draw a string _GDIPlus_Startup() Global $hBrush = _GDIPlus_BrushCreateSolid(0xFF99ff33) Global $hFormat = _GDIPlus_StringFormatCreate() Global $hFamily = _GDIPlus_FontFamilyCreate("VT323") Global $hFont = _GDIPlus_FontCreate($hFamily, 14, 0) Global $tLayout = _GDIPlus_RectFCreate(20, 20, 0, 0) Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) Global $hBitmap = _GDIPlus_BitmapCreateFromScan0(420, 300) Global $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetTextRenderingHint($hBuffer, 4) _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 4) GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN") For $iString = 1 to StringLen($sText) $sMessage = StringLeft($sText,$iString) $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sMessage, $hFont, $tLayout, $hFormat) _GDIPlus_GraphicsClear($hBuffer, 0x000000) _GDIPlus_GraphicsDrawStringEx($hBuffer, $sMessage, $hFont, $aInfo[0], $hFormat, $hBrush) $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _WinAPI_BitmapDisplayTransparentInGUI($hHBitmap, $hGUI) _WinAPI_DeleteObject($hHBitmap) Next Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Close() ; Clean up resources (my best guess at what needs closing/shutting down) Func Close() _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hBitmap) _GDIPlus_Shutdown() Exit EndFunc ;==>Close 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 Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam) Switch $hWnd Case $hGUI _SendMessage($hWnd, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0) EndSwitch EndFunc ;==>_WM_LBUTTONDOWN  
      The above script lets me push the text out to the screen, but I want to display the text atop a PNG graphic, which is an imagined piece of hand-held test equipment that I'll refer to here as the Veeblefetzer.
      Here's a half-size animated gif of the desired result.

       
      Note that initially I used a different script to stream the text out atop a built-in black background rectangle.  I figured I would place the Veeblefetzer graphic above the text -- with the center "display area" of the Veeblefetzer cut out (transparent).  
      Then UEZ's example script came along. The benefit of using text that has a transparent BG, and placing it in a layer above the Veeblefetzer, is this lets me include reflections in the Veeblefetzer's display.
      Now to the challenges I'm ill-equipped to figure out.  
      The function I use to display the Veeblefetzer is below. It, too, is drawn from some of examples by @UEZ.
      There are actually two functions below, one I use to display the PNG graphic, and one that can be used to fade the graphic in or out.  I include it here only because it might be applicable to my ancillary goal of needing to clear the text on the handheld display before streaming the next message onto the Veeblefetzer's display.  I realize that the fade in/out function is for graphic objects, so it may not be applicable to text. 
       
      ; Display the image at center unless otherwise specified. If Fader will not be used then $iAlpha's default of 0xFF is good. ; If Fader will be used then start with $iAlpha equal to zero. Option to make this image "Always on top" is also available. Func DisplayImage($sFile, $iPosX = -1, $iPosY = -1, $iAlpha = 0xFF, $bTopmost = True) Local Const $hBmp_Background = _GDIPlus_BitmapCreateFromFile($sFile) ;load the image If @error Then Return SetError(1, 0, 0) ;image cannot be loaded Local Const $iW = _GDIPlus_ImageGetWidth($hBmp_Background), $iH = _GDIPlus_ImageGetHeight($hBmp_Background) ;get the dimension of the background image Local Const $hGUI = GUICreate("", $iW, $iH, $iPosX, $iPosY, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST * $bTopmost, $WS_EX_TOOLWINDOW)) ;create GUI with appropriate styles and extented style (borderless transparent GUI) GUICtrlCreateLabel("", 0, 0, $iW, $iH, Default, $GUI_WS_EX_PARENTDRAG) ;create a hidden label for GUI dragging GUISetState(@SW_SHOW, $hGUI) ;show GUI Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) ;define an empty bitmap where all the gfx stuff will copied to Local Const $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap) ;get the context to the bitmap to be able to copy / draw to the bitmap _GDIPlus_GraphicsDrawImageRect($hGfx, $hBmp_Background, 0, 0, $iW, $iH) ;draw background image to the empty bitmap ;display GDI+ with transparency on desktop Local Const $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) ;convert GDI+ image to GDI to display it on the screen using GDI functions Local Const $hScrDC = _WinAPI_GetDC($hGUI) ;get the device context (dc) handle of the GUI Local Const $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC) ;create a compatible dc handle Local Const $hOld = _WinAPI_SelectObject($hMemDC, $hHBitmap) ;selects the GDI bitmap object into the specified device context Local Const $tSize = DllStructCreate($tagSIZE) ;create a $tagSIZE struct (x = width, y = height) DllStructSetData($tSize, "X", $iW) ;set data for width DllStructSetData($tSize, "Y", $iH) ;set data for height Local $tSource = DllStructCreate($tagPOINT) ;create a $tagPOINT struct (x = x position, y = y position) Local $tBlend = DllStructCreate($tagBLENDFUNCTION) ;create $tagBLENDFUNCTION struct -> see help file for more info DllStructSetData($tBlend, "Alpha", $iAlpha) ;set the alpha channel of the GUI -> 255 = opaque, 0 = transparent DllStructSetData($tBlend, "Format", 1) ;set the format to 1 -> bitmap has alpha channels DllCall("user32.dll", "bool", "UpdateLayeredWindow", "hwnd", $hGUI, "handle", $hScrDC, "ptr", 0, "struct*", $tSize, "handle", $hMemDC, "struct*", $tSource, "dword", 0, "struct*", $tBlend, "dword", $ULW_ALPHA) ;display bitmap on screen ;release resources otherwise memory will filled up (memory leak) _GDIPlus_GraphicsDispose($hGfx) _GDIPlus_BitmapDispose($hBitmap) Local $aResource[7] = [$hGUI, _ ;GUI handle $hScrDC, _ ;device context (dc) handle of the GUI (GDI) $hHBitmap, _ ;GDI bitmap handle of the displayed image $hMemDC, _ ;compatible dc handle from $hScrDC $tBlend, _ ;tBlend struct (source blend oper., flags, alpha value, format) -> see help file for description $tSize, _ ;tSize struct (width and height of the window / image) $tSource] ;tSource struct for x / y position of the GUI Return $aResource ;returns the handles to release it later or to use it for fading effects EndFunc ;==>DisplayImage ; This function releases the resources of a specific image and closes it Func ReleaseResources(ByRef $aResource) If Not IsArray($aResource) Then Return SetError(1, 0, 0) If UBound($aResource) <> 7 Then Return SetError(2, 0, 0) _WinAPI_ReleaseDC($aResource[0], $aResource[1]) _WinAPI_DeleteDC($aResource[3]) _WinAPI_DeleteObject($aResource[2]) GUIDelete($aResource[0]) EndFunc ;==>ReleaseResources ; To fade in an image leave $bIn at default (True); to fade out specify False. ; There are also options to set the ending transparency level (0 transparent, 255 opaque), speed and delay. ; If you change the speed or delay be sure to specify $bIn and $iTrans, otherwise you'll wonder why the fade-in or out isn't what you hoped for. ; The default values are specified in the function below. Func _Fader($res1, $bIn = True, $iTrans = 255, $speed = 3, $delay = 10 ) If Not IsArray($res1) Then Return SetError(1, 0, 0) If UBound($res1) <> 7 Then Return SetError(2, 0, 0) Switch $bIn Case True For $a = 0 To $iTrans Step $speed DllStructSetData($res1[4], "Alpha", $a) DllCall("user32.dll", "bool", "UpdateLayeredWindow", "hwnd", $res1[0], "handle", $res1[1], "ptr", 0, "struct*", $res1[5], "handle", $res1[3], "struct*", $res1[6], "dword", 0, "struct*", $res1[4], "dword", $ULW_ALPHA) ;display bitmap on screen Sleep($delay) Next Case Else For $a = $iTrans To 0 Step -$speed DllStructSetData($res1[4], "Alpha", $a) DllCall("user32.dll", "bool", "UpdateLayeredWindow", "hwnd", $res1[0], "handle", $res1[1], "ptr", 0, "struct*", $res1[5], "handle", $res1[3], "struct*", $res1[6], "dword", 0, "struct*", $res1[4], "dword", $ULW_ALPHA) ;display bitmap on screen Sleep($delay) Next EndSwitch EndFunc ;==>_FadeIn  
      Is anyone willing to step in and show me how to use the text display function along with the PNG display function, so that the resulting Veeblefetzer will be a single draggable object on screen?
      I'm equally baffled about how to properly clear off one message before displaying the next.
      The reason?   I have only the most rudimentary grasp of the commands within -- or the relationships between -- what seem like three distinct sections common to each of UEZ's scripts:
      Initialization (which defines a number of attributes, some of which are obvious to me, for text in this case)
      _GDIPlus_Startup() Global $hBrush = _GDIPlus_BrushCreateSolid(0xFF99ff33) Global $hFormat = _GDIPlus_StringFormatCreate() Global $hFamily = _GDIPlus_FontFamilyCreate("VT323") Global $hFont = _GDIPlus_FontCreate($hFamily, 14, 0) Global $tLayout = _GDIPlus_RectFCreate(20, 20, 0, 0) Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) Global $hBitmap = _GDIPlus_BitmapCreateFromScan0(420, 300) Global $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetTextRenderingHint($hBuffer, 4) _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 4)  
      Delivery... (apparently what's needed to display the text)
      $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sMessage, $hFont, $tLayout, $hFormat) _GDIPlus_GraphicsClear($hBuffer, 0x000000) _GDIPlus_GraphicsDrawStringEx($hBuffer, $sMessage, $hFont, $aInfo[0], $hFormat, $hBrush) $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _WinAPI_BitmapDisplayTransparentInGUI($hHBitmap, $hGUI) _WinAPI_DeleteObject($hHBitmap) Even at my primitive level of understanding I have figured out that you can reuse the above "delivery" section to display other strings before proceeding to the next section.
       
      Cleanup... (apparently needed to release resources, which to me is like closing a previously opened file: it's part of the process so I'll do it):
      _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hBitmap) _GDIPlus_Shutdown()  
      (You're getting an inside look at a monkey brain at work here!)
      UEZ's script to display the PNG graphic follows a similar pattern. What I cannot figure out is how to merge the two scripts, while avoiding redundancy and conflicts. To clear the text between messages must I release any resources, and if so: which ones? AND, how do I group the PNG graphic with the text so the resulting "object" can be moved around on the screen?
       
       
    • PINTO1927
      By PINTO1927
       
      Hi guys, I would like to make a gui borderless viewing a png image with transparent background.
       
      pretty much has to be visible only the png image with no background..you have any simple example?
      Thank's
      GUICtrlCreatePic  
      still it provides the image with the background...
    • wakillon
      By wakillon
      Convert SVG file to PNG using Cairo and rsvg libraries (and their imports)
      #Region ;************ Includes ************ #include <File.au3> #EndRegion ;************ Includes ************ ; typedef enum _cairo_status Global Const $CAIRO_STATUS_SUCCESS = 0 Global Const $CAIRO_STATUS_NO_MEMORY = 1 Global Const $CAIRO_STATUS_INVALID_RESTORE = 2 Global Const $CAIRO_STATUS_INVALID_POP_GROUP = 3 Global Const $CAIRO_STATUS_NO_CURRENT_POINT = 4 Global Const $CAIRO_STATUS_INVALID_MATRIX = 5 Global Const $CAIRO_STATUS_INVALID_STATUS = 6 Global Const $CAIRO_STATUS_NULL_POINTER = 7 Global Const $CAIRO_STATUS_INVALID_STRING = 8 Global Const $CAIRO_STATUS_INVALID_PATH_DATA = 9 Global Const $CAIRO_STATUS_READ_ERROR = 10 Global Const $CAIRO_STATUS_WRITE_ERROR = 11 Global Const $CAIRO_STATUS_SURFACE_FINISHED = 12 Global Const $CAIRO_STATUS_SURFACE_TYPE_MISMATCH = 13 Global Const $CAIRO_STATUS_PATTERN_TYPE_MISMATCH = 14 Global Const $CAIRO_STATUS_INVALID_CONTENT = 15 Global Const $CAIRO_STATUS_INVALID_FORMAT = 16 Global Const $CAIRO_STATUS_INVALID_VISUAL = 17 Global Const $CAIRO_STATUS_FILE_NOT_FOUND = 18 Global Const $CAIRO_STATUS_INVALID_DASH = 19 Global Const $CAIRO_STATUS_INVALID_DSC_COMMENT = 20 Global Const $CAIRO_STATUS_INVALID_INDEX = 21 Global Const $CAIRO_STATUS_CLIP_NOT_REPRESENTABLE = 22 Global Const $CAIRO_STATUS_TEMP_FILE_ERROR = 23 Global Const $CAIRO_STATUS_INVALID_STRIDE = 24 Global Const $CAIRO_STATUS_FONT_TYPE_MISMATCH = 25 Global Const $CAIRO_STATUS_USER_FONT_IMMUTABLE = 26 Global Const $CAIRO_STATUS_USER_FONT_ERROR = 27 Global Const $CAIRO_STATUS_NEGATIVE_COUNT = 28 Global Const $CAIRO_STATUS_INVALID_CLUSTERS = 29 Global Const $CAIRO_STATUS_INVALID_SLANT = 30 Global Const $CAIRO_STATUS_INVALID_WEIGHT = 31 Global Const $CAIRO_STATUS_INVALID_SIZE = 32 Global Const $CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED = 33 Global Const $CAIRO_STATUS_DEVICE_TYPE_MISMATCH = 34 Global Const $CAIRO_STATUS_DEVICE_ERROR = 35 Global Const $CAIRO_STATUS_INVALID_MESH_CONSTRUCTION = 36 Global Const $CAIRO_STATUS_DEVICE_FINISHED = 37 Global Const $CAIRO_STATUS_LAST_STATUS = 38 ; typedef enum _cairo_format Global Const $CAIRO_FORMAT_INVALID = -1 Global Const $CAIRO_FORMAT_ARGB32 = 0 Global Const $CAIRO_FORMAT_RGB24 = 1 Global Const $CAIRO_FORMAT_A8 = 2 Global Const $CAIRO_FORMAT_A1 = 3 Global Const $CAIRO_FORMAT_RGB16_565 = 4 Global Const $CAIRO_FORMAT_RGB30 = 5 ; Check libraries. $aList = _FileListToArray ( @ScriptDir, '*.dll', 1, 0 ) For $i = 1 To UBound ( $aList ) -1 If _GetBinaryType ( @ScriptDir & '\' & $aList[$i] ) <> 'i386' Then Exit MsgBox ( 262144+16, 'Error', $aList[$i] & ' is not 32bit !', 5 ) ;~ ConsoleWrite ( $aList[$i] & @TAB & 'Version ' & FileGetVersion ( $aList[$i] ) & @Crlf ) Next #Region ------ Global Variables ------------------------------ FileChangeDir ( @ScriptDir & '\Libraries' ) Global $h_RsvgDll = DllOpen ( @ScriptDir & '\Libraries\librsvg-2-2.dll' ) Global $h_CairoDll = DllOpen ( @ScriptDir & '\Libraries\libcairo-2.dll' ) Global $sPngFilePath = @DesktopDir & '\' & @HOUR & @MIN & @SEC & @MSEC & '.png' Global $sSvgFilePath, $hRsvg, $pCairoSurface, $pCr #EndRegion --- Global Variables ------------------------------ FileChangeDir ( @ScriptDir & '\SVG files' ) $sSvgFilePath = FileOpenDialog ( 'Select a Shape', @WorkingDir, 'Vector Graphic (*.svg)', 1+2, '' ) If @error Then Exit ; Open the SVG image file $hRsvg = _Rsvg_handle_new_from_file ( $sSvgFilePath ) ConsoleWrite ( '!->-- [' & StringFormat ( '%03i', @ScriptLineNumber ) & '] $hRsvg : ' & $hRsvg & @Crlf ) ; Get dimensions $aSize = _Rsvg_handle_get_dimensions ( $hRsvg ) If Not @error Then ConsoleWrite ( '> Width : ' & $aSize[0] & ', Height : ' & $aSize[1] & @Crlf ) ; Create a Surface into which we render the SVG drawing $pCairoSurface = _Cairo_image_surface_create ( $CAIRO_FORMAT_ARGB32, $aSize[0], $aSize[1] ) ConsoleWrite ( '!->-- [' & StringFormat ( '%03i', @ScriptLineNumber ) & '] $pCairoSurface : ' & $pCairoSurface & @Crlf ) ; Create a new Cairo renderer $pCr = _Cairo_create ( $pCairoSurface ) ConsoleWrite ( '!->-- [' & StringFormat ( '%03i', @ScriptLineNumber ) & '] $pCr : ' & $pCr & @Crlf ) ConsoleWrite ( 'Cairo status after _Cairo_create : ' & _Cairo_status ( $pCr ) & @Crlf ) ; Render the SVG into the Cairo buffer _Rsvg_handle_render_cairo ( $hRsvg, $pCr ) ConsoleWrite ( 'Cairo status after _Rsvg_handle_render_cairo : ' & _Cairo_status ( $pCr ) & @Crlf ) ; Save to png _Cairo_surface_write_to_png ( $pCairoSurface, $sPngFilePath ) ConsoleWrite ( 'Cairo status after _Cairo_surface_write_to_png : ' & _Cairo_status ( $pCr ) & @Crlf ) _Cairo_surface_finish ( $pCairoSurface ) ConsoleWrite ( 'Cairo status after _Cairo_surface_finish : ' & _Cairo_status ( $pCr ) & @Crlf ) _Rsvg_handle_close ( $hRsvg ) ConsoleWrite ( 'Cairo status after _Rsvg_handle_close : ' & _Cairo_status ( $pCr ) & @Crlf ) ; Display _BitmapDisplayInWindowsViewer ( $sPngFilePath ) ; Cleanup _Cairo_destroy ( $pCr ) _Cairo_surface_destroy ( $pCairoSurface ) DllClose ( $h_RsvgDll ) DllClose ( $h_CairoDll ) Exit Func _BitmapDisplayInWindowsViewer ( $sFilePath ) If Not FileExists ( $sFilePath ) Then Return SetError ( -1 ) Run ( 'rundll32 shimgvw.dll,ImageView_Fullscreen ' & $sFilePath ) EndFunc ;==> _BitmapDisplayInWindowsViewer() Func _Cairo_create ( $pCairoSurface ) Local $aRet = DllCall ( $h_CairoDll, 'ptr:cdecl', 'cairo_create', 'ptr', $pCairoSurface ) If @error Then Return SetError ( @error, 0, 0 ) Return $aRet[0] EndFunc ;==> _Cairo_create() Func _Cairo_destroy ( $pCr ) Local $aRet = DllCall ( $h_CairoDll, 'int:cdecl', 'cairo_destroy', 'ptr', $pCr ) If @error Then Return SetError ( @error, 0, 0 ) Return $aRet[0] EndFunc ;==> _Cairo_destroy() Func _Cairo_image_surface_create ( $iFormat, $iWidth, $iHeight ) Local $aRet = DllCall ( $h_CairoDll, 'ptr:cdecl', 'cairo_image_surface_create', 'int', $iFormat, 'int', $iWidth, 'int', $iHeight ) If @error Then Return SetError ( @error, 0, 0 ) Return $aRet[0] EndFunc ;==> _Cairo_image_surface_create() Func _Cairo_image_surface_create_for_data ( $iFormat, $iWidth, $iHeight, $iStride ) Local $tStruct = DllStructCreate ( 'byte[' & $iStride*$iHeight & ']' ) Local $aRet = DllCall ( $h_CairoDll, 'ptr:cdecl', 'cairo_image_surface_create_for_data', 'ptr', DllStructGetPtr ( $tStruct ), 'int', $iFormat, 'int', $iWidth, 'int', $iHeight, 'int', $iStride ) If @error Then Return SetError ( @error, 0, 0 ) $tStruct = 0 Return $aRet[0] EndFunc ;==> _Cairo_image_surface_create_for_data() Func _Cairo_status ( $pCr ) Local $aRet = DllCall ( $h_CairoDll, 'int:cdecl', 'cairo_status', 'ptr', $pCr ) If @error Then Return SetError ( @error, 0, 0 ) Switch $aRet[0] Case $CAIRO_STATUS_SUCCESS Return 'SUCCESS' Case $CAIRO_STATUS_NO_MEMORY Return 'NO MEMORY' Case $CAIRO_STATUS_INVALID_RESTORE Return 'INVALID RESTORE' Case $CAIRO_STATUS_INVALID_POP_GROUP Return 'INVALID POP GROUP' Case $CAIRO_STATUS_NO_CURRENT_POINT Return 'NO CURRENT POINT' Case $CAIRO_STATUS_INVALID_MATRIX Return 'INVALID MATRIX' Case $CAIRO_STATUS_INVALID_STATUS Return 'INVALID STATUS' Case $CAIRO_STATUS_NULL_POINTER Return 'NULL POINTER' Case $CAIRO_STATUS_INVALID_STRING Return 'INVALID STRING' Case $CAIRO_STATUS_INVALID_PATH_DATA Return 'INVALID PATH DATA' Case $CAIRO_STATUS_READ_ERROR Return 'READ ERROR' Case $CAIRO_STATUS_WRITE_ERROR Return 'WRITE ERROR' Case $CAIRO_STATUS_SURFACE_FINISHED Return 'SURFACE FINISHED' Case $CAIRO_STATUS_SURFACE_TYPE_MISMATCH Return 'SURFACE TYPE MISMATCH' Case $CAIRO_STATUS_PATTERN_TYPE_MISMATCH Return 'PATTERN TYPE MISMATCH' Case $CAIRO_STATUS_INVALID_CONTENT Return 'INVALID CONTENT' Case $CAIRO_STATUS_INVALID_FORMAT Return 'INVALID FORMAT' Case $CAIRO_STATUS_INVALID_VISUAL Return 'INVALID VISUAL' Case $CAIRO_STATUS_FILE_NOT_FOUND Return 'FILE NOT FOUND' Case $CAIRO_STATUS_INVALID_DASH Return 'INVALID DASH' Case $CAIRO_STATUS_INVALID_DSC_COMMENT Return 'INVALID DSC COMMENT' Case $CAIRO_STATUS_INVALID_INDEX Return 'INVALID INDEX' Case $CAIRO_STATUS_CLIP_NOT_REPRESENTABLE Return 'CLIP NOT REPRESENTABLE' Case $CAIRO_STATUS_TEMP_FILE_ERROR Return 'TEMP FILE ERROR' Case $CAIRO_STATUS_INVALID_STRIDE Return 'INVALID STRIDE' Case $CAIRO_STATUS_FONT_TYPE_MISMATCH Return 'FONT TYPE MISMATCH' Case $CAIRO_STATUS_USER_FONT_IMMUTABLE Return 'USER FONT IMMUTABLE' Case $CAIRO_STATUS_USER_FONT_ERROR Return 'USER FONT ERROR' Case $CAIRO_STATUS_NEGATIVE_COUNT Return 'NEGATIVE COUNT' Case $CAIRO_STATUS_INVALID_CLUSTERS Return 'INVALID CLUSTERS' Case $CAIRO_STATUS_INVALID_SLANT Return 'INVALID SLANT' Case $CAIRO_STATUS_INVALID_WEIGHT Return 'INVALID WEIGHT' Case $CAIRO_STATUS_INVALID_SIZE Return 'INVALID SIZE' Case $CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED Return 'USER FONT NOT IMPLEMENTED' Case $CAIRO_STATUS_DEVICE_TYPE_MISMATCH Return 'DEVICE TYPE MISMATCH' Case $CAIRO_STATUS_DEVICE_ERROR Return 'DEVICE ERROR' Case $CAIRO_STATUS_INVALID_MESH_CONSTRUCTION Return 'INVALID MESH CONSTRUCTION' Case $CAIRO_STATUS_DEVICE_FINISHED Return 'DEVICE FINISHED' Case $CAIRO_STATUS_LAST_STATUS Return 'LAST STATUS' Case Else Return 'UNKNOW ERROR' EndSwitch EndFunc ;==> _Cairo_status() Func _Cairo_status_to_string() Local $aRet = DllCall ( $h_CairoDll, 'str:cdecl', 'cairo_status_to_string' ) If @error Then Return SetError ( @error, 0, 0 ) ;~ If $aRet[0] = '<unknown error status>' Then Return '' Return $aRet[0] EndFunc ;==> _Cairo_status_to_string() Func _Cairo_surface_destroy ( $pCairoSurface ) Local $aRet = DllCall ( $h_CairoDll, 'int:cdecl', 'cairo_surface_destroy', 'ptr', $pCairoSurface ) If @error Then Return SetError ( @error, 0, 0 ) Return $aRet[0] EndFunc ;==> _Cairo_surface_destroy() Func _Cairo_surface_finish ( $pCairoSurface ) Local $aRet = DllCall ( $h_CairoDll, 'int:cdecl', 'cairo_surface_finish', 'ptr', $pCairoSurface ) If @error Then Return SetError ( @error, 0, 0 ) Return $aRet[0] EndFunc ;==> _Cairo_surface_finish() Func _Cairo_surface_write_to_png ( $pCairoSurface, $sFilePath ) Local $aRet = DllCall ( $h_CairoDll, 'int:cdecl', 'cairo_surface_write_to_png', 'ptr', $pCairoSurface, 'str', $sFilePath ) If @error Then Return SetError ( @error, 0, 0 ) Return $aRet[0] EndFunc ;==> _Cairo_surface_write_to_png() Func _GetBinaryType ( $sFilePath ) ; by Dougiefresh Local $hFile = FileOpen ( $sFilePath, 16 ) If $hFile = -1 Then Return SetError ( -1, 0, 'Invalid' ) If BinaryToString ( FileRead ( $hFile, 2 ) ) = 'MZ' Then FileSetPos ( $hFile, 60, 0 ) FileSetPos ( $hFile, Int ( FileRead ( $hFile, 4 ) ) +4, 0 ) Local $sFileRead = FileRead ( $hFile, 2 ) FileClose ( $hFile ) If $sFileRead = '0x6486' Then Return 'AMD64' If $sFileRead = '0x4c01' Then Return 'i386' If $sFileRead = '0x0002' Then Return 'IA64' EndIf FileClose ( $hFile ) Return 'Unknown' EndFunc ;==> _GetBinaryType() Func _Rsvg_handle_close ( $hRsvg ) Local $iError = 0 Local $aRet = DllCall ( $h_RsvgDll, 'ptr:cdecl', 'rsvg_handle_close', 'ptr', $hRsvg, 'int', $iError ) If @error Then Return SetError ( @error, 0, 0 ) If $iError Then Return SetError ( $iError, 0, 0 ) Return $aRet[0] EndFunc ;==> _Rsvg_handle_close() Func _Rsvg_handle_get_dimensions ( $hRsvg ) Local $aSize[4], $tRsvgDimensionData = DllStructCreate ( 'int width;int height;double em;double ex' ) Local $aRet = DllCall ( $h_RsvgDll, 'int:cdecl', 'rsvg_handle_get_dimensions', 'ptr', $hRsvg, 'ptr', DllStructGetPtr ( $tRsvgDimensionData ) ) If @error Then Return SetError ( @error, 0, 0 ) $aSize[0] = $tRsvgDimensionData.width $aSize[1] = $tRsvgDimensionData.height $aSize[2] = $tRsvgDimensionData.em $aSize[3] = $tRsvgDimensionData.ex $tRsvgDimensionData = 0 Return $aSize EndFunc ;==> _Rsvg_handle_get_dimensions() Func _Rsvg_handle_new_from_file ( $sSvgFile ) If Not FileExists ( $sSvgFile ) Then Return SetError ( -1, 0, 0 ) Local $iError = 0 Local $aRet = DllCall ( $h_RsvgDll, 'ptr:cdecl', 'rsvg_handle_new_from_file', 'str', FileGetShortName ( $sSvgFile ), 'int', $iError ) If @error Then Return SetError ( @error, 0, 0 ) If $iError Then Return SetError ( $iError, 0, 0 ) Return $aRet[0] EndFunc ;==> _Rsvg_handle_new_from_file() Func _Rsvg_handle_render_cairo ( $hRsvg, $pCr ) Local $aRet = DllCall ( $h_RsvgDll, 'bool:cdecl', 'rsvg_handle_render_cairo', 'ptr', $hRsvg, 'ptr', $pCr ) If @error Then Return SetError ( @error, 0, 0 ) Return $aRet[0] ; Returns TRUE if drawing succeeded. EndFunc ;==> _Rsvg_handle_render_cairo() Func _Rsvg_init() ; deprecated since version 2.36 and should not be used in newly-written code. Local $aRet = DllCall ( $h_RsvgDll, 'int:cdecl', 'rsvg_init' ) If @error Then Return SetError ( @error, 0, 0 ) Return $aRet[0] EndFunc ;==> _Rsvg_init() Script and files are available in the downloads Section
       
    • wakillon
      By wakillon
      Convert SVG file to PNG using Cairo and rsvg libraries
×