Jump to content



Photo

_GDIPlus_GraphicsDrawRoundRect


  • Please log in to reply
5 replies to this topic

#1 WideBoyDixon

WideBoyDixon

    Code Monkey

  • Active Members
  • PipPipPipPipPipPip
  • 381 posts

Posted 25 June 2009 - 02:31 PM

I was toying around with owner-drawn buttons and I wanted a GDI+ function to draw a rectangle with rounded corners. Once I got over the shock of realising that one didn't exist, I wrote my own.

[codebox]
Plain Text         
#include <GDIPlus.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> _GDIPlus_Startup() Global $hWndMain = GUICreate("Rounded Rectangles", 400, 400) GUISetState() Global $hDC = _WinAPI_GetDC($hWndMain) Global $hGraphics = _GDIPlus_GraphicsCreateFromHDC($hDC) Global $hBrush = _GDIPlus_BrushCreateSolid(0xffffc080) _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 4) GUIRegisterMsg($WM_PAINT, "_OnPaint") _OnPaint($hwndMain, 0, 0, 0) While GUIGetMsg() <> -3     Sleep(10) WEnd _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphics) _WinAPI_ReleaseDC($hWndMain, $hDC) _GDIPlus_Shutdown() Func _OnPaint($hWnd, $nMsg, $wParam, $lParam)     If $hWnd = $hWndMain Then         _GDIPlus_GraphicsClear($hGraphics, 0xffffffff)         _GDIPlus_GraphicsDrawRoundRect($hGraphics, 8, 8, 384, 100, 16, $hBrush)         _GDIPlus_GraphicsDrawRoundRect($hGraphics, 8, 116, 384, 80, 20)         _GDIPlus_GraphicsDrawRoundRect($hGraphics, 8, 204, 188, 188, 20, $hBrush)         _GDIPlus_GraphicsDrawRoundRect($hGraphics, 204, 204, 188, 188, 60)     EndIf EndFunc Func _GDIPlus_GraphicsDrawRoundRect($hGraphics, $iX, $iY, $iWidth, $iHeight, $iRadius, $hBrush = 0, $hPen = 0)     _GDIPlus_PenDefCreate($hPen)     Local $hPath = _GDIPlus_GraphicsPathCreate()     _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iRadius, $iY, $iX + $iWidth - ($iRadius * 2), $iY)     _GDIPlus_GraphicsPathAddArc($hPath, $iX + $iWidth - ($iRadius * 2), $iY, $iRadius * 2, $iRadius * 2, 270, 90)     _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth, $iY + $iRadius, $iX + $iWidth, $iY + $iHeight - ($iRadius * 2))     _GDIPlus_GraphicsPathAddArc($hPath, $iX + $iWidth - ($iRadius * 2), $iY + $iHeight - ($iRadius * 2), $iRadius * 2, $iRadius * 2, 0, 90)     _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth - ($iRadius * 2), $iY + $iHeight, $iX + $iRadius, $iY + $iHeight)     _GDIPlus_GraphicsPathAddArc($hPath, $iX, $iY + $iHeight - ($iRadius * 2), $iRadius * 2, $iRadius * 2, 90, 90)     _GDIPlus_GraphicsPathAddLine($hPath, $iX, $iY + $iHeight - ($iRadius * 2), $iX, $iY + $iRadius)     _GDIPlus_GraphicsPathAddArc($hPath, $iX, $iY, $iRadius * 2, $iRadius * 2, 180, 90)     _GDIPlus_GraphicsPathCloseFigure($hPath)     If $hBrush <> 0 Then _GDIPlus_GraphicsFillPath($hGraphics, $hBrush, $hPath)     _GDIPlus_GraphicsDrawPath($hGraphics, $hPen, $hPath)     _GDIPlus_GraphicsPathDispose($hPath)     _GDIPlus_PenDefDispose() EndFunc Func _GDIPlus_GraphicsPathCreate($iFillMode = 0)     Local $aResult = DllCall($ghGDIPDll, "int", "GdipCreatePath", "int", $iFillMode, "int*", 0);     If @error Then Return SetError(@error, @extended, 0)     Return SetError($aResult[0], 0, $aResult[2]) EndFunc Func _GDIPlus_GraphicsPathAddLine($hGraphicsPath, $iX1, $iY1, $iX2, $iY2)     Local $aResult = DllCall($ghGDIPDll, "int", "GdipAddPathLine", "hwnd", $hGraphicsPath, "float", $iX1, "float", $iY1, _                                 "float", $iX2, "float", $iY2)     If @error Then Return SetError(@error, @extended, 0)     Return SetError($aResult[0], 0, 0) EndFunc Func _GDIPlus_GraphicsPathAddArc($hGraphicsPath, $iX, $iY, $iWidth, $iHeight, $iStartAngle, $iSweepAngle)     Local $aResult = DllCall($ghGDIPDll, "int", "GdipAddPathArc", "hwnd", $hGraphicsPath, "float", $iX, "float", $iY, _                                 "float", $iWidth, "float", $iHeight, "float", $iStartAngle, "float", $iSweepAngle)     If @error Then Return SetError(@error, @extended, 0)     Return SetError($aResult[0], 0, 0) EndFunc Func _GDIPlus_GraphicsPathCloseFigure($hGraphicsPath)     Local $aResult = DllCall($ghGDIPDll, "int", "GdipClosePathFigure", "hwnd", $hGraphicsPath)     If @error Then Return SetError(@error, @extended, 0)     Return SetError($aResult[0], 0, 0) EndFunc Func _GDIPlus_GraphicsPathDispose($hGraphicsPath)     Local $aResult = DllCall($ghGDIPDll, "int", "GdipDeletePath", "hwnd", $hGraphicsPath)     If @error Then Return SetError(@error, @extended, 0)     Return SetError($aResult[0], 0, 0) EndFunc Func _GDIPlus_GraphicsDrawPath($hGraphics, $hPen, $hGraphicsPath)     Local $aResult = DllCall($ghGDIPDll, "int", "GdipDrawPath", "hwnd", $hGraphics, "hwnd", $hPen, "hwnd", $hGraphicsPath)     If @error Then Return SetError(@error, @extended, 0)     Return SetError($aResult[0], 0, 0) EndFunc Func _GDIPlus_GraphicsFillPath($hGraphics, $hBrush, $hGraphicsPath)     Local $aResult = DllCall($ghGDIPDll, "int", "GdipFillPath", "hwnd", $hGraphics, "hwnd", $hBrush, "hwnd", $hGraphicsPath)     If @error Then Return SetError(@error, @extended, 0)     Return SetError($aResult[0], 0, 0) EndFunc



