Jump to content

Rendering PNG or line on Alpha GUI - stuck!


Threap
 Share

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:

_GDIPlus_Startup()   
$GUI = _GUICreate_Alpha("TBT", @ScriptDir & "\sample.png")
$hWnd = WinGetHandle("TBT")
$hDC  = _WinAPI_GetWindowDC($hWnd)
GUISetState(@SW_SHOW)
;...
$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!

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

Picea

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

Opt("GUIOnEventMode",1)

_GDIPlus_Startup()
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))
        GUISetState(@SW_SHOWNOACTIVATE, $GUI)
global $xco=150,$yco=0
$object=_Imagechange(150,150,150,0)
SetBitmap($GUI, $object, 255)
;guistart()
$donx=+2
$dony=+2
While 1
sleep(10)
    _WinAPI_DeleteObject($object)
    if $xco=250 and $donx=+2 then
        $donx=-2
    Elseif $xco<50 and $donx=-2 then
        $donx=+2
    EndIf
    if $yco=250 and $dony=+2 then
        $dony=-2
    Elseif $yco<50 and $dony=-2 then
        $dony=+2
    EndIf
$xco=$xco+$donx
$yco=$yco+$dony
    $object=_Imagechange(150,150,$xco,$yco)
SetBitmap($GUI, $object, 255)
_ReduceMemory()
WEnd
func onautoitexit()
_WinAPI_DeleteObject($object)    
_GDIPlus_Shutdown()
EndFunc

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])
    Else
        Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
    EndIf
    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)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteDC($hMemDC)
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)
   ;Draw
    _GDIPlus_GraphicsDrawImageRect($newGC, $oldImage, 0, 0, $iW, $iH)
        $hPen = _GDIPlus_PenCreate (0xFF222222,3)
    _GDIPlus_GraphicsDrawLine ($newGC, $startx,$starty,$endx, $endy, $hPen)
   ;Cleanup
   ;_GDIPlus_BitmapDispose($newBmp)
       _GDIPlus_PenDispose ($hPen)
    _GDIPlus_GraphicsDispose($GC)
    _GDIPlus_GraphicsDispose($newGC)

    Return $newBmp
EndFunc  ;==>_ImageResize

post-45064-12550350643764_thumb.png

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...