Solved

FrameRgn Issue in Form.Paint

Posted on 2008-10-28
7
826 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 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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 technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses
Course of the Month6 days, 3 hours left to enroll

627 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