Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

FrameRgn Issue in Form.Paint

Posted on 2008-10-28
7
Medium Priority
?
830 Views
Last Modified: 2013-11-22
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
Comment
Question by:rogitor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 49

Expert Comment

by:DanRollins
ID: 22836234
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
 

Author Comment

by:rogitor
ID: 22848825
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
 
LVL 49

Accepted Solution

by:
DanRollins earned 1000 total points
ID: 22853190
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:rogitor
ID: 22896638
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 22900158
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
 

Author Comment

by:rogitor
ID: 22942946
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
 

Author Comment

by:rogitor
ID: 23042008
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question