Jump to content

Recommended Posts

Posted (edited)

How would I go about getting a Transparent background for this _GDIPlus_GraphicsDrawStringEx ?, Ive already tried multiple UDF's that would work properly with the standard controls.

 

#include <GDIPlus.au3>

Opt("GUIOnEventMode", 1)

$hwnd = GUICreate("GDI+ Example", 400, 300)
$label = GUICtrlCreateLabel("", 10, 10, 380, 40)
GUICtrlCreateButton("Start/Stop scrolling",150,50,100,30)
GUICtrlSetOnEvent(-1,"startstop")
GUISetOnEvent(-3, "close")
GUICtrlCreatePic(@ScriptDir & '\Img\Main2.jpg' ,0 ,0 ,0 ,0 ,0 ,0 )
GUISetState()

_GDIPlus_Startup()
$graphics = _GDIPlus_GraphicsCreateFromHWND(ControlGetHandle($hwnd, "", $label))
$bitmap = _GDIPlus_BitmapCreateFromGraphics(380, 40, $graphics)
$backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)

$ffamily = _GDIPlus_FontFamilyCreate("Arial")
$arial = _GDIPlus_FontCreate($ffamily, 24)

$sformat = _GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetAlign($sformat, 1)
$blackbrush = _GDIPlus_BrushCreateSolid()

$pos = 0
$speed=0


Do
    _GDIPlus_GraphicsClear($backbuffer, 0xFFF0F0F0)

    $pos -= $speed
    $rectf = _GDIPlus_RectFCreate($pos, 0, 380, 40)
    If $pos < -300 Then $pos = 300


    _GDIPlus_GraphicsDrawStringEx($backbuffer, "Scrolling text", $arial, $rectf, $sformat, $blackbrush)

    _GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, 380, 40)
    Sleep(10)
Until False

Func startstop()
    $speed=Not $speed
EndFunc



Func close()
    _GDIPlus_BrushDispose($blackbrush)
    _GDIPlus_StringFormatDispose($sformat)
    _GDIPlus_FontDispose($arial)
    _GDIPlus_FontFamilyDispose($ffamily)
    _GDIPlus_GraphicsDispose($backbuffer)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_GraphicsDispose($graphics)
    _GDIPlus_Shutdown()
    Exit
EndFunc  ;==>close

 

Edited by CodeTinkerer
Posted

Instead of creating a background pic control create a bitmap with that image and copy it everytime to $backbuffer instead of using _GDIPlus_GraphicsClear($backbuffer, 0xFFF0F0F0).

Otherwise it is directly not possible to move a transparent image over another.

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted

Thank you UEZ. So Using _GDIPlus_BitmapCreateFromFile, How would I as you had said "copy" it to the $backbuffer? looking through the help I couldnt find a "copy" func per say

Posted

Then try this:

#include <GDIPlus.au3>

Opt("GUIOnEventMode", 1)

$hwnd = GUICreate("GDI+ Example", 400, 300)
$label = GUICtrlCreateLabel("", 10, 10, 380, 40)
GUICtrlCreateButton("Start/Stop scrolling",150,50,100,30)
GUICtrlSetOnEvent(-1,"startstop")
GUISetOnEvent(-3, "close")
;~ GUICtrlCreatePic(@ScriptDir & '\Test.jpg' , 0, 0, 400, 300)
GUISetState()

_GDIPlus_Startup()
$graphics = _GDIPlus_GraphicsCreateFromHWND(ControlGetHandle($hwnd, "", $label))
$bitmap = _GDIPlus_BitmapCreateFromGraphics(380, 40, $graphics)
$backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
$background = _GDIPlus_BitmapCreateFromFile(@ScriptDir & '\Test.jpg')
$ffamily = _GDIPlus_FontFamilyCreate("Arial")
$arial = _GDIPlus_FontCreate($ffamily, 24)

$sformat = _GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetAlign($sformat, 1)
$blackbrush = _GDIPlus_BrushCreateSolid()

$pos = 0
$speed=0


Do
    _GDIPlus_GraphicsDrawImageRect($backbuffer, $background, 0, 0, 400, 300)

    $pos -= $speed
    $rectf = _GDIPlus_RectFCreate($pos, 0, 380, 40)
    If $pos < -300 Then $pos = 300


    _GDIPlus_GraphicsDrawStringEx($backbuffer, "Scrolling text", $arial, $rectf, $sformat, $blackbrush)

    _GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, 380, 40)
    Sleep(10)
Until False

Func startstop()
    $speed=Not $speed
EndFunc



Func close()
    _GDIPlus_BrushDispose($blackbrush)
    _GDIPlus_StringFormatDispose($sformat)
    _GDIPlus_FontDispose($arial)
    _GDIPlus_FontFamilyDispose($ffamily)
    _GDIPlus_GraphicsDispose($backbuffer)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_BitmapDispose($background)
    _GDIPlus_GraphicsDispose($graphics)
    _GDIPlus_Shutdown()
    Exit
EndFunc  ;==>close

 

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted

This method is nice to know of.

I added a GraphicsClear statement to keep the text from smearing into black on black.

But is that the proper solution?  It seems to add a slight hesitation.

 

GraphicsClear.thumb.png.d46536af84518ea5

Posted

_GDIPlus_GraphicsClear() erases the graphic context with the color you provide or by default with 0xFF000000 (black). So for moving objects you have to clear the graphic context otherwise smearing will appear.

For alpha tranparency it might be a little bit more complicated depending on what you want to achieve.

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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
  • Recently Browsing   0 members

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