Jump to content

Draw a rectangle box with circle corner in the GUI window


altex
 Share

Go to solution Solved by UEZ,

Recommended Posts

Hello everyone,

Does anyone know how to draw a rectangle box with round corner in the GUI window. This rectangle box should be transparent, so anything inside it can be shown.

Attached picture is an example. As you can see, there are a rectangle box with circle corner as well as a progress bar inside it.

X70Niyy3.png

 

Also, as you can see, this progress bar has a border with darker yellow colour.  Can someone give some advice? Thank you.

Edited by altex
Link to comment
Share on other sites

You can start with this link: 

You need to adjust the code if you are running 3.3.12.0.

 

Br,

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

You can start with this link: 

You need to adjust the code if you are running 3.3.12.0.

 

Br,

UEZ

 

i tried every approach in that thread. All I need is a rectangle board with circle corner. Examples in that thread make the rectangle box "filled", there is no way to place an progress bar inside it.

Link to comment
Share on other sites

  • Solution

Well, then try this:

 

;coded by UEZ build 2014-09-27
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


_GDIPlus_Startup()
Global $iCountdown = 20 ;in seconds

Global Const $iW = 800, $iH = 50, $STM_SETIMAGE = 0x0172
Global Const $hGUI = GUICreate("Test", $iW, $iH, -1, -1, $WS_POPUP)
Global Const $hPic = GUICtrlCreatePic("", 0, 0, $iW, $iH)
Global Const $hRegion = _WinAPI_CreateRoundRectRgn(0, 0, $iW + 1, $iH + 1, 12, 12)
_WinAPI_SetWindowRgn($hGUI, $hRegion)
Global $hGDIBmp_Bg = _GDIPlus_BitmapCreateRoundCornerRectProgressbar(100, $iCountdown & " seconds left to start rocket", $iW, $iH, 6)
_WinAPI_DeleteObject(GUICtrlSendMsg($hPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hGDIBmp_Bg))
GUISetState()
Global $iDiff, $iTimer = TimerInit()

Do
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _Exit()
    EndSwitch
    $iDiff = (TimerDiff($iTimer) / 1000)
    If $iDiff < $iCountdown + 1 Then
        $hGDIBmp_Bg = _GDIPlus_BitmapCreateRoundCornerRectProgressbar(100 - $iDiff / $iCountdown * 100, Int($iCountdown - $iDiff) & " seconds left to take off", $iW, $iH, 6)
        _WinAPI_DeleteObject(GUICtrlSendMsg($hPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hGDIBmp_Bg))
        _WinAPI_DeleteObject($hGDIBmp_Bg)
    Else
        $hGDIBmp_Bg = _GDIPlus_BitmapCreateRoundCornerRectProgressbar(0, "Taking off...", $iW, $iH, 6)
        _WinAPI_DeleteObject(GUICtrlSendMsg($hPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hGDIBmp_Bg))
        _WinAPI_DeleteObject($hGDIBmp_Bg)
        Sleep(2000)
        _Exit()
    EndIf
Until False

Func _Exit()
    _WinAPI_DeleteObject($hRegion)
    _WinAPI_DeleteObject($hGDIBmp_Bg)
    GUIDelete()
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>_Exit

