Solved

FrameRgn Issue in Form.Paint

Posted on 2008-10-28
7
811 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
  • 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 250 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now