RoundRect Function

Declare Function RoundRect Lib "gdi32.dll" (ByVal hdc As Long, ByVal nLeftRect As Long, ByVal nTopRect As Long, ByVal nRightRect As Long, ByVal nBottomRect As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long

Platforms

Description & Usage

RoundRect draws a rectangle with rounded corners on a device. The rounded rectangle is drawn in the device's current and is filled using its current brush. The first two (x,y) coordinate pairs specified are the upper-left and lower-right corners of a comparable square-cornered rectangle. The third pair specifies the width and height of the rounded corner to use.

Return Value

If an error occurs, the function returns 0 (Windows NT, 2000: use GetLastError to get the error code). If successful, the function returns a non-zero value.

Visual Basic-Specific Issues

None.

Parameters

hdc
A handle to the device context of the device to draw on.
nLeftRect
The x-coordinate of the upper-left corner of the corresponding square-edged rectangle.
nTopRect
The y-coordinate of the upper-left corner of the corresponding square-edged rectangle.
nRightRect
The x-coordinate of the lower-right corner of the corresponding square-edged rectangle.
nBottomRect
The y-coordinate of the lower-right corner of the corresponding square-edged rectangle.
nWidth
The width of each rounded corner.
nHeight
The height of each rounded corner.

Example

' This code is licensed according to the terms and conditions listed here.

' Declarations and such needed for the example:
' (Copy them to the (declarations) section of a module.)
Public Declare Function RoundRect Lib "gdi32.dll" (ByVal hdc As Long, ByVal nLeftRect _
	As Long, ByVal nTopRect As Long, ByVal nRightRect As Long, ByVal nBottomRect _
	As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Public Declare Function SelectObject Lib "gdi32.dll" (ByVal hdc As Long, ByVal hObject _
	As Long) As Long
Public Declare Function GetStockObject Lib "gdi32.dll" (ByVal nIndex As Long) As Long
Public Const WHITE_PEN = 6
Public Const LTGRAY_BRUSH = 1

' Draw a white rounded rectangle on window Form1 with an upper-left
' corner of (25,30) and a lower-right corner of (100,50).  Give the rounded
' corners a width of 10 and a height of 5.  Fill the shape with light gray.
Dim hPen As Long  ' handle to the pen to use to draw the shape
Dim hBrush As Long  ' handle to the brush to use to draw the shape
Dim hOldPen As Long  ' handle to Form1's previous pen
Dim hOldBrush As Long  ' handle to Form1's previous brush
Dim retval As Long  ' return value

' Get handles to the appropriate stock pen and brush.
hPen = GetStockObject(WHITE_PEN)
hBrush = GetStockObject(LTGRAY_BRUSH)
' Select the pen and brush for use by Form1.
hOldPen = SelectObject(Form1.hDC, hPen)
hOldBrush = SelectObject(Form1.hDC, hBrush)
' Draw the rounded rectangle.
retval = RoundRect(Form1.hDC, 25, 30, 100, 50, 10, 5)
' Restore Form1's previous pen and brush selections.
retval = SelectObject(Form1.hDC, hOldPen)
retval = SelectObject(Form1.hDC, hOldBrush)

See Also

Rectangle

Category

Filled Shapes

Go back to the alphabetical Function listing.
Go back to the Reference section index.


Last Modified: April 16, 2000
This page is copyright © 2000 Paul Kuliniewicz. Copyright Information.
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/r/roundrect.html