Click to See Complete Forum and Search --> : Technique for determining Bounding Rect


rliq
March 29th, 2005, 03:02 AM
Given that I have a CPen of thickness m_nThickness and have already selected it to the Device Context. What is the technique for finding the EXACT bounding Rectangle painted when I do a...

pDC->Rectangle( s_rect );

I have tried using the s_rect, tried inflating it (based on m_nThickness) etc etc, but there always seems to be a scenario where I lose one pixel along an edge or two or three or four.

I am painting many things front to back (to avoid flicker when the window is being resized) and need to detmine the EXACT rectangle to remove from the Update Region.

Or does somebody have another technique all together? Is a technique to paint from back to front (because I can already do this perfectly) on a CompatibleDC and then Blit it over the main one?

Thanks

Leo77
March 29th, 2005, 11:55 AM
I really didnt understand any of your commands (really didnt have a clue), but I suppose that if you want to create a bounding rectangle, you have several pionts/vertex as data. If so, its really easy: Get the pionts/vertex coords., select the biggest X and Y coord. and the smallest X and Y. Your rect is (smallX, smallY), (smallX, bigY) (bigX, bigY) (bigX, smallY).

rliq
March 29th, 2005, 05:15 PM
I need the bounding (actual) rectangle that Windows uses when it draws a Rectangle of size s_rect with a Pen thickness of X....
CRect MyClass::s_rect;
...
void MyView::OnDraw( CDC pDC* )
{
....
// Code to create CPen of thickness X and SelectObject() to the CDC
// Code to initialise s_rect
....
pDC->Rectangle( s_rect );
....
}It's not s_rect itself, as when the CPen thickness is > 1, some of the drawing Windows does, is OUTSIDE of the s_rect object's left/top/right/bottom coordinates.

I've tried s_rect.InflateRect( X, X ) and s_rect.InflateRect( X/2, X/2 ). None of which seem to be exactly what windows used (in all cases).

Can I get the EXACT Bounding Rectangle that Windows used?

Thanks