CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 1999
    Posts
    2

    Windows GDI Bug ?

    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



  2. #2
    Join Date
    Apr 1999
    Location
    INDIA
    Posts
    4

    Re: Windows GDI Bug ?

    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.



  3. #3
    Join Date
    Apr 1999
    Posts
    53

    Re: Windows GDI Bug ?

    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


  4. #4
    Join Date
    Apr 1999
    Posts
    53

    Re: Windows GDI Bug ?

    P.S. --

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


  5. #5
    Join Date
    Jun 1999
    Posts
    2

    Re: Windows GDI Bug ?

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured