Leaderboard
Popular Content
Showing content with the highest reputation on 01/12/2025 in all areas
-
Added this UDF to the wiki3 points
-
How to create rounded corners? (_GDIPlus)
argumentum and one other reacted to ioa747 for a topic
another approach for buttons with rounded corners https://www.autoitscript.com/forum/topic/211721-round-buttons/#findComment-15402632 points -
I like the AddArc. It is simpler to code than AddCurve. Here my take on your function : Func _GDIPlus_PathAddRoundRect(ByRef $hPath, $iX, $iY, $iWidth, $iHeight, $iRadius) _GDIPlus_PathAddArc($hPath, $iX, $iY, $iRadius, $iHeight, 90, 180) _GDIPlus_PathAddArc($hPath, $iX + $iWidth, $iY, $iRadius, $iHeight, -90, 180) _GDIPlus_PathCloseFigure($hPath) EndFunc Called this way : _GDIPlus_PathAddRoundRect($hPath, $tRect_Coords[0], $tRect_Coords[1], $tRect_Coords[2], $tRect_Coords[3], 60) Adding : _GDIPlus_GraphicsSetSmoothingMode($hGraphic, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ; antialiasing Make really nice rounded buttons...2 points
-
a little different #include <GUIConstantsEx.au3> #include <GDIPlus.au3> #include <WindowsConstants.au3> #include <WinAPIGdi.au3> Global $hGraphic, $hBrush, $hBrushFont, $hFont, $hFormat, $hFamily, $hGUI, $tRect_Coords[4] Global $iTheme = 0 Example() ;--------------------------------------------------------------------------------------- Func Example() ; Create GUI $hGUI = GUICreate("GDI+ Centered Text", 400, 300) ; Initialize GDI+ _GDIPlus_Startup() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) $hBrush = _GDIPlus_BrushCreateSolid(0xAA43A6DF) ; Blue $hBrushFont = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) ; White $hFormat = _GDIPlus_StringFormatCreate() _GDIPlus_StringFormatSetAlign($hFormat, 1) ; Horizontal alignment _GDIPlus_StringFormatSetLineAlign($hFormat, 1) ; Vertical alignment $hFamily = _GDIPlus_FontFamilyCreate("Segoe UI Light") $hFont = _GDIPlus_FontCreate($hFamily, 20, 2) ; Rectangle coordinates $tRect_Coords[0] = 50 $tRect_Coords[1] = 50 $tRect_Coords[2] = 200 $tRect_Coords[3] = 100 ; Register for painting GUIRegisterMsg($WM_PAINT, "WM_PAINT") GUISetState() ; Loop until the user exits Do Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $GUI_EVENT_PRIMARYDOWN If CheckPointer($tRect_Coords) Then SetTheme(1) Case $GUI_EVENT_PRIMARYUP SetTheme(0) Case $GUI_EVENT_MOUSEMOVE If GetTheme() = 1 Then ContinueLoop If CheckPointer($tRect_Coords) Then SetTheme(2) Else SetTheme(0) EndIf EndSwitch Until 0 ; Clean up resources _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_BrushDispose($hBrush) _GDIPlus_BrushDispose($hBrushFont) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() EndFunc ;==>Example ;--------------------------------------------------------------------------------------- Func WM_PAINT($hGUI, $iMsg, $wParam, $lParam) _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW) ; Clear the canvas _GDIPlus_GraphicsClear($hGraphic, 0xFFF0F0F0) ; Create a path for the rounded rectangle Local $hPath = _GDIPlus_PathCreate() _GDIPlus_PathAddRoundRect($hPath, $tRect_Coords[0], $tRect_Coords[1], $tRect_Coords[2], $tRect_Coords[3], 20) ; Fill the rounded rectangle _GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush) ; Optionally draw the outline Local $hPen = _GDIPlus_PenCreate(0xFF3685B2, 2) ; Darker Blue border _GDIPlus_GraphicsDrawPath($hGraphic, $hPath, $hPen) ; Draw the string centered in the rectangle _GDIPlus_GraphicsDrawStringEx($hGraphic, "Click Me", $hFont, _GDIPlus_RectFCreate($tRect_Coords[0], $tRect_Coords[1], $tRect_Coords[2], $tRect_Coords[3]), $hFormat, $hBrushFont) ; Clean up _GDIPlus_PenDispose($hPen) _GDIPlus_PathDispose($hPath) _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE) Return 0 EndFunc ;==>WM_PAINT ;--------------------------------------------------------------------------------------- Func CheckPointer(ByRef $aiCoords_ClientRel) Return _WinAPI_PtInRectEx(_WinAPI_GetMousePosX(True, $hGUI), _WinAPI_GetMousePosY(True, $hGUI), $aiCoords_ClientRel[0], $aiCoords_ClientRel[1], $aiCoords_ClientRel[0] + $aiCoords_ClientRel[2], $aiCoords_ClientRel[1] + $aiCoords_ClientRel[3]) EndFunc ;==>CheckPointer ;--------------------------------------------------------------------------------------- Func GetTheme() Return $iTheme EndFunc ;==>GetTheme ;--------------------------------------------------------------------------------------- Func SetTheme($Theme, $f_Redraw = True) If GetTheme() = $Theme Then Return 1 If $Theme = 0 Then ; Idle _GDIPlus_BrushSetSolidColor($hBrush, 0xAA43A6DF) ; Blue $tRect_Coords[0] = 50 $tRect_Coords[1] = 50 ElseIf $Theme = 1 Then ; MouseDown _GDIPlus_BrushSetSolidColor($hBrush, 0xFF3685B2) ; Darker Blue $tRect_Coords[0] = 52 $tRect_Coords[1] = 52 ; Move slightly down ElseIf $Theme = 2 Then ; MouseOver _GDIPlus_BrushSetSolidColor($hBrush, 0xBB7BC1E9) ; Lighter Blue $tRect_Coords[0] = 50 $tRect_Coords[1] = 50 Else Return SetError(1, 0, 0) EndIf $iTheme = $Theme If $f_Redraw Then _WinAPI_RedrawWindow($hGUI, 0, 0, BitOR($RDW_INTERNALPAINT, $RDW_ERASE)) EndFunc ;==>SetTheme ;--------------------------------------------------------------------------------------- Func _GDIPlus_PathAddRoundRect($hPath, $iX, $iY, $iWidth, $iHeight, $iRadius) Local $iDiameter = $iRadius * 2 _GDIPlus_PathAddArc($hPath, $iX, $iY, $iDiameter, $iDiameter, 180, 90) _GDIPlus_PathAddLine($hPath, $iX + $iRadius, $iY, $iX + $iWidth - $iRadius, $iY) _GDIPlus_PathAddArc($hPath, $iX + $iWidth - $iDiameter, $iY, $iDiameter, $iDiameter, 270, 90) _GDIPlus_PathAddLine($hPath, $iX + $iWidth, $iY + $iRadius, $iX + $iWidth, $iY + $iHeight - $iRadius) _GDIPlus_PathAddArc($hPath, $iX + $iWidth - $iDiameter, $iY + $iHeight - $iDiameter, $iDiameter, $iDiameter, 0, 90) _GDIPlus_PathAddLine($hPath, $iX + $iWidth - $iRadius, $iY + $iHeight, $iX + $iRadius, $iY + $iHeight) _GDIPlus_PathAddArc($hPath, $iX, $iY + $iHeight - $iDiameter, $iDiameter, $iDiameter, 90, 90) _GDIPlus_PathAddLine($hPath, $iX, $iY + $iHeight - $iRadius, $iX, $iY + $iRadius) EndFunc ;==>_GDIPlus_PathAddRoundRect ;---------------------------------------------------------------------------------------2 points
-
Here how you could draw a rounded button with GDI+ : #include <GDIPlus.au3> #include <GUIConstants.au3> Example() Func Example() Local $hGUI = GUICreate("GDI+", 500, 300) GUISetState(@SW_SHOW) _GDIPlus_Startup() Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) _GDIPlus_GraphicsSetSmoothingMode($hGraphic, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ; antialiasing _GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF) Local $hBrush = _GDIPlus_BrushCreateSolid(0x7F8800AA) Local $hPen = _GDIPlus_PenCreate(0xFF8800AA, 2) Local $hPen2 = _GDIPlus_PenCreate(0xFFFF0000, 2) Local $aPoints[4][2] = [[3]] Local $hPath = _GDIPlus_PathCreate() $aPoints[1][0] = 0 $aPoints[1][1] = 35 $aPoints[2][0] = 5 $aPoints[2][1] = 5 $aPoints[3][0] = 35 $aPoints[3][1] = 0 _GDIPlus_PathAddCurve($hPath, $aPoints) _GDIPlus_PathAddLine($hPath, 35, 0, 150, 0) $aPoints[1][0] = 150 $aPoints[1][1] = 0 $aPoints[2][0] = 180 $aPoints[2][1] = 5 $aPoints[3][0] = 185 $aPoints[3][1] = 35 _GDIPlus_PathAddCurve($hPath, $aPoints) $aPoints[1][0] = 185 $aPoints[1][1] = 35 $aPoints[2][0] = 180 $aPoints[2][1] = 65 $aPoints[3][0] = 150 $aPoints[3][1] = 70 _GDIPlus_PathAddCurve($hPath, $aPoints) _GDIPlus_PathAddLine($hPath, 150, 70, 35, 70) $aPoints[1][0] = 35 $aPoints[1][1] = 70 $aPoints[2][0] = 5 $aPoints[2][1] = 65 $aPoints[3][0] = 0 $aPoints[3][1] = 35 _GDIPlus_PathAddCurve($hPath, $aPoints) _GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush) _GDIPlus_GraphicsDrawPath($hGraphic, $hPath, $hPen) Local $hBrushFont = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) Local $hFormat = _GDIPlus_StringFormatCreate() Local $hFamily = _GDIPlus_FontFamilyCreate("Segoe UI Light") Local $hFont = _GDIPlus_FontCreate($hFamily, 18, 1) _GDIPlus_GraphicsDrawStringEx($hGraphic, "Hello world !", $hFont, _GDIPlus_RectFCreate(20, 20, 160, 40), $hFormat, $hBrushFont) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_BrushDispose($hBrushFont) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_PathDispose($hPath) _GDIPlus_BrushDispose($hBrush) _GDIPlus_PenDispose($hPen) _GDIPlus_PenDispose($hPen2) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() EndFunc ;==>Example I hardcoded everything since I am not sure if this is what you want.2 points
-
I modified one of my old script from 2014: ;Coded by UEZ #include <GUIConstantsEx.au3> #include <GDIPlus.au3> _GDIPlus_Startup() Global Const $STM_SETIMAGE = 0x0172 Global Const $hGUI = GUICreate("GDI+ Test", 200, 100) GUISetBkColor(0x505050) Global Const $iPicBtn = GUICtrlCreatePic("", 50, 28, 100, 44) Global $aButtons = _GDIPlus_BitmapCreateRoundedButtonAndText("install", 100, 44) _WinAPI_DeleteObject(GUICtrlSendMsg($iPicBtn, $STM_SETIMAGE, $IMAGE_BITMAP, $aButtons[0])) GUISetState() Global $aMouseInfo, $bShow = False, $bHide = False Do If WinActive($hGUI) Then $aMouseInfo = GUIGetCursorInfo($hGUI) ;hover simulation Switch $aMouseInfo[4] Case $iPicBtn _WinAPI_DeleteObject(GUICtrlSendMsg($iPicBtn, $STM_SETIMAGE, $IMAGE_BITMAP, $aButtons[1])) $bShow = True $bHide = False Case Else _WinAPI_DeleteObject(GUICtrlSendMsg($iPicBtn, $STM_SETIMAGE, $IMAGE_BITMAP, $aButtons[0])) $bHide = True $bShow = False EndSwitch EndIf Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _WinAPI_DeleteObject($aButtons[0]) _WinAPI_DeleteObject($aButtons[1]) _GDIPlus_Shutdown() Exit Case $iPicBtn MsgBox(0, "Information", "Button pressed") EndSwitch Until False ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GDIPlus_BitmapCreateRoundedButtonAndText ; Description ...: Draw rounded button ; Syntax ........: _GDIPlus_BitmapCreateRoundedButtonAndText($sString, $iWidth, $iHeight[, $iBgColor = 0xFF1BA0E1[, $iFontSize = 16[, $sFont = "Times New Roman"[, ; $iHoverColor = 0xFFC9388C[, $iFrameSize = 2[, $iFontFrameColor = 0x408AD5EA[, $iFontColor = 0xFFFFFFFF]]]]]]) ; Parameters ....: $sString - A string value. ; $iWidth - An integer value. ; $iHeight - An integer value. ; $iBgColor - [optional] An integer value. Default is 0xFF1BA0E1. ; $iFontSize - [optional] An integer value. Default is 16. ; $sFont - [optional] A string value. Default is "Times New Roman". ; $iHoverColor - [optional] An integer value. Default is 0xFFC9388C. ; $iFrameSize - [optional] An integer value. Default is 2. ; $iFontFrameColor - [optional] An integer value. Default is 0x408AD5EA. ; $iFontColor - [optional] An integer value. Default is 0xFFFFFFFF. ; Return values .: an array with 2 GDI bitmap handles -> [0]: default button, [1]: hover button ; Author ........: UEZ ; Version .......: 0.85 build 2025-01-12 ; Modified ......: ; Remarks .......: Dispose returned GDI bitmap handles when done ; Example .......: Yes ; =============================================================================================================================== Func _GDIPlus_BitmapCreateRoundedButtonAndText($sString, $iWidth, $iHeight, $iBgColor = 0xFF1BA0E1, $iFontSize = 16, $sFont = "Times New Roman", $iHoverColor = 0xF0FFFFFF, $iFrameSize = 2, $iFontFrameColor = 0x408AD5EA, $iFontColor = 0xFFFFFFFF) ;some checks If $sString = "" Then Return SetError(1, 0, 0) If Int($iWidth) < $iFrameSize * 2 Then Return SetError(2, 0, 0) If Int($iHeight) < $iFrameSize * 2 Then Return SetError(3, 0, 0) ;create font objects Local Const $hFormat = _GDIPlus_StringFormatCreate() Local Const $hFamily = _GDIPlus_FontFamilyCreate($sFont) Local $tLayout = _GDIPlus_RectFCreate(0, 0, $iWidth, $iHeight) _GDIPlus_StringFormatSetAlign($hFormat, 1) ;center string on X axis _GDIPlus_StringFormatSetLineAlign($hFormat, 1) ;center string on Y axis ;create bitmap and graphics context handles Local Const $aBitmaps[2] = [_GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight), _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight)] Local Const $aGfxCtxt[2] = [_GDIPlus_ImageGetGraphicsContext($aBitmaps[0]), _GDIPlus_ImageGetGraphicsContext($aBitmaps[1])] ;set drawing quality _GDIPlus_GraphicsSetSmoothingMode($aGfxCtxt[0], $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsSetSmoothingMode($aGfxCtxt[1], $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsSetTextRenderingHint($aGfxCtxt[0], $GDIP_TEXTRENDERINGHINTANTIALIASGRIDFIT) ;define brush and pen objects Local Const $hBrushFontColor = _GDIPlus_BrushCreateSolid($iFontColor) ;, $hBrushBGColor = _GDIPlus_BrushCreateSolid($iBgColor) Local Const $hPenFontFrameColor = _GDIPlus_PenCreate($iFontFrameColor, $iFrameSize), $hPenHoverColor = _GDIPlus_PenCreate($iHoverColor, $iFrameSize) ;create path object Local Const $hPath = _GDIPlus_PathCreate() ;create cloned path object for string measurement Local Const $hPath_Dummy = _GDIPlus_PathClone($hPath) _GDIPlus_PathAddString($hPath_Dummy, $sString, $tLayout, $hFamily, 0, $iFontSize, $hFormat) _GDIPlus_PathStartFigure($hPath) Local $fArcSize = $iWidth * 0.33333 _GDIPlus_PathAddArc($hPath, $iFrameSize, $iHeight - $fArcSize - $iFrameSize, $fArcSize, $fArcSize, 180, -90) ;BR _GDIPlus_PathAddArc($hPath, $iWidth - $fArcSize - $iFrameSize, $iHeight - $fArcSize - $iFrameSize, $fArcSize, $fArcSize, -270, -90) ;BL _GDIPlus_PathAddArc($hPath, $iWidth - $fArcSize - $iFrameSize, $iFrameSize, $fArcSize, $fArcSize, 0, -90) ;TR _GDIPlus_PathAddArc($hPath, $iFrameSize, $iFrameSize, $fArcSize, $fArcSize, -90, -90) ;TL _GDIPlus_PathCloseFigure($hPath) Local Const $hPath_Clone = _GDIPlus_PathClone($hPath) Local Const $hBrushBGColor = _GDIPlus_PathBrushCreateFromPath($hPath) _GDIPlus_PathBrushSetSurroundColor($hBrushBGColor, $iBgColor) _GDIPlus_PathBrushSetCenterColor($hBrushBGColor, 0xFFFFFFFF) _GDIPlus_PathBrushSetCenterPoint($hBrushBGColor, $iWidth / 2, $iHeight / 2) _GDIPlus_PathBrushSetSigmaBlend($hBrushBGColor, 1, 0.33333) _GDIPlus_GraphicsFillPath($aGfxCtxt[0], $hPath, $hBrushBGColor) _GDIPlus_GraphicsDrawPath($aGfxCtxt[0], $hPath, $hPenFontFrameColor) _GDIPlus_PathReset($hPath) ;add string to path _GDIPlus_PathAddString($hPath, $sString, $tLayout, $hFamily, 1, $iFontSize, $hFormat) ;clear bitmap and draw string _GDIPlus_GraphicsFillPath($aGfxCtxt[0], $hPath, $hBrushFontColor) _GDIPlus_GraphicsDrawPath($aGfxCtxt[0], $hPath, $hPenFontFrameColor) ;draw rectangle on cloned bitmap for hover effect _GDIPlus_GraphicsDrawImageRect($aGfxCtxt[1], $aBitmaps[0], 0, 0, $iWidth, $iHeight) _GDIPlus_GraphicsDrawPath($aGfxCtxt[1], $hPath_Clone, $hPenHoverColor) ;dispose object resources _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_PathDispose($hPath) _GDIPlus_PathDispose($hPath_Dummy) _GDIPlus_PathDispose($hPath_Clone) _GDIPlus_GraphicsDispose($aGfxCtxt[0]) _GDIPlus_GraphicsDispose($aGfxCtxt[1]) _GDIPlus_BrushDispose($hBrushFontColor) _GDIPlus_BrushDispose($hBrushBGColor) _GDIPlus_PenDispose($hPenFontFrameColor) _GDIPlus_PenDispose($hPenHoverColor) ;create GDI bitmap for later usage Local $aHBitmaps[2] = [_GDIPlus_BitmapCreateHBITMAPFromBitmap($aBitmaps[0]), _GDIPlus_BitmapCreateHBITMAPFromBitmap($aBitmaps[1])] ;dispose GDI+ bitmaps _GDIPlus_BitmapDispose($aBitmaps[0]) _GDIPlus_BitmapDispose($aBitmaps[1]) Return $aHBitmaps EndFunc ;==>_GDIPlus_BitmapCreateRoundedButtonAndText1 point
-
Method for Colorful Rectangle Buttons with rounded corners ; https://www.autoitscript.com/forum/topic/211721-round-buttons/#findComment-1540263 ;---------------------------------------------------------------------------------------- ; Title...........: RoundRectButtonsSpecial.au3 ; Description.....: collection of rectangles buttons - Special Edition ; AutoIt Version..: 3.3.16.1 Author: ioa747 ; Note............: Testet in Win10 22H2 ;---------------------------------------------------------------------------------------- #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <WinAPIGdi.au3> Global $MyGui, $aBtn[6][2] $MyGui = GUICreate(@ScriptName, 180, 220) GUISetBkColor(0x000000) GUISetState(@SW_SHOW) $aBtn[0][0] = 5 ; cnt of buttons $aBtn[1][1] = 0xA64500 $aBtn[1][0] = _CreateButton($MyGui, "Button1", 10, 20, 150, 30, $aBtn[1][1], -1, 0xFFFFFF, 10, 800) $aBtn[2][1] = 0x826E00 $aBtn[2][0] = _CreateButton($MyGui, "Button2", 10, 60, 150, 30, $aBtn[2][1], -1, 0xFFFFFF, 10, 800) $aBtn[3][1] = 0x268000 $aBtn[3][0] = _CreateButton($MyGui, "Button3", 10, 100, 150, 30, $aBtn[3][1], -1, 0xFFFFFF, 10, 800) $aBtn[4][1] = 0x0094FF $aBtn[4][0] = _CreateButton($MyGui, "Button4", 10, 140, 150, 30, $aBtn[4][1], -1, 0xFFFFFF, 10, 800) $aBtn[5][1] = 0x9600D5 $aBtn[5][0] = _CreateButton($MyGui, "Button5", 10, 180, 150, 30, $aBtn[5][1], -1, 0xFFFFFF, 10, 800) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch _IsOver() WEnd ;--------------------------------------------------------------------------------------- Func _IsOver() Local Static $iActive, $iClicked = 0 Local $aActive = GUIGetCursorInfo($MyGui) If $aActive[2] And $iClicked = 1 Then Return If $iActive <> $aActive[4] And $iClicked = 0 Then $iActive = $aActive[4] For $i = 1 To $aBtn[0][0] If $aBtn[$i][0] = $aActive[4] Then GUICtrlSetBkColor($aBtn[$i][0], ColorLight($aBtn[$i][1], 30)) ;hover Else GUICtrlSetBkColor($aBtn[$i][0], $aBtn[$i][1]) ;normal EndIf Next EndIf If $aActive[2] Or $iClicked = 1 Then For $i = 1 To $aBtn[0][0] If $aBtn[$i][0] = $iActive Then If $iClicked = 0 Then GUICtrlSetBkColor($aBtn[$i][0], ColorLight($aBtn[$i][1], -30)) ;click GUICtrlSetFont($aBtn[$i][0], 10, 800, 2, "MS Sans Serif") GUICtrlSetColor($aBtn[$i][0], 0xCCCCCC) $iClicked = 1 Else GUICtrlSetBkColor($aBtn[$i][0], ColorLight($aBtn[$i][1], 30)) ;hover GUICtrlSetFont($aBtn[$i][0], 10, 800, 0, "MS Sans Serif") GUICtrlSetColor($aBtn[$i][0], 0xFFFFFF) $iClicked = 0 _ButtonCaller($aBtn[$i][0]) EndIf EndIf Next EndIf EndFunc ;==>_IsOver ;--------------------------------------------------------------------------------------- Func _ButtonCaller($Btn) Switch $Btn Case $aBtn[1][0] ConsoleWrite(GUICtrlRead($aBtn[1][0]) & @CRLF) Case $aBtn[2][0] ConsoleWrite(GUICtrlRead($aBtn[2][0]) & @CRLF) Case $aBtn[3][0] ConsoleWrite(GUICtrlRead($aBtn[3][0]) & @CRLF) Case $aBtn[4][0] ConsoleWrite(GUICtrlRead($aBtn[4][0]) & @CRLF) Case $aBtn[5][0] ConsoleWrite(GUICtrlRead($aBtn[5][0]) & @CRLF) Case $aBtn[6][0] ConsoleWrite(GUICtrlRead($aBtn[6][0]) & @CRLF) EndSwitch EndFunc ;==>_ButtonCaller ; #FUNCTION# -------------------------------------------------------------------------------------------------------------------- ; Name...........: _CreateButton ; Description....: Creates a button with rounded corners. ; Syntax.........: _CreateButton($hGUI, $Text, $Left, $Top, $Width, $Height, $Color, $Corner = -1, $fColor = -1, $fSize = -1, $fWeight = -1, $fName = -1) ; Parameters.....: $hGUI - Handle to the parent GUI. ; $Text - Text to display on the button. ; $Left - Horizontal position of the button. ; $Top - Vertical position of the button. ; $Width - Width of the button. ; $Height - Height of the button. ; $Color - Background color of the button. ; $Corner - [optional] Corner radius of the button (default: $Height / 2). ; $fColor - [optional] Font color of the button text (default: 0x000000). ; $fSize - [optional] Font size of the button text (default: $Height * 0.4). ; $fWeight - [optional] Font weight of the button text (default: 400). ; $fName - [optional] Font name of the button text (default: "MS Sans Serif"). ; Return values..: The handle to the created button control. ; Author ........: ioa747 ; Notes .........: This function uses the WinAPI function CreateRoundRectRgn() and SetWindowRgn() to create a button with rounded corners. ; Link ..........: https://www.autoitscript.com/forum/topic/211721-round-buttons/#findComment-1540263 ; Dependencies...: #include <WinAPIGdi.au3>, #include <WindowsConstants.au3> ;-------------------------------------------------------------------------------------------------------------------------------- Func _CreateButton($hGUI, $Text, $Left, $Top, $Width, $Height, $Color, $Corner = -1, $fColor = -1, $fSize = -1, $fWeight = -1, $fName = -1) ; Validate parameters If $fColor = Default Or $fColor = -1 Then $fColor = 0x000000 If $fSize = Default Or $fSize = -1 Then $fSize = $Height * 0.4 If $fWeight = Default Or $fWeight = -1 Then $fWeight = 400 If $fName = Default Or $fName = -1 Then $fName = "MS Sans Serif" If $Corner < 0 Or $Corner = Default Then $Corner = $Height / 2 If $Corner > $Height / 2 Then $Corner = $Height If $Width <= 0 Or $Height <= 0 Then Return SetError(1, 0, 0) EndIf Local $hChGUI = GUICreate("", $Width, $Height, $Left, $Top, $WS_CHILD, $WS_EX_CONTROLPARENT, $hGUI) Local $idLabel = GUICtrlCreateLabel($Text, 0, 0, $Width, $Height, BitOR($SS_CENTER, $SS_NOTIFY, $SS_CENTERIMAGE)) GUICtrlSetBkColor($idLabel, $Color) GUICtrlSetColor($idLabel, $fColor) GUICtrlSetFont($idLabel, $fSize, $fWeight, 0, $fName) Local $hRgn = _WinAPI_CreateRoundRectRgn(0, 0, $Width, $Height, $Corner, $Corner) _WinAPI_SetWindowRgn($hChGUI, $hRgn) GUISetState() Return $idLabel EndFunc ;==>_CreateButton ; #FUNCTION# -------------------------------------------------------------------------------------------------------------------- ; Name...........: ColorLight() ; Description....: Returns a new color that is a combination of the $HexColor plus the amount of $Lightness it adds to all three RGB channels. ; Syntax.........: ColorLight($HexColor [, $Lightness [,$output]]) ; Parameters.....: $HexColor - The start color to be combined. ; $Lightness - The amount it adds to all three RGB channels. Negative number to subtract (darker) ; $output - Optional: The format of the output string: ; 0 = "0x" followed by the hexadecimal value of the new color (default) ; 1 = "#" followed by the hexadecimal value of the new color ; 2 = an array containing the red, green and blue values of the new color ; Return values..: The new color as a string or an array. ; Author ........: ioa747 ; Notes .........: ;-------------------------------------------------------------------------------------------------------------------------------- Func ColorLight($HexColor, $Lightness = 0, $sOutput = 0) If StringLeft($HexColor, 1) = "#" Then $HexColor = StringReplace($HexColor, "#", "0x") Local $sHexColor = Hex($HexColor, 6) ;ConsoleWrite("$sHexColor=" & $sHexColor & @CRLF) Local $aSplit = StringSplit($sHexColor, "") Local $aRGB[3] If $aSplit[0] = 6 Then $aRGB[0] = Dec($aSplit[1] & $aSplit[2], 0) $aRGB[1] = Dec($aSplit[3] & $aSplit[4], 0) $aRGB[2] = Dec($aSplit[5] & $aSplit[6], 0) ;ConsoleWrite(StringFormat("aRGB(%d,%d,%d)", $aRGB[0], $aRGB[1], $aRGB[2]) & @CRLF) Else ConsoleWrite("Something wrong $aSplit[0]=" & $aSplit[0] & @CRLF) Return SetError(1, 0, -1) EndIf Local $aNewRGB[] = [$aRGB[0] + $Lightness, $aRGB[1] + $Lightness, $aRGB[2] + $Lightness] If $aNewRGB[0] < 0 Then $aNewRGB[0] = 0 If $aNewRGB[0] > 255 Then $aNewRGB[0] = 255 If $aNewRGB[1] < 0 Then $aNewRGB[1] = 0 If $aNewRGB[1] > 255 Then $aNewRGB[1] = 255 If $aNewRGB[2] < 0 Then $aNewRGB[2] = 0 If $aNewRGB[2] > 255 Then $aNewRGB[2] = 255 ;ConsoleWrite(StringFormat("aNewRGB(%d,%d,%d)", $aNewRGB[0], $aNewRGB[1], $aNewRGB[2]) & @CRLF) Local $sColor ;$sOutput: 0:="0x" | 1:="#" | 2:=aRGB[R,G,B] Switch $sOutput Case 0, 1 $sColor = ($sOutput = 1 ? "#" : "0x") $sColor &= Hex(String($aNewRGB[0]), 2) $sColor &= Hex(String($aNewRGB[1]), 2) $sColor &= Hex(String($aNewRGB[2]), 2) ;ConsoleWrite("$sColor=" & $sColor & @CRLF & @CRLF) Case 2 $sColor = $aNewRGB EndSwitch Return $sColor EndFunc ;==>ColorLight have fun Thank you very much1 point
-
It's not the solution for the _GDIPlus problem, but it does make buttons with rounded corners. with the code from 212533-input-control-with-label-and-rounded-corners1 point