Hi.
I draw a RoundRect with red brush, inside this one i need to fill with
a gradient color...!
Col1 to Col2...
My problem was that with GradientFillRect i paint only RECT bat not
RndRect...
I have not any idea.
tnx
@Alex
Alessandro Baraldi <ik2zok@libero.it> schrieb im Beitrag
<1190414523.951336.27690@50g2000hsm.googlegroups.com>...
> I draw a RoundRect with red brush, inside this one i need to fill with
> a gradient color...!
> Col1 to Col2...
Why don't you read the documentation? It states that the frame of the
rectangle will be drawn with the current pen (not brush!) and that its
interior will be filled with the current brush. So you have to create a
brush with the colour you need, select it into the DC, and then draw the
rectangle. And don't forget to replace the brush afterwards with the DC's
original brush.

Signature
----------------------------------------------------------------------
THORSTEN ALBERS Universität Freiburg
albers@
uni-freiburg.de
----------------------------------------------------------------------
ALESSANDRO Baraldi - 22 Sep 2007 18:14 GMT
> Why don't you read the documentation? It states that the frame of the
> rectangle will be drawn with the current pen (not brush!) and that its
[quoted text clipped - 3 lines]
> original brush.
> THORSTEN ALBERS
Mmm...
I usually read documentation don't warry, if i write it's only because i
can't understand, so
i ask any suggestion can help me...!
So this is my short code:
'Crete a new pen and new Brush
hRPen = CreatePen(PS_SOLID, 1, myColor)
'Select our pen into the form's device context and delete the old
pen
DeleteObject SelectObject(hDcCreate, hRPen)
mBrush = CreateSolidBrush(myColor)
DeleteObject SelectObject(hDcCreate, mBrush)
' Draw Round Rect
RoundRect hDcCreate, x, y, cx, cy, R, R
' THIS WAS GRADIENT FILLED... BUT NOT ROUNDED
' ColorSTART
With vertR(0)
.x = sp
.y = 5
.Red = -256
.Green = 0&
.Blue = 0&
.Alpha = 0&
End With
'ColorEND
With vertR(1)
.x = sp - dx + mARRW
.y = 25
.Red = 0&
.Green = 0&
.Blue = -256
.Alpha = 0&
End With
gRect.UpperLeft = 0
gRect.LowerRight = 1
GradientFillRect hDcCreate, vertR(0), 2, gRect, 1, 0
As you can see i obtain a roundRect filled object, but is not gradient
filled.... because i don't know how do it...!
Using GradientFillRect i obtain a right RECT gradient filled... but not
ROUNDED...!
Now i hope it's more clear mi problem.
TNX

Signature
@Alex (Alessandro Baraldi)
---------------------------------------------------------------------------
http://www.sitocomune.com/
http://www.alessandrobaraldi.it
---------------------------------------------------------------------------
Thorsten Albers - 23 Sep 2007 00:13 GMT
ALESSANDRO Baraldi <ik2zok@libero.it> schrieb im Beitrag
<e8KxuxT$HHA.1168@TK2MSFTNGP02.phx.gbl>...
> Mmm...
> I usually read documentation don't warry, if i write it's only because i
> can't understand, so
> i ask any suggestion can help me...!
Sorry, it was my fault: I didn't pay attention to "gradient"...

