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
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