Click to See Complete Forum and Search --> : FillRgn with CreateEllipticRgn
Rabby
Jun 11th, 2001, 04:17 PM
I am trying to create a filled ellipse with an image of my choice I would like the image to fill the ellipse completely, however, the image appears to tile and leaves a gap between the image and the ellipse region - is this for the hidden titlebar and if so how can I remove it.
h_brush = CreatePatternBrush(pic1.Image)
hRgn = SelectObject(Me.hdc, h_brush)
hRgn = CreateEllipticRgn(30,30, 90, 90)
FillRgn Me.hdc, hRgn, h_brush
SetWindowRgn Me.hWnd, hRgn, 1
Cheers
Rab.
Frans C
Jun 12th, 2001, 01:55 AM
If you set the borderstyle to none, it will fill the entire region. To avoid the tiling, the image has to be big enough to fill the region.
Frans C
Jun 12th, 2001, 02:06 AM
By the way,
Your code will be leaking GDI handles.
You need to select the original brush into the DC when done, and delete the objects you created.
Dim hRgn As Long
Dim hOldBrush As Long
Dim h_brush As Long
Dim retVal As Long
h_brush = CreatePatternBrush(Picture1.Image)
hOldBrush = SelectObject(Me.hdc, h_brush)
hRgn = CreateEllipticRgn(30, 30, 90, 90)
FillRgn Me.hdc, hRgn, h_brush
SetWindowRgn Me.hWnd, hRgn, 1
' select the oginal brush back into the dc
h_brush = SelectObject(Me.hdc, hOldBrush)
' delete the brush
retVal = DeleteObject(h_brush)
' delete the region
retVal = DeleteObject(hRgn)
Frans C
Jun 12th, 2001, 02:21 AM
Sorry, but the thing I said about the tiling is not correct.
I think it has to do with the use of brushes.
You could use BitBlt instead.
Dim hRgn As Long
Dim retVal As Long
hRgn = CreateEllipticRgn(30, 30, 90, 90)
SetWindowRgn Me.hWnd, hRgn, 1
retVal = BitBlt(Me.hdc, 0, 0, Me.Width, Me.Height, Picture1.hdc, 0, 0, SRCCOPY)
retVal = DeleteObject(hRgn)
Rabby
Jun 12th, 2001, 03:22 PM
The bitblt code works great Fran, thanx. I had forgotten about that api with all the reading about FillRgn.
I have now encountered another problem as a result of the bitblt- I would like to add labels and controls at runtime but when I run the code the labels that I have tried it with are not visible. When I add a label at design time I can see the control but this is not feasible due to the nature of the form.
Your thoughts will be greatly appreciated.
Rab.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.