Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 834
  • Last Modified:

FrameRgn Issue in Form.Paint

Hi,

C++ Builder 2009

I have created a round-ish form using CreateRoundRectRgn, which works well, but I am having difficulty drawing a frame around the new shape.  The attached code compiles and seems to run fine...except that it doesn't draw the frame.  The return code from FrameRgn is non-negative, indicating success.  I have tried different types of brushes, different parameters, different canvas handles, and still no frame is being drawn.  Frustrating!  

In further testing I have also attempted to flood the form using FillRgn, but nothing is drawn even though the return code is also success.

I have spent far too much time on this, and am becoming extremely frustrated!  Any and all suggestions are greatly appreciated.

Thanks

void __fastcall TfrmMain::FormPaint(TObject *Sender)
{
	RECT rect = GetClientRect();
	HRGN hRgn = CreateRoundRectRgn(1, 1, rect.right, rect.bottom, 50, 50);
 	SetWindowRgn (Handle, hRgn, TRUE);
 
	hRgn = CreateRoundRectRgn(0, 1, rect.right, rect.bottom, 50, 50);
	FrameRgn(Canvas->Handle, hRgn, GetStockObject(BLACK_BRUSH), 3, 3);
	DeleteObject(hRgn); 
}

Open in new window

0
rogitor
Asked:
rogitor
  • 4
  • 3
1 Solution
 
DanRollinsCommented:
As an experiment, make the drawing region smaller by several pixels in each direction.  My hunch is that FrameRgn is trying to draw on the outside of the region, but the Window region is the same size, so the drawing it gets clipped.
0
 
rogitorAuthor Commented:
Unfortunately, modifying the region parameters didn't change anything.  I modified the parameters to various subsets contained within the full window, and tried different brushes, but still couldn't get anything to draw.  I'm not sure why nothing will draw, is Paint() the right place for this?  Or, could it be that the vcl components are refreshing after I draw my lines?

Thanks for the suggestion, I will keep digging and update my findings here.
0
 
DanRollinsCommented:
Indeed,  Paint() is the wrong place to change the shape of the window.  Do it when you create the window.
Also, try InvalidateRect() just before calling FrameRgn to make sure that the the output will not be clipped.
And just to be very clear, I'm suggesting that you change (shrink) the region used in the second part (not the one that defines the shape of th window, but the one that is used in the drawing function).
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rogitorAuthor Commented:
I still can't seem to draw the frame. :(

I have changed the Rgn for drawing the frame to 10, 10, 100, 100 but I still can't get anything to show up.  I will play a little more with the brush, regions, framerect, and maybe even try a new control.  Thanks for your patience.
0
 
DanRollinsCommented:
Another thing to do is just get any GDI drawing to happen.  For instance, if you can draw a diagonal line using the LineTo() API or output some text with TextOut(), then you know you are on the right track.  
Until then we don't know if the problem is with the call for FrameRgn (and its parameters) or with drawing in general.
0
 
rogitorAuthor Commented:
I was called out of town for the week, just didn't want you to think that I forgot about you.  ;)

See you next week!
0
 
rogitorAuthor Commented:
I finally gave up and created a new project, which not works as expected.  Something must have been corrupted.  Thanks for you help!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now