Solved

FrameRgn Issue in Form.Paint

Posted on 2008-10-28
7
822 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
Graphics32 under Delphi 10.1 Berlin 2 105
Copy output image from TWindowsMediaPlayer 6 48
Tidtcpserver listening on multiports? 1 35
firemonkey Android Listview Sort items 7 53
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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.

830 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