FIX: Hatch Marks in MFC DRAWCLI Print Preview

ID: Q123162


The information in this article applies to:


SYMPTOMS

Although hatching should never appear when using a print DC, under the conditions outlined in the "Steps to Reproduce Problem" section of this article, the active embedded item is represented with hatch marks across it in the print preview.


CAUSE

This is a bug in the DRAWCLI sample. The function CDrawOleObj::Draw draws the hatch marks across the item. The Draw function should check to see whether or not the DC passed to is a printer DC or a screen DC. Then based on the type of DC, the sample should either draw or not draw hatch marks. Presently, any item that is currently open (active) has hatching drawn across it regardless of the type of DC.


RESOLUTION

The code to draw the rectangle tracker and the hatching over the item begins on line 1024 of DRAWOBJ.CPP. It can be found in the MSVC\MFC\SAMPLES\DRAWCLI directory. The code is the following:


   // use a CRectTracker to draw the standard effects
   CRectTracker tracker;
   tracker.m_rect = m_position;
   pDC->LPtoDP(tracker.m_rect);
   if (c_bShowItems)
   {
      // put correct border depending on item type
      if (pItem->GetType() == OT_LINK)
        tracker.m_nStyle |= CRectTracker::dottedLine;
      else
        tracker.m_nStyle |= CRectTracker::solidLine;
   }
   // put hatching over the item if it is currently open
   if (pItem->GetItemState() == COleClientItem::openState ||
   pItem->GetItemState() == COleClientItem::activeUIState)
   {
      tracker.m_nStyle |= CRectTracker::hatchInside;
   }
   tracker.Draw(pDC); 
Change the code to this:

// don't draw tracker in print preview or on printer
if (!pDC->IsPrinting())
{
   // use a CRectTracker to draw the standard effects
   CRectTracker tracker;
   tracker.m_rect = m_position;
   pDC->LPtoDP(tracker.m_rect);
   if (c_bShowItems)
   {
      // put correct border depending on item type
      if (pItem->GetType() == OT_LINK)
        tracker.m_nStyle |= CRectTracker::dottedLine;
      else
        tracker.m_nStyle |= CRectTracker::solidLine;
   }
   // put hatching over the item if it is currently open
   if (pItem->GetItemState() == COleClientItem::openState ||
   pItem->GetItemState() == COleClientItem::activeUIState)
   {
      tracker.m_nStyle |= CRectTracker::hatchInside;
   }
   tracker.Draw(pDC);
} 


STATUS

Microsoft has confirmed this to be a bug in the products listed at the beginning of this article. This bug was corrected in The Microsoft Foundation Classes, version 2.51, included with Visual C++ version 1.51.


MORE INFORMATION

Steps to Reproduce Problem

  1. Run the DRAWCLI sample (MSVC\MFC\SAMPLE\DRAWCLI\DRAWCLI.EXE).


  2. Choose Insert New Object from the Edit menu.


  3. Insert a new object in the Drawcli application.


  4. Choose Print Preview from the File menu, or choose Print from the File menu.


Additional query words: 1.50 2.50


Keywords          : kbole kb16bitonly kbMFC kbPrinting kbVC CodeSam 
Version           : 1.50
Platform          : WINDOWS 
Issue type        : 

Last Reviewed: July 21, 1999