Click to See Complete Forum and Search --> : Windows GDI Bug ?


Vasu Sheshadri
June 3rd, 1999, 01:55 PM
Hello,

I have just discovered a strange behaviour in Windows GDI.
Check the following code.

This code draws a RED rectangle in the view. The coordinates of
the rectangle is given in the
'boundRect' variable. If the boundRect rectangle is (0,0,373,301)
then this code draws the rectangle properly.
If the boundRect is (3,3,373,301) then it DOES NOT draw the
rectangle at all!!! I am sure that there are many other
rectangles that DO NOT work. I have tested this behaviour in Windows 95 and Windows 98.

Try it youself. Create a new SDI(Single Document Interface)
project in Visual C++ appwizard and replace the OnDraw(()
function in the CView derived class in your project. Try the two
rectangles menstioned above.

By the way, how do get rid of this problem ? Is it a bug in GDI ?
Am i using it improperly ?

Please let me know if you have any ideas.

..................................
void CBltbugView::OnDraw(CDC* pDC)
{
CBltbugDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

//Get the size of the rectangle;

//DOES NOT WORK
//CRect boundRect(3,3,373,301);

//DOES WORK
CRect boundRect(0,0,373,301);

//create memory DC
CBitmap bmp, *bmpPtr;
bmp.CreateCompatibleBitmap(pDC, boundRect.Width(),
boundRect.Height());
CDC memDC; memDC.CreateCompatibleDC(NULL);
bmpPtr = memDC.SelectObject(&bmp);

//set map mode to MM_LOENGLISH
int oldmapmode = pDC->SetMapMode(MM_LOENGLISH);
memDC.SetMapMode(MM_LOENGLISH);

memDC.DPtoLP(&boundRect);
boundRect.NormalizeRect();

CBrush brush; brush.CreateSolidBrush(RGB(255,0,0));
// color wash the surface
memDC.FillRect(CRect(0,0,boundRect.Width(),-boundRect.Height
()), &brush);

//copy from memory DC to display DC
pDC->BitBlt(2, -2, boundRect.Width(), -boundRect.Height(),
&memDC, 0, 0, SRCCOPY);

memDC.SelectObject(bmpPtr);
pDC->SetMapMode(oldmapmode);
}


-Vasu

sharad
June 4th, 1999, 01:36 PM
You are right about the bug. Strange enough it works perfect on NT. However the problem might be with the folowing calls -
memDC.DPtoLP(&boundRect);
boundRect.NormalizeRect();
I just commented these and it worked fine. The 16 bit GDI code on 95 and 98 might be creating this problem.

Wes Rogers
June 4th, 1999, 03:11 PM
Hi,

You need to call NormalizeRect() before you can use Width() and Height() reliably -- they just happen to work out OK if the upper left coords are 0,0.

Yours,
Wes Rogers

Wes Rogers
June 4th, 1999, 03:15 PM
P.S. --

Call NormalizeRect() right away, before you call CreateCompatibleBitmap().

Vasu Sheshadri
June 4th, 1999, 05:17 PM
The boundRect(0,0,373,301); is already in the normalized state. So calling NormalizeRect() as you have mentioned does not help. I tryed it in my code and it dint work.

-vasu