Jump to content
Sign in to follow this  

Rendering PNG or line on Alpha GUI - stuck!

Recommended Posts


Hi, esteemed AutoIt experts,

I have trawled extensively through the forums & not seen an answer to this problem - if this is a well-known issue then please, call me stupid & point me in the right direction!

I have a program that uses _GUICreate_Alpha (thanks, Kip & others!) to create an alpha-blended GUI based on a part-transparent PNG. On top of that, I am trying to render & rotate another PNG - although for what I am trying to achieve, a "speedometer" effect, I'd settle for just being able to draw a simple line, provided I can reposition the line at run-time.

Here's the relevant bit of what I am currently using:

$GUI = _GUICreate_Alpha("TBT", @ScriptDir & "\sample.png")
$hWnd = WinGetHandle("TBT")
$hDC  = _WinAPI_GetWindowDC($hWnd)
$graphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
$bitmap = _GDIPlus_BitmapCreateFromGraphics(300, 300, $graphics)
;...then code for matrix rotating & rendering another PNG...

Now, this doesn't work - my alpha-blended GUI gets rendered perfectly, but any _GDIPlus_ graphics operations I then perform don't appear.

If, however, I delete the _GUICreate_Alpha line and replace it with this:

$Form1 = GUICreate("TBT", 0, 0, 300, 300, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE))

..and then use $Form1 as the parameter for my GDIPlus_GraphicsCreateFromHWnd() statement, then all my lines, other PNGs etc, get rendered properly but, of course, my GUI looks like an ordinary window, not a beautifully-rendered alpha-blended PNG.

The _GUICreate_Alpha() function invokes GUICreate() - even if I pull the $hWnd value that is returned there, and use that as my GraphicsCreateFromHWND() parameter, it still doesn't work, which suggests to me that the problem is not an incorrect window handle, but instead something more fundamental.

What am I doing wrong? It must be very simple... right? Please let me know if I need to supply any more details.

Many thanks in advance for anything you can suggest!

Share this post

Link to post
Share on other sites

A speedometer looks a bit like a clock. There are many clocks on the forum so that would definately be a good place to start. Some of the clocks are very well developed though so be prepared.

[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post

Link to post
Share on other sites

I've been playing a lot with just drawing right on a png instead of using seperate graphics or guictrls.

I thought I would give your problem a try using that technique. Interesting experiment. May not be what you are looking for though.


#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#Include <Array.au3>


Global $iconname=@ScriptDir & "\test.png"
global $oldImage = _GDIPlus_ImageLoadFromFile($iconname)
Global $GUI
Global $iW = 300
Global $iH = 300
global $object,$background
    $GUI = GUICreate("test", $iW, $iH, -1, -1, $WS_POPUP,bitor($WS_EX_TOOLWINDOW,$WS_EX_LAYERED))
global $xco=150,$yco=0
SetBitmap($GUI, $object, 255)
While 1
    if $xco=250 and $donx=+2 then
    Elseif $xco<50 and $donx=-2 then
    if $yco=250 and $dony=+2 then
    Elseif $yco<50 and $dony=-2 then
SetBitmap($GUI, $object, 255)
func onautoitexit()

Func _ReduceMemory($i_PID = -1)
    If $i_PID <> -1 Then
        Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)
        Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
        DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
        Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
    Return $ai_Return[0]
EndFunc;==> _ReduceMemory()

Func SetBitmap($hGUI, $hImage, $iOpacity)
    ;set up layered window
    Local Const $AC_SRC_ALPHA = 1
    Local Const $ULW_ALPHA = 2
    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", _GDIPlus_ImageGetWidth($hImage))
    DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
    _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
EndFunc ;==>SetBitmap

Func _Imagechange($startx,$starty,$endx, $endy)
    ;resize the png
    Local $GC, $newBmp, $newGC
   ; Load Image

   ;Create New image
    $GC = _GDIPlus_ImageGetGraphicsContext($oldImage)
    $newBmp = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $GC)
    $newGC = _GDIPlus_ImageGetGraphicsContext($newBmp)
    _GDIPlus_GraphicsDrawImageRect($newGC, $oldImage, 0, 0, $iW, $iH)
        $hPen = _GDIPlus_PenCreate (0xFF222222,3)
    _GDIPlus_GraphicsDrawLine ($newGC, $startx,$starty,$endx, $endy, $hPen)
       _GDIPlus_PenDispose ($hPen)

    Return $newBmp
EndFunc  ;==>_ImageResize


Share this post

Link to post
Share on other sites

I demonstrated on another post how to move a png around on top of another.


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