Results 1 to 5 of 5

Thread: FillRgn with CreateEllipticRgn

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    14

    FillRgn with CreateEllipticRgn

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

  2. #2
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    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.

  3. #3
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    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)

  4. #4
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    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)

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    14
    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.
    Rab.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width