Signature
----------------------------------------------------------------------
THORSTEN ALBERS Universität Freiburg
albers@
uni-freiburg.de
----------------------------------------------------------------------
> I draw a RoundRect with red brush, inside this one i need to fill with
> a gradient color...!
[quoted text clipped - 4 lines]
>
> I have not any idea.
In GDI you'd need to use a clipping region to accomplish this, here's a demo:
'***
Private Declare Function CreateRoundRectRgn Lib "GDI32.dll" ( _
ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, _
ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
Private Declare Function SelectClipRgn Lib "GDI32.dll" ( _
ByVal hDC As Long, ByVal hRgn As Long) As Long
Private Declare Function GetClientRect Lib "User32.dll" ( _
ByVal hWnd As Long, ByRef lpRect As RectAPI) As Long
Private Declare Function InflateRect Lib "User32.dll" ( _
ByRef lpRect As RectAPI, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function DeleteObject Lib "GDI32.dll" (ByVal hObject As Long) As Long
Private Declare Function RoundRect Lib "GDI32.dll" ( _
ByVal hDC As Long, ByVal X1 As Long, ByVal Y1 As Long, _
ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
Private Declare Function CreatePen Lib "GDI32.dll" ( _
ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
Private Declare Function GetStockObject Lib "GDI32.dll" (ByVal nIndex As Long) As Long
Private Declare Function SelectObject Lib "GDI32.dll" ( _
ByVal hDC As Long, ByVal hObject As Long) As Long
Private Type RectAPI
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Const PS_SOLID As Long = &H0
Private Const NULL_BRUSH As Long = &H5
Private Sub Form_Paint()
Dim ClientArea As RectAPI
Dim hClipRgn As Long
Dim hPen As Long, hOldPen As Long
Dim hDC As Long
Const CornerSize As Long = 32
hDC = Me.hDC
' Get the form's size and shrink by 5 pixels
Call GetClientRect(Me.hwnd, ClientArea)
Call InflateRect(ClientArea, -5, -5)
' Create and selection clipping region for fill
hClipRgn = CreateRoundRectRgn(ClientArea.Left, ClientArea.Top, _
ClientArea.Right + 1, ClientArea.Bottom + 1, CornerSize, CornerSize)
Call SelectClipRgn(hDC, hClipRgn)
' Draw gradient fill
Call DrawRectGrad(hDC, _
NewTriVertex(ClientArea.Left, ClientArea.Top, vb3DHighlight), _
NewTriVertex(ClientArea.Right, ClientArea.Bottom, vb3DShadow), False)
' Deselect and destroy clipping region
Call SelectClipRgn(hDC, 0&)
Call DeleteObject(hClipRgn)
' Draw border
hPen = CreatePen(PS_SOLID, 0, vbBlack)
hOldPen = SelectObject(hDC, hPen)
Call RoundRect(hDC, ClientArea.Left, ClientArea.Top, _
ClientArea.Right, ClientArea.Bottom, CornerSize, CornerSize)
Call SelectObject(hDC, hOldPen)
Call DeleteObject(hPen)
End Sub
Private Sub Form_Resize()
' Re-paint on resize, ugly, but ok for demo
Call Me.Refresh
End Sub
'***
I'm using my gradient drawing library (available on my site if you're feeling lazy too!) for this demo to save some
declarations and filling out the TRIVERTEX structures, but you can easily replace this in your own code with a
GradientFill() which it uses internally anyway.
If you're not happy with this implementation then if GDI+ is an option to you or if you're already using it in your
project then you can use a LinearGradientBrush to perform the fill. Rounded rectangles are not natively supported by
the library (for some reason??), however you can use a GraphicsPath and a series of Arc's to create the profile that way
then FillPath/DrawPath to draw it.
Hope this helps,
Mike
- Microsoft Visual Basic MVP -
E-Mail: EDais@mvps.org
WWW: Http://EDais.mvps.org/
ALESSANDRO Baraldi - 23 Sep 2007 00:34 GMT
> I'm using my gradient drawing library (available on my site if you're feeling lazy too!) for this demo to save some
> declarations and filling out the TRIVERTEX structures, but you can easily replace this in your own code with a
[quoted text clipped - 6 lines]
>
> Mike
Perfect with your Library.
Thanks Mike

Signature
@Alex (Alessandro Baraldi)
---------------------------------------------------------------------------
http://www.sitocomune.com/
http://www.alessandrobaraldi.it
---------------------------------------------------------------------------