Jump to content

[SOLVED] Rounded corner and Border Label


Recommended Posts

Hi,

I'm searching for a way to round the 4 corner surrounding a label. After doing some searching, I came across a way to round corners of a GUI using GDI32.dll. I use it for my GUI, and it works like a charm. So I try using it for my label, but, unfortunately it doesn't work out. :)

I thought GDI32.dll also has some function to do this, so I tried searching for a list of function in GDI32.dll on MSDN, and it gives me like thousands of articles with some being so general, and some other talking about some other stuff, and only mention GDI32.dll one time in the whole article. I think I should practice searching on MSDN much much more.

Then I try using Google, but again, I didn't succeed. :)

Can anyone please help me out with this? Here's my testing code.

Thanks guys very much in advance, ;)

And have a good day,

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=c:\documents and settings\vietdtq\desktop\projects\treasure hunter\form1.kxf
$Form1 = GUICreate("Testing", 790, 405, -1, -1, BitOR($WS_MINIMIZEBOX,$WS_POPUP,$WS_GROUP))
_Gui_RoundCorners(WinGetHandle("Testing"), 0, 0, 30, 30)
$Label = GUICtrlCreateLabel("A", 100, 100, 44, 49, BitOR($SS_CENTER,$SS_CENTERIMAGE,$WS_BORDER))
;_Gui_RoundCorners(GUICtrlGetHandle($Label), 0, 0, 10, 10)
GUICtrlSetFont(-1, 16, 800, 0, "Georgia")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case 0
  Case $GUI_EVENT_CLOSE
   Exit
EndSwitch
WEnd
Func _Gui_RoundCorners($h_win, $i_x1, $i_y1, $i_x3, $i_y3)
Local $XS_pos, $XS_ret, $XS_ret2
$XS_pos = WinGetPos($h_win)
$XS_ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $i_x1, "long", $i_y1, "long", $XS_pos[2], "long", $XS_pos[3], "long", $i_x3, "long", $i_y3)
If $XS_ret[0] Then
  $XS_ret2 = DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $XS_ret[0], "int", 1)
EndIf
EndFunc
Edited by eEniquEe
Link to comment
Share on other sites

I've never tried doing rounded corners on a label but you can try sending the _Gui_RoundCorners() func the HANDLE to the control using GuiCtrlGetHandle()

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

I've never tried doing rounded corners on a label but you can try sending the _Gui_RoundCorners() func the HANDLE to the control using GuiCtrlGetHandle()

Yes, I did try it, but it didn't work. ;)

When I use _Gui_RoundCorners() func on bordered labels, the 4 bordered corners disappear (making it looks a little bit ugly), then I tried setting Bkcolor for the labels, and it reveals that the corner hasn't been rounded at all.

Link to comment
Share on other sites

When I use _Gui_RoundCorners() func on bordered labels, the 4 bordered corners disappear (making it looks a little bit ugly), then I tried setting Bkcolor for the labels, and it reveals that the corner hasn't been rounded at all.

You can't round the corners of a label (Static control) with that code unless a class property of the Static control is removed.

You can remove the style, and it works, but there might be issues, these methods are better.

Look into the png gui methods on the forum for making smoother looking rounded forms and rounded labels.

Playlet has a vertical tab gui that uses a rounded png form with a drop shadow and rounded png labels

Example uses code from here:

Translucent label on pic control

_GDIPlus_GraphicsDrawRoundRect

The GDI rounded labels have border and bodies with sharper aliased edges.

The GDI+ labels are anti-aliased and the border alpha can be set lower for a softer look.

You will have adjust the text alignment in the GDI+ example.

;GDI - GDI+ round static control border frames and bodies
;coded by rover 2k12
;GDI+ code from Funkey and Wide Boy Dixon

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>
#include <WinAPI.au3>
#include <GDIPlus.au3>

Global $aLblCtrl[1][4]
_Main()

Func _Main()
Local $Form1 = GUICreate("Testing", 790, 405, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_POPUP, $WS_GROUP))
_Gui_RoundCorners($Form1, 0, 0, 30, 30)