Enjoy.

WBD





#2 UEZ

UEZ

    Never say never

  • MVPs
  • 3,593 posts

Posted 25 June 2009 - 03:18 PM

Coool WBD, you making me crazy :D

I see that you have a lot of time... Great work again! Keep it up!


Thanks for sharing!!!


UEZ

Edited by UEZ, 25 June 2009 - 06:05 PM.

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯


#3 cramaboule

cramaboule

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 273 posts

Posted 05 June 2010 - 12:55 PM

Hello,

I got an error:
D:\Software\au3\testfromtheforum\gui-round rect.au3(39,32) : ERROR: _GDIPlus_PenDefCreate(): undefined function.     _GDIPlus_PenDefCreate($hPen) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ D:\Software\au3\testfromtheforum\gui-round rect.au3(53,28) : ERROR: _GDIPlus_PenDefDispose(): undefined function.     _GDIPlus_PenDefDispose() ~~~~~~~~~~~~~~~~~~~~~~~~~~~^ D:\Software\au3\testfromtheforum\gui-round rect.au3 - 2 error(s), 0 warning(s)

I use AutoIt v3.3.6.1

Thanks
Cramaboule

#4 picea892

picea892

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 689 posts

Posted 05 June 2010 - 01:04 PM

Here is the updated function

Func _GDIPlus_GraphicsDrawRoundRect($hGraphics, $iX, $iY, $iWidth, $iHeight, $iRadius, $hBrush = 0, $hPen = 0)     _GDIPlus_PenCreate($hPen)     Local $hPath = _GDIPlus_GraphicsPathCreate()     _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iRadius, $iY, $iX + $iWidth - ($iRadius * 2), $iY)     _GDIPlus_GraphicsPathAddArc($hPath, $iX + $iWidth - ($iRadius * 2), $iY, $iRadius * 2, $iRadius * 2, 270, 90)     _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth, $iY + $iRadius, $iX + $iWidth, $iY + $iHeight - ($iRadius * 2))     _GDIPlus_GraphicsPathAddArc($hPath, $iX + $iWidth - ($iRadius * 2), $iY + $iHeight - ($iRadius * 2), $iRadius * 2, $iRadius * 2, 0, 90)     _GDIPlus_GraphicsPathAddLine($hPath, $iX + $iWidth - ($iRadius * 2), $iY + $iHeight, $iX + $iRadius, $iY + $iHeight)     _GDIPlus_GraphicsPathAddArc($hPath, $iX, $iY + $iHeight - ($iRadius * 2), $iRadius * 2, $iRadius * 2, 90, 90)     _GDIPlus_GraphicsPathAddLine($hPath, $iX, $iY + $iHeight - ($iRadius * 2), $iX, $iY + $iRadius)     _GDIPlus_GraphicsPathAddArc($hPath, $iX, $iY, $iRadius * 2, $iRadius * 2, 180, 90)     _GDIPlus_GraphicsPathCloseFigure($hPath)     If $hBrush <> 0 Then _GDIPlus_GraphicsFillPath($hGraphics, $hBrush, $hPath)     _GDIPlus_GraphicsDrawPath($hGraphics, $hPen, $hPath)     _GDIPlus_GraphicsPathDispose($hPath)     _GDIPlus_PenDispose($hPen) EndFunc


#5 Yoriz

Yoriz

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 356 posts

Posted 05 June 2010 - 01:11 PM

Me too, just change these
;~     _GDIPlus_PenDefCreate($hPen)     $hPen = _GDIPlus_PenCreate()

;~     _GDIPlus_PenDefDispose()     _GDIPlus_PenDispose($hPen)

GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.

#6 cramaboule

cramaboule

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 273 posts

Posted 12 June 2010 - 11:50 AM

Thanks,
But it doen't work on Windows XP,
It is working fine on W7.

Cramaboule




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users