Func _GDIPlus_BitmapCreateRoundCornerRectProgressbar($fPerc, $sText, $iW, $iH, $iRadius_Corner = 6, _
        $iColorOuter_Pb = 0xFFC4A000, $iColorInner_Pb = 0xFFFCE94F, $iColorOuter_Bg = 0xFFA0A0A0, $iColorInner_Bg = 0xFFD3D7CF, _
        $iSizeBorder_Bg = 4, $iSizeBorder_Pb = 4, _
        $sFont = "Arial Black", $fFontSize = 20, $iColor_FontBorder = 0xFF101010, $iColor_Font = 0xFFFFFFFF, $iSizeBorder_Ft = 2, $bGDIBitmap = True)
    Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH), $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 4)
    #Region background
    Local Const $hPath = _GDIPlus_PathCreate()
    Local $iWidth = $iW - $iSizeBorder_Bg - 1, $iHeight = $iH - $iSizeBorder_Bg - 1
    _GDIPlus_PathAddArc($hPath, $iSizeBorder_Bg / 2, $iSizeBorder_Bg / 2, $iRadius_Corner * 2, $iRadius_Corner * 2, 180, 90) ;left upper corner
    _GDIPlus_PathAddArc($hPath, $iWidth - $iRadius_Corner * 2 + $iSizeBorder_Bg / 2, $iSizeBorder_Bg / 2, $iRadius_Corner * 2, $iRadius_Corner * 2, 270, 90) ;right upper corner
    _GDIPlus_PathAddArc($hPath, $iWidth - $iRadius_Corner * 2 + $iSizeBorder_Bg / 2, $iHeight - $iRadius_Corner * 2 + $iSizeBorder_Bg / 2, $iRadius_Corner * 2, $iRadius_Corner * 2, 0, 90) ;right bottom corner
    _GDIPlus_PathAddArc($hPath, $iSizeBorder_Bg / 2, $iHeight - $iRadius_Corner * 2 + $iSizeBorder_Bg / 2, $iRadius_Corner * 2, $iRadius_Corner * 2, 90, 90) ;left bottm corner
    _GDIPlus_PathCloseFigure($hPath)
    Local $hPen = _GDIPlus_PenCreate($iColorOuter_Bg, $iSizeBorder_Bg), $hBrush = _GDIPlus_BrushCreateSolid($iColorInner_Bg)
    _GDIPlus_GraphicsDrawPath($hGraphics, $hPath, $hPen)
    _GDIPlus_GraphicsFillPath($hGraphics, $hPath, $hBrush)
    #EndRegion background

    #Region progressbar
    Local $iX = 3 * $iSizeBorder_Pb, $iY = 3 * $iSizeBorder_Pb
    $iHeight = $iH - 2 * $iY
    $fPerc = $fPerc < 0 ? 0 : $fPerc > 100 ? 100 : $fPerc
    $iWidth = ($iW - 2 * $iX) * $fPerc / 100
    _GDIPlus_PathReset($hPath)
    _GDIPlus_PenSetColor($hPen, $iColorOuter_Pb)
    _GDIPlus_PenSetWidth($hPen, $iSizeBorder_Pb)
    _GDIPlus_BrushSetSolidColor($hBrush, $iColorInner_Pb)
    _GDIPlus_PathAddRectangle($hPath, $iX, $iY, $iWidth, $iHeight)
    _GDIPlus_GraphicsDrawPath($hGraphics, $hPath, $hPen)
    _GDIPlus_GraphicsFillPath($hGraphics, $hPath, $hBrush)
    #EndRegion progressbar

    #Region text render
    _GDIPlus_PathReset($hPath)
    Local Const $hFormat = _GDIPlus_StringFormatCreate()
    Local Const $hFamily = _GDIPlus_FontFamilyCreate($sFont)
    Local Const $tLayout = _GDIPlus_RectFCreate(0, 0, $iW, $iH)
    _GDIPlus_StringFormatSetAlign($hFormat, 1)
    _GDIPlus_StringFormatSetLineAlign($hFormat, 1)
    _GDIPlus_GraphicsSetTextRenderingHint($hGraphics, 4)
    _GDIPlus_PathAddString($hPath, $sText, $tLayout, $hFamily, 0, $fFontSize, $hFormat)
    _GDIPlus_PenSetColor($hPen, $iColor_FontBorder)
    _GDIPlus_PenSetWidth($hPen, $iSizeBorder_Ft)
    _GDIPlus_BrushSetSolidColor($hBrush, $iColor_Font)
    _GDIPlus_GraphicsDrawPath($hGraphics, $hPath, $hPen)
    _GDIPlus_GraphicsFillPath($hGraphics, $hPath, $hBrush)
    #EndRegion text render

    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_PathDispose($hPath)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGraphics)
    If $bGDIBitmap Then
        Local Const $hGDIBmp_Bg = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
        _GDIPlus_BitmapDispose($hBitmap)
        Return $hGDIBmp_Bg
    EndIf
    Return $hBitmap
EndFunc   ;==>_GDIPlus_BitmapCreateRoundCornerRectProgressbar

Br,

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

Thank you,sir. It works as expected. You even duplicate the color of the progress bar in my picture :thumbsup:

One more question, how to realize the following: Pop up a new window (e.g. Setting window) when I click some button from current GUI window and keep the new window always on top of the old one until I close the new window? After closing the new window, we go back to the main GUI window rather than exiting the program. And how can I adjust the size of the new window, but only adjust the height of it?

Edited by altex
Link to comment
Share on other sites

Just create an child GUI using GUICreate() by providing the handle to the parent GUI. Further use BitOR($WS_EX_MDICHILD, $WS_EX_TOPMOST) as an ext. style.

Check out the help file and search the forum - there are plenty of examples.

Br,

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