Local $Wow64 = ""
If @AutoItX64 Then $Wow64 = "\Wow6432Node"
Local $sPath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE" & $Wow64 & "\AutoIt v3\AutoIt", "InstallDir") & "\Examples\GUI\msoobe.jpg"
Local $cPic = GUICtrlCreatePic($sPath, 0, 0, 790, 405, 0)
GuiCtrlSetState(-1, $GUI_DISABLE)

;brushes and pens - stock object can be called as needed, handles are always the same for 2nd+ copies - handles do not have to be deleted.
Local $hBrushCol2 = _WinAPI_CreateSolidBrush(0x494949)
Local $hPen2 = _WinAPI_CreatePen($PS_SOLID, 1, 0xFF0000)

Local $c0 = GUICtrlCreateDummy(), $nMsg
GUICtrlDelete($c0)

ReDim $aLblCtrl[7+$c0][4]
$aLblCtrl[0][0] = $c0 ; set first element to first control ID

;GDI
$aLblCtrl[$c0][0] = GUICtrlCreateLabel("A", 100, 100, 44, 49, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 16, 800, 0, "Georgia", $ANTIALIASED_QUALITY)
$aLblCtrl[$c0][1] = 0x000000 ;default black text colour
$aLblCtrl[$c0][2] = 0x000000 ;default black pen border frame
$aLblCtrl[$c0][3] = _WinAPI_GetStockObject($LTGRAY_BRUSH) ;grey label background
$c0+=1
$aLblCtrl[$c0][0] = GUICtrlCreateLabel("B", 100, 180, 44, 49, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 16, 800, 0, "Georgia", $ANTIALIASED_QUALITY)
$aLblCtrl[$c0][1] = 0xF4F4F4 ;white text colour - BGR
$aLblCtrl[$c0][2] = $hPen2 ;blue pen border frame
$aLblCtrl[$c0][3] = _WinAPI_GetStockObject($NULL_BRUSH) ;transparent label background
$c0+=1
$aLblCtrl[$c0][0] = GUICtrlCreateLabel("C", 100, 260, 44, 49, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetFont(-1, 16, 800, 0, "Georgia", $ANTIALIASED_QUALITY)
$aLblCtrl[$c0][1] = 0x00FFFF ;yellow text colour - BGR
$aLblCtrl[$c0][2] = _WinAPI_GetStockObject($NULL_PEN) ;transparent pen border frame - no border - rounded label body
$aLblCtrl[$c0][3] = $hBrushCol2 ;dark brown label background
$aLblCtrl[1][0] = $aLblCtrl[$c0][0] ; set second element to last control ID
$aLblCtrl[2][0] = _WinAPI_GetStockObject($NULL_BRUSH) ; set third element to null brush
$aLblCtrl[$c0+1][3] = 10 ; ellipse width
$aLblCtrl[$c0+2][3] = 10 ; ellipse height
$aLblCtrl[$c0+3][3] = DllOpen("gdi32.dll")
$aLblCtrl[$c0+4][3] = DllOpen("user32.dll")

;GDI+
GUICtrlCreateLabel("A", 200, 100, 44, 49, BitOR($SS_CENTER, $SS_CENTERIMAGE))
_LabelMakeTranslucent(-1, $cPic, 44, 49, 6, 0x205555f5, 0xEEf0f000, 0x77000000, 1, "", 16, "Georgia", BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlCreateLabel("B", 200, 180, 44, 49, BitOR($SS_CENTER, $SS_CENTERIMAGE))
_LabelMakeTranslucent(-1, $cPic, 44, 49, 6, 0xAA494949, 0xFF000000, 0x00000000, 1, "", 16, "Georgia", BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlCreateLabel("C", 200, 260, 44, 49, BitOR($SS_CENTER, $SS_CENTERIMAGE))
_LabelMakeTranslucent(-1, $cPic, 44, 49, 6, 0x50000000, 0xFFFFFFFF, 0x77FFFFFF, 1, "", 16, "Georgia", BitOR($SS_CENTER, $SS_CENTERIMAGE))

GUIRegisterMsg($WM_CTLCOLORSTATIC, '_WM_CTLCOLORSTATIC')
GUISetState(@SW_SHOW)

While 1
  $nMsg = GUIGetMsg()
  Switch $nMsg
   Case 0
   Case $GUI_EVENT_CLOSE
    ;delete non-stock object resources - no need to delete stock objects on exit
    _WinAPI_DeleteObject($hBrushCol2)
    _WinAPI_DeleteObject($hPen2)
    Exit
  EndSwitch
WEnd
EndFunc

Func _WM_CTLCOLORSTATIC($hWnd, $msg, $wParam, $lParam)
#forceref $hWnd, $Msg
Local $hDC = $wParam, $iLast = $aLblCtrl[1][0]
Local $ID = DllCall($aLblCtrl[$iLast+4][3], "int", "GetDlgCtrlID", "hwnd", $lParam)
If @error Then Return $GUI_RUNDEFMSG
If $ID[0] < $aLblCtrl[0][0] Or $ID[0] > $aLblCtrl[1][0] Then Return $GUI_RUNDEFMSG ;filter out other labels or controls
DllCall($aLblCtrl[$iLast+3][3], "int", "SetBkMode", "handle", $hDC, "int", $TRANSPARENT) ;transparent text background
DllCall($aLblCtrl[$iLast+3][3], "int", "SetTextColor", "hwnd", $hDC, "int", $aLblCtrl[$ID[0]][1]) ;text colour
DllCall($aLblCtrl[$iLast+3][3], "handle", "SelectObject", "handle", $hDC, "handle", $aLblCtrl[$ID[0]][2]) ;border frame pen colour
DllCall($aLblCtrl[$iLast+3][3], "handle", "SelectObject", "handle", $hDC, "handle", $aLblCtrl[$ID[0]][3]) ;background fill colour
Local $aPos = ControlGetPos($lParam, '', $lParam)
DllCall($aLblCtrl[$iLast+3][3], 'int', 'RoundRect', 'handle', $hdc, 'int', 0, 'int', 0, 'int', $aPos[2]-1, 'int', $aPos[3]-1, 'int', $aLblCtrl[$iLast+1][3], 'int', $aLblCtrl[$iLast+2][3])
Return $aLblCtrl[2][0]
EndFunc   ;==>_WM_CTLCOLORSTATIC

Func _Gui_RoundCorners($h_win, $i_x1, $i_y1, $i_x3, $i_y3)
Local $XS_pos, $XS_ret, $XS_ret2
$XS_pos = WinGetPos($h_win)
$XS_ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $i_x1, "long", $i_y1, "long", $XS_pos[2], "long", $XS_pos[3], "long", $i_x3, "long", $i_y3)
If $XS_ret[0] Then
  $XS_ret2 = DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $XS_ret[0], "int", 1)
EndIf
EndFunc   ;==>_Gui_RoundCorners

;code below from:
;Author: Funkey
;Translucent label on pic control
;http://www.autoitscript.com/forum/topic/133687-translucent-label-on-pic-control/
Func _LabelMakeTranslucent($nLbl, $nPic, $iW = 0, $iH = 0, $iRadius = 0, $TransColor = 0x30FFFFFF, $FontColor = 0xFF000000, $Frame = 0xFF000000, $StartGdip = 1, $sText = "", $iSize = 8, $sFontName = "Arial", $iStyle = 0)
;Author: Funkey
Local $hLbl = GUICtrlGetHandle($nLbl)
Local $hPic = GUICtrlGetHandle($nPic)
Local $hImage = _SendMessage($hPic, 371)
Local $hParent = _WinAPI_GetParent($hLbl)
Local $Style = _WinAPI_GetWindowLong($hLbl, -16)
Local $iSS_CENTER = BitAND($Style, 0x1)
Local $iSS_RIGHT = BitAND($Style, 0x2)
Local $iSS_CENTERIMAGE = BitAND($Style, 0x200)
Local $IsPic = BitAND($Style, 0xE)

;ConsoleWrite($IsPic & @CR)
If $sText = "" Then $sText = GUICtrlRead($nLbl)
If $IsPic = 0xE Then
  $iSS_CENTER = BitAND(GUICtrlRead($nLbl), 0x1)
  $iSS_RIGHT = BitAND(GUICtrlRead($nLbl), 0x2)
  $iSS_CENTERIMAGE = BitAND(GUICtrlRead($nLbl), 0x200)
Else
  GUICtrlSetData($nLbl, $Style) ;remember the old style in text
  If $iSS_CENTER Then $Style = BitXOR($Style, 0x1) ;delete SS_CENTER
  _WinAPI_SetWindowLong($hLbl, -16, BitOR($Style, 0x200, 0xE))
EndIf
Local $aLblPos = ControlGetPos($hParent, "", $hLbl)
Local $aPicPos = ControlGetPos($hParent, "", $nPic)

If $StartGdip Then _GDIPlus_Startup()
Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hImage)
Local $hBitmap2 = _GDIPlus_BitmapCloneArea($hBitmap, $aLblPos[0] - $aPicPos[0], $aLblPos[1] - $aPicPos[1], $aLblPos[2], $aLblPos[3])
Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap2)
_GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2) ;Anti-Aliasing
Local $hBrushArea = _GDIPlus_BrushCreateSolid($TransColor)
_GDIPlus_GraphicsDrawRoundRect($hGraphics, 0, 0, $iW-3, $iH-3, $iRadius, $hBrushArea, $Frame)
;_GDIPlus_GraphicsFillRect($hGraphics, 0, 0, $aLblPos[2], $aLblPos[3], $hBrushArea)

