Jump to content

My GDI+ tests


Recommended Posts

Hi forum. i´m playing with GDI+ and i found a couple of issues that i can`t figure out how to solve, maybe you can give me a help

I Attempt to do a kind of splash on the screen of some shapes with transparency... if i use a GUI whit layered style and the _WinAPI_SetLayeredWindowAttributes() function the shapes are NOT transparent and look opaques so i use the desktop to dysplay the shapes...

My first problem it happend when some Window pass over the draw.. then the shapes dissapear and i can`t find a way to keep the draw always visible.

The second thing is when i terminate the script, i can`t erase the draw from the desktop automaticly(sorry my bad english)

I leave the script to you to see it

#include <GDIplus.au3>
#include <winapi.au3>
#include <WindowsConstants.au3>
HotKeySet("{ESC}","_Exit")
$DeskHndl = _WinAPI_GetDesktopWindow()
GUIRegisterMsg($WM_PAINT, "_WM_PAINT") ;this doesnt work
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($DeskHndl)
$hBrush = _GDIPlus_BrushCreateSolid(0x66ff0000)
_GDIPlus_GraphicsFillPie($hGraphic, 100, 80, 100, 100, 45, 90, $hBrush)
_GDIPlus_GraphicsFillPie($hGraphic, 150, 80, 100, 100, 45, 90, $hBrush)
_GDIPlus_GraphicsFillPie($hGraphic, 200, 80, 100, 100, 45, 90, $hBrush)
_GDIPlus_GraphicsFillPie($hGraphic, 125, 55, 100, 100, 45, 90, $hBrush)
_GDIPlus_GraphicsFillPie($hGraphic, 175, 55, 100, 100, 45, 90, $hBrush)
_GDIPlus_GraphicsFillPie($hGraphic, 150, 30, 100, 100, 45, 90, $hBrush)
While True
    Sleep(10)
WEnd
Func _WM_PAINT($hWnd, $Msg)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Msg = ' & $Msg & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
    ; The console debug is for testing propouses to check if the message have been trigger
    DllStructSetData($tagRECT,1,0)
    DllStructSetData($tagRECT,2,0)
    DllStructSetData($tagRECT,3,300)
    DllStructSetData($tagRECT,4,300)
    _WinAPI_RedrawWindow($DeskHndl,$tagRECT) ; i dont think this will be the way for doing this
EndFunc   ;==>_WM_PAINT
Func _Exit()
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    _WinAPI_RedrawWindow($DeskHndl,$tagRECT)
    Exit
EndFunc   ;==>_Exit
Link to comment
Share on other sites

Try this:

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

Global Const $SC_DRAGMOVE = 0xF012
_GDIPlus_Startup()
Global Const $iWidth = 300
Global Const $iHeight = 180

;create bitmap and draw filled pie to bitmap
Global $hImage = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
$hImage = $hImage[6]
Global Const $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
Global Const $hBrush = _GDIPlus_BrushCreateSolid(0x66ff0000)
_GDIPlus_GraphicsFillPie($hGraphic, 100, 80, 100, 100, 45, 90, $hBrush)
_GDIPlus_GraphicsFillPie($hGraphic, 150, 80, 100, 100, 45, 90, $hBrush)
_GDIPlus_GraphicsFillPie($hGraphic, 200, 80, 100, 100, 45, 90, $hBrush)
_GDIPlus_GraphicsFillPie($hGraphic, 125, 55, 100, 100, 45, 90, $hBrush)
_GDIPlus_GraphicsFillPie($hGraphic, 175, 55, 100, 100, 45, 90, $hBrush)
_GDIPlus_GraphicsFillPie($hGraphic, 150, 30, 100, 100, 45, 90, $hBrush)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_BrushDispose($hBrush)

;create GUI and child GUI
Global Const $hGUI = GUICreate("GDI+ Example by UEZ 2011", $iWidth, $iHeight, -1, -1, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOPMOST)
Global Const $hGUI_child = GUICreate("", $iWidth, $iHeight, 0, 0, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOPMOST + $WS_EX_MDICHILD, $hGUI)
GUISetBkColor(0xFFFFFF, $hGUI_child)
GUISetState(@SW_SHOW, $hGUI)
GUISetState(@SW_SHOW, $hGUI_child)

;make child GUI transparent and set bitmap to parent GUI
_WinAPI_SetLayeredWindowAttributes($hGUI_child, 0xFFFFFF, 0xFF)
SetTransparentBitmap($hGUI, $hImage)

;enabler windows moving
GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            GUIRegisterMsg($WM_LBUTTONDOWN, "")
            _GDIPlus_BitmapDispose($hImage)
            _GDIPlus_Shutdown()
            GUIDelete($hGUI)
            ExitLoop
    EndSwitch
WEnd

Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
EndFunc   ;==>_WM_LBUTTONDOWN

Func SetTransparentBitmap($hGUI, $hImage, $iOpacity = 0xFF)
    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", 1)
    _WinAPI_UpdateLayeredWindow($hGUI,  $hMemDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteDC($hMemDC)
EndFunc   ;==>SetTransparentBitmap

Br,

UEZ

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

Link to comment
Share on other sites

that works.. but my idea was learn from the process but this way i dont get it... ¿did you know where i can find some online GDI+ Guide from basics, that explain me the logic of how it work and his functions?

EDIT: I`ve reading MSDN about GetLastStatus ¿how can i call this method in autoit?

