Example #1
0
void CChildView::OnPaint() 
{
  CPaintDC *dc;
  CDC *pdc;
  CRgn ur;
  ur.CreateRectRgn(0, 0, 0, 0);
  GetUpdateRgn(&ur);

  CRect cr;
  GetClientRect(&cr);
  if (theApp.m_bStarted && !theApp.m_map.IsEmpty()) {
//    pdc = &dc;
    m_MemDC.SelectClipRgn(&ur);
    pdc = &m_MemDC;

    theApp.m_map.DrawMap(*pdc, &cr, &ur);

    CRect r;
//    r = cr;
    ur.GetRgnBox(r);
//    r.InflateRect(1, 1);
    if (r.left < 0)
      r.left = 0;
    if (r.top < 0)
      r.top = 0;
  	dc = new CPaintDC(this); // device context for painting
    dc->BitBlt(r.left, r.top, r.Width(), r.Height(), &m_MemDC, r.left, r.top, SRCCOPY);
  }
  else {
  	dc = new CPaintDC(this); // device context for painting
    if (theApp.m_bStarted) {
      dc->SetTextAlign(TA_CENTER);
      CPoint cp = cr.CenterPoint();
      CString s;
      s.Format("There are no maps in '%s'", theApp.m_map.m_sMapsPath);
      dc->ExtTextOut(cp.x, cp.y - dc->GetOutputTextExtent("W").cy/2, ETO_OPAQUE, &cr, s, NULL);
    }
    else {
      dc->FillSolidRect(cr, 0);
    }
  }
  delete dc;
}
Example #2
0
void CMainWindow::OnPaint ()
{
    CPaintDC dc (this);
    
    //
    // Initialize the device context.
    //
    dc.SetMapMode (MM_LOENGLISH);
    dc.SetTextAlign (TA_CENTER | TA_BOTTOM);
    dc.SetBkMode (TRANSPARENT);

    //
    // Draw the body of the ruler.
    //
    CBrush brush (RGB (255, 255, 0));
    CBrush* pOldBrush = dc.SelectObject (&brush);
    dc.Rectangle (100, -100, 1300, -200);
    dc.SelectObject (pOldBrush);

    //
    // Draw the tick marks and labels.
    //
    for (int i=125; i<1300; i+=25) {
        dc.MoveTo (i, -192);
        dc.LineTo (i, -200);
    }

    for (i=150; i<1300; i+=50) {
        dc.MoveTo (i, -184);
        dc.LineTo (i, -200);
    }

    for (i=200; i<1300; i+=100) {
        dc.MoveTo (i, -175);
        dc.LineTo (i, -200);

        CString string;
        string.Format (_T ("%d"), (i / 100) - 1);
        dc.TextOut (i, -175, string);
    }
}