CDC描画

来源:互联网 发布:java remainder 编辑:程序博客网 时间:2024/04/28 09:29

void CXXXestDlg::OnPaint()
{
 if (IsIconic())
 {
  CPaintDC dc(this); // device context for painting

  SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

  // Center icon in client rectangle
  int cxIcon = GetSystemMetrics(SM_CXICON);
  int cyIcon = GetSystemMetrics(SM_CYICON);
  CRect rect;
  GetClientRect(&rect);
  int x = (rect.Width() - cxIcon + 1) / 2;
  int y = (rect.Height() - cyIcon + 1) / 2;

  // Draw the icon
  dc.DrawIcon(x, y, m_hIcon);
 }
 else
 {
  CPaintDC dc(this); // device context for painting
//  CWindowDC dc(GetDesktopWindow());

  vector<Line_t> vecLine;
  Link2Node( vecLine );
  
  for (vector<Line_t>::iterator iter = vecLine.begin(); iter != vecLine.end(); ++ iter )
  {

    CPen pen(PS_SOLID,1,RGB(iter->a.x%255,iter->a.y%255,iter->b.x%255));
    dc.SelectObject( &pen );
    
    char buff[10];
    ltoa(distance(vecLine.begin(),iter)+1,buff,10);
    CString cs = buff;
    
    dc.DrawText(cs,
       CRect(iter->a,iter->b),
       DT_SINGLELINE|DT_CENTER|DT_VCENTER);
    
    dc.MoveTo( iter->a );
    dc.LineTo( iter->b );
   
  }

  
  
//  CDialog::OnPaint();
 }
}

原创粉丝点击