I try it on your script to add this and it doesnt work if i getlasterror i retrieve error 127 = ERROR_PROC_NOT_FOUND = The specified procedure could not be found.

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

Global Const $SC_DRAGMOVE = 0xF012
_GDIPlus_Startup()
Global Const $iWidth = 300
Global Const $iHeight = 180

;create bitmap and draw filled pie to bitmap
Global $hImage = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
$hImage = $hImage[6]
Global Const $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
Global Const $hBrush = _GDIPlus_BrushCreateSolid(0x66ff0000)
_GDIPlus_GraphicsFillPie($hGraphic, 100, 80, 100, 100, 45, 90, $hBrush)
_GDIPlus_GraphicsFillPie($hGraphic, 150, 80, 100, 100, 45, 90, $hBrush)
_GDIPlus_GraphicsFillPie($hGraphic, 200, 80, 100, 100, 45, 90, $hBrush)
_GDIPlus_GraphicsFillPie($hGraphic, 125, 55, 100, 100, 45, 90, $hBrush)
_GDIPlus_GraphicsFillPie($hGraphic, 175, 55, 100, 100, 45, 90, $hBrush)
_GDIPlus_GraphicsFillPie($hGraphic, 150, 30, 100, 100, 45, 90, $hBrush)
consolewrite(_GDIPlus_GetLastStatus())
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : _GDIPlus_GetLastStatus() = ' & _GDIPlus_GetLastStatus() & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_BrushDispose($hBrush)

;create GUI and child GUI
Global Const $hGUI = GUICreate("GDI+ Example by UEZ 2011", $iWidth, $iHeight, -1, -1, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOPMOST)
Global Const $hGUI_child = GUICreate("", $iWidth, $iHeight, 0, 0, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOPMOST + $WS_EX_MDICHILD, $hGUI)
GUISetBkColor(0xFFFFFF, $hGUI_child)
GUISetState(@SW_SHOW, $hGUI)
GUISetState(@SW_SHOW, $hGUI_child)

;make child GUI transparent and set bitmap to parent GUI
_WinAPI_SetLayeredWindowAttributes($hGUI_child, 0xFFFFFF, 0xFF)
SetTransparentBitmap($hGUI, $hImage)

;enabler windows moving
GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            GUIRegisterMsg($WM_LBUTTONDOWN, "")
            _GDIPlus_BitmapDispose($hImage)
            _GDIPlus_Shutdown()
            GUIDelete($hGUI)
            ExitLoop
    EndSwitch
WEnd

Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
EndFunc   ;==>_WM_LBUTTONDOWN

Func SetTransparentBitmap($hGUI, $hImage, $iOpacity = 0xFF)
    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", 1)
    _WinAPI_UpdateLayeredWindow($hGUI,  $hMemDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteDC($hMemDC)
EndFunc   ;==>SetTransparentBitmap
Func _GDIPlus_GetLastStatus()
    local $ret = Dllcall("Gdiplus.dll","int","GetLastStatus")
    If @error Then
        seterror( _winapi_getlasterror())
        return ""
    Else
        return $ret
    EndIf
EndFunc
Edited by monoscout999
Link to comment
Share on other sites

I did not learn GDI+ from any tutorial, I learned it studying the examples posted here in this forum.

There some German GDI+ tutorials tutorials autoit.de but neither in English nor Spanish.

Br,

UEZ

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

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