Local $hBrushText = _GDIPlus_BrushCreateSolid($FontColor)
Local $hFormat = _GDIPlus_StringFormatCreate()
Local $hFontFamily = _GDIPlus_FontFamilyCreate($sFontName)
Local $hFont = _GDIPlus_FontCreate($hFontFamily, $iSize, $iStyle)
Local $tLayout = _GDIPlus_RectFCreate()
If $iSS_CENTERIMAGE Then DllStructSetData($tLayout, 2, $aLblPos[3] / 2 - $iSize + 4) ;vertical center
Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $sText, $hFont, $tLayout, $hFormat)
If $iSS_CENTER Then DllStructSetData($aInfo[0], 1, ($aLblPos[2] - DllStructGetData($aInfo[0], 3)) / 2) ;horizontal center
If $iSS_RIGHT Then DllStructSetData($aInfo[0], 1, $aLblPos[2] - DllStructGetData($aInfo[0], 3) - 1) ; right
_GDIPlus_GraphicsDrawStringEx($hGraphics, $sText, $hFont, $aInfo[0], $hFormat, $hBrushText)

Local $hImageNew = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap2)
_WinAPI_DeleteObject(GUICtrlSendMsg($nLbl, 370, 0, $hImageNew))

_WinAPI_DeleteObject($hImageNew)
_GDIPlus_ImageDispose($hBitmap)
_GDIPlus_ImageDispose($hBitmap2)
_GDIPlus_BrushDispose($hBrushArea)
_GDIPlus_BrushDispose($hBrushText)
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFontFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_GraphicsDispose($hGraphics)
If $StartGdip Then _GDIPlus_Shutdown()
EndFunc   ;==>_LabelMakeTranslucent


;code below from:
;Author: Wide Boy Dixon
;_GDIPlus_GraphicsDrawRoundRect
;http://www.autoitscript.com/forum/topic/97362-gdiplus-graphicsdrawroundrect/
Func _GDIPlus_GraphicsDrawRoundRect($hGraphics, $iX, $iY, $iWidth, $iHeight, $iRadius, $hBrush = 0, $hPen = 0)
;Author: Wide Boy Dixon
    $hPen = _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

Func _GDIPlus_GraphicsPathCreate($iFillMode = 0)
;Author: Wide Boy Dixon
    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)
;Author: Wide Boy Dixon
    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)
;Author: Wide Boy Dixon
    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)
;Author: Wide Boy Dixon
    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)
;Author: Wide Boy Dixon
    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)
;Author: Wide Boy Dixon
    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)
;Author: Wide Boy Dixon
    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

I see fascists...

Link to comment
Share on other sites

You can use a child gui too:

#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <WinAPI.au3>
Global $hGui = GUICreate("MainForm")
_GuiCtrlCreateRoundedLabel($hGui, "Round Label", 10, 10, 100, 30, 0x201)
GUICtrlSetBkColor(-1, 0xabcdef)
_GuiCtrlCreateRoundedLabel($hGui, "Red Label", 10, 50, 100, 30, 0x201)
GUICtrlSetBkColor(-1, 0xFF0000)
GUISetState()
Do
Until GUIGetMsg() = -3

Func _GuiCtrlCreateRoundedLabel($hParent, $sText, $iX, $iY, $iW, $iH, $iStyle = $GUI_SS_DEFAULT_LABEL, $iExStyle = 0)
Local $hChild = GUICreate($sText, $iW, $iH, $iX, $iY, $WS_CHILD, 0, $hParent)
_Gui_RoundCorners($hChild, 0, 0, 10, 10)
Local $nLabel = GUICtrlCreateLabel($sText, 0, 0, $iW, $iH, $iStyle, $iExStyle)
GUISetState()
GUISwitch($hParent)
Return $nLabel
EndFunc   ;==>_GuiCtrlCreateRoundedLabel
Func _Gui_RoundCorners($h_win, $i_x1, $i_y1, $i_x3, $i_y3)
Local $XS_pos, $XS_ret, $XS_ret2
$XS_pos = WinGetPos($h_win)
$XS_ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $i_x1, "long", $i_y1, "long", $XS_pos[2], "long", $XS_pos[3], "long", $i_x3, "long", $i_y3)
If $XS_ret[0] Then
  $XS_ret2 = DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $XS_ret[0], "int", 1)
EndIf
EndFunc   ;==>_Gui_RoundCorners

Edit: Sorry, forgot about the border! ;)

#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <WinAPI.au3>
#include <GUIConstantsEx.au3>
Global $hGui = GUICreate("MainForm")
_GuiCtrlCreateRoundedLabel($hGui, "Round Label", 10, 10, 100, 30, 0xABCDEF, 0x201)
_GuiCtrlCreateRoundedLabel($hGui, "Red Label", 10, 50, 100, 30, 0XFF0000, 0x201)
GUISetState()
Do
Until GUIGetMsg() = -3

Func _GuiCtrlCreateRoundedLabel($hParent, $sText, $iX, $iY, $iW, $iH, $iColor, $iStyle = $GUI_SS_DEFAULT_LABEL, $iExStyle = 0)
 Local $hChild = GUICreate($sText, $iW, $iH, $iX, $iY, $WS_CHILD, 0, $hParent)
 GUISetBkColor($iColor)
 _Gui_RoundCorners($hChild, 0, 0, $iW - 1, $iH - 1)
 GUICtrlCreateGraphic(0, 0, $iW, $iH, 0)
 GUICtrlSetGraphic(-1, $GUI_GR_PENSIZE, 3)
 GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 0, 0, $iW - 1, $iH - 1)
 Local $nLabel = GUICtrlCreateLabel($sText, 0, 0, $iW, $iH, $iStyle, $iExStyle)
 GUICtrlSetBkColor(-1, -2)
 GUISetState()
 GUISwitch($hParent)
 Return $nLabel
EndFunc   ;==>_GuiCtrlCreateRoundedLabel
Func _Gui_RoundCorners($h_win, $i_x1, $i_y1, $i_x3, $i_y3)
 Local $XS_pos, $XS_ret, $XS_ret2
 $XS_pos = WinGetPos($h_win)
 $XS_ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $i_x1, "long", $i_y1, "long", $XS_pos[2], "long", $XS_pos[3], "long", $i_x3, "long", $i_y3)
 If $XS_ret[0] Then
  $XS_ret2 = DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $XS_ret[0], "int", 1)
 EndIf
EndFunc   ;==>_Gui_RoundCorners
Edited by funkey

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

Thanks everyone very much for your kind support.

Thanks rover, I really like the final output of your code. I'll try to apply that to my project, though it looks a little bit complicated. But I think I can figure it out, every line is commented carefully.

And I also want to thank funkey, I also love your approach. It's a creative, easy and nice way to tackle the problem.

I think I do learn something new today. Thank you guys very much for your kind help. ;)

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