Declare Function Rectangle Lib "gdi32.dll" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
ForeColor
property. It basically performs the same function as Visual Basic's Line command when used with the B parameter. However, my own tests have shown that the Rectangle API function is slightly faster than the Visual Basic equivalent! So, if you are going to do a lot of graphics-intensive programming, use this code. If not, you should probably use Line. This function returns an error code you can safely disregard.hdc | The device context of the object. |
X1 | The x coordinate of the rectangle's upper-left corner. |
Y1 | The y coordinate of the rectangle's upper-left corner. |
X2 | The x coordinate of the rectangle's lower-right corner. |
Y2 | The y coordinate of the rectangle's lower-right corner. |
Draw a green rectangle
Picture1.ForeColor = RGB(0, 255, 0) 'green
x = Rectangle(Picture1.hdc, 25, 25, 100, 50)
Declare Function ReleaseDC Lib "user32.dll" (ByVal hWnd As Long, ByVal hdc As Long) As Long
hWnd | The handle of the object to break the association with. |
hdc | The variable holding the object's device context. |
x = ReleaseDC(desktophWnd, desktophdc)
Declare Function RoundRect Lib "gdi32.dll" (ByVal hdc As Long, X1 As Long, Y1 As Long, X2 As Long, Y2 As Long, X3 As Long, Y3 As Long) As Long
ForeColor
property. The first two (x,y) coordinate pairs in the parameter list are the upper-left and lower-right corners of a square-cornered rectangle the same dimensions as the one to be drawn. The last pair are the height and width of the ellipse used to make the rounded corners. Each corner is drawn as a corresponding "corner" of an ellipse of height 2*Y3 and width 2*X3. That is, X3 and Y3 are the width and height of the rounded corner. You can safely ignore the value returned.hdc | The device context of the graphical object to draw on. |
X1 | The x coordinate of the upper-left corner of the corresponding square-edged rectangle. |
Y1 | The y coordinate of the upper-left corner of the corresponding square-edged rectangle. |
X2 | The x coordinate of the lower-right corner of the corresponding square-edged rectangle. |
Y2 | The y coordinate of the lower-right corner of the corresponding square-edged rectangle. |
X3 | The width of each elliptical rounded corner. |
Y3 | The height of each elliptical rounded corner. |
'Draw a rounded rectangle with rounded corners 10 pixels wide and 5 high
'The rectangle stretches from (10,10) to (150,100).
'Draw this on Form1
Form1.Cls 'Clear drawings on the form
x = RoundRect(Form1.hDC, 10, 10, 150, 100, 10, 5)
Paul Kuliniewicz
E-mail: Borg953@aol.com
All material presented on these pages is Copyright © Paul Kuliniewicz, except for other copyrighted material.
http://members.aol.com/Borg953/api/r.html