void CFirstPage::OnPaint()
{
CPaintDC dc(this); // device context for painting
////////////画笔定义
Pen pen(Color(0xFF2E8B57));
Pen penY(Color(0xFFFFFF00),2.0);
Pen penR(Color(0xFF7CFC00),1.0);
Pen penG(Color(0xFF696969),2.0);
SolidBrush brush(Color(255,0,0,0));
//Monthly Display
////////月显示/////////////////
Graphics graphics(this->GetDC()->m_hDC);
CRect rect;
GetDlgItem(IDC_STATIC_M)->GetWindowRect(&rect);
ScreenToClient(&rect);//IMPORTANT
Bitmap bmp1(rect.right,rect.bottom);
Graphics* graph = Graphics::FromImage(&bmp1);
graph->FillRectangle(&brush,rect.TopLeft().x+10,rect.TopLeft().y+20,rect.Width()-20,rect.Height()-30);
//edge
graph->DrawLine(&penG,PointF(rect.TopLeft().x+10,rect.TopLeft().y+20),
PointF(rect.TopLeft().x+10+rect.Width()-20,rect.TopLeft().y+20));
graph->DrawLine(&penG,PointF(rect.TopLeft().x+10+rect.Width()-20,rect.TopLeft().y+20+rect.Height()-30),
PointF(rect.TopLeft().x+10+rect.Width()-20,rect.TopLeft().y+20));
graph->DrawLine(&penG,PointF(rect.TopLeft().x+10+rect.Width()-20,rect.TopLeft().y+20+rect.Height()-30),
PointF(rect.TopLeft().x+10,rect.TopLeft().y+20+rect.Height()-30));
graph->DrawLine(&penG,PointF(rect.TopLeft().x+10,rect.TopLeft().y+20),
PointF(rect.TopLeft().x+10,rect.TopLeft().y+20+rect.Height()-30));
//5*31points drawing grids
for(int i=1;i<7;i++)
{
graph->DrawLine(&pen,PointF(rect.TopLeft().x+80,rect.TopLeft().y+20+(rect.Height()-30)*i/7),
PointF(rect.TopLeft().x-10+rect.Width(),rect.TopLeft().y+20+(rect.Height()-30)*i/7));
}
//vertical line
//yellow line
graph->DrawLine(&penY,PointF(rect.TopLeft().x+80,rect.TopLeft().y+20),
PointF(rect.TopLeft().x+80,rect.TopLeft().y+rect.Height()-10));
//others
for(int i=1;i<31;i++)
{
graph->DrawLine(&pen,PointF(rect.TopLeft().x+80+(rect.Width()-90)*i/31,rect.TopLeft().y+20),
PointF(rect.TopLeft().x+80+(rect.Width()-90)*i/31,rect.TopLeft().y+rect.Height()-10));
}
graphics.DrawImage(&bmp1,rect.left-8,rect.top-8,rect.right-8,rect.bottom-8);
/////////////////////////////Daily Dispaly//////////////////////////////
/////////////////////////////每天显示///////////////////////////////
GetDlgItem(IDC_STATIC_D)->GetWindowRect(&rect);
ScreenToClient(&rect);
/////////////////DOUBLEBUFFER
Bitmap bmp(rect.right,rect.bottom);
graph = Graphics::FromImage(&bmp);
///////////////black backgound///////////////黑色背景
graph->FillRectangle(&brush,rect.TopLeft().x+10,rect.TopLeft().y+20,rect.Width()-20,rect.Height()-30);
////////////grey  edge//////////////灰色边缘
graph->DrawLine(&penG,PointF(rect.TopLeft().x+10,rect.TopLeft().y+20),
PointF(rect.TopLeft().x+10+rect.Width()-20,rect.TopLeft().y+20));
graph->DrawLine(&penG,PointF(rect.TopLeft().x+10+rect.Width()-20,rect.TopLeft().y+20+rect.Height()-30),
PointF(rect.TopLeft().x+10+rect.Width()-20,rect.TopLeft().y+20));
graph->DrawLine(&penG,PointF(rect.TopLeft().x+10+rect.Width()-20,rect.TopLeft().y+20+rect.Height()-30),
PointF(rect.TopLeft().x+10,rect.TopLeft().y+20+rect.Height()-30));
graph->DrawLine(&penG,PointF(rect.TopLeft().x+10,rect.TopLeft().y+20),
PointF(rect.TopLeft().x+10,rect.TopLeft().y+20+rect.Height()-30));
////////////////5*23points drawing grids/////////////////格子
/////////////水平方向7条
for(int i=1;i<7;i++)
{
graph->DrawLine(&pen,PointF(rect.TopLeft().x+80,rect.TopLeft().y+20+(rect.Height()-30)*i/7),
PointF(rect.TopLeft().x-10+rect.Width(),rect.TopLeft().y+20+(rect.Height()-30)*i/7));
}
//vertical lines
/////////竖直方向24条/////////////////////
//Yellow line
graph->DrawLine(&penY,PointF(rect.TopLeft().x+80,rect.TopLeft().y+20),
PointF(rect.TopLeft().x+80,rect.TopLeft().y+rect.Height()-10));
//others
for(int i=1;i<24;i++)
{
graph->DrawLine(&pen,PointF(rect.TopLeft().x+80+(rect.Width()-90)*i/24,rect.TopLeft().y+20),
PointF(rect.TopLeft().x+80+(rect.Width()-90)*i/24,rect.TopLeft().y+rect.Height()-10));
}
CTime ctime=CTime::GetCurrentTime();
m_Rset.MoveFirst();
/////////////Find the beginning data.
while((m_Rset.m_tDatetime.GetYear()!=ctime.GetYear()||
m_Rset.m_tDatetime.GetMonth()!=ctime.GetMonth()||
m_Rset.m_tDatetime.GetDay()!=ctime.GetDay()))
{
m_Rset.MoveNext();
if(m_Rset.IsEOF())
{
m_Rset.MoveLast();
break;
}
}
int nItemNum = this->m_ListTable.GetItemCount () ;
CString stemp="";
stemp.Format(L"%lf",m_Rset.m_tTpture);
this->m_ListTable.InsertItem(nItemNum,stemp);
this->m_ListTable.SetItemText(nItemNum,1,(CString)m_Rset.m_tLocation);
stemp.Format(L"%d-%d-%d-%d:%d:%d",m_Rset.m_tDatetime.GetYear(),m_Rset.m_tDatetime.GetMonth(),
m_Rset.m_tDatetime.GetDay(),m_Rset.m_tDatetime.GetHour(),m_Rset.m_tDatetime.GetMinute(),
m_Rset.m_tDatetime.GetSecond());
this->m_ListTable.SetItemText(nItemNum,2,stemp);
m_pointF1.X=m_Rset.ttoi(m_Rset.m_tDatetime,rect.TopLeft().x,rect.Width());
m_pointF1.Y=m_Rset.htoi(m_Rset.m_tTpture,rect.TopLeft().y,rect.Height());
m_Rset.MoveNext();
while(!m_Rset.IsEOF())
{
m_pointF2.X=m_Rset.ttoi(m_Rset.m_tDatetime,rect.TopLeft().x,rect.Width());
m_pointF2.Y=m_Rset.htoi(m_Rset.m_tTpture,rect.TopLeft().y,rect.Height());
int nItemNum = this->m_ListTable.GetItemCount () ;
stemp.Format(L"%lf",m_Rset.m_tTpture);
this->m_ListTable.InsertItem(nItemNum ,stemp);
this->m_ListTable.SetItemText(nItemNum ,1,(CString)m_Rset.m_tLocation);
stemp.Format(L"%d-%d-%d-%d:%d:%d",m_Rset.m_tDatetime.GetYear(),m_Rset.m_tDatetime.GetMonth(),
m_Rset.m_tDatetime.GetDay(),m_Rset.m_tDatetime.GetHour(),m_Rset.m_tDatetime.GetMinute(),
m_Rset.m_tDatetime.GetSecond());
this->m_ListTable.SetItemText(nItemNum ,2,stemp);
m_ListTable.EnsureVisible(m_ListTable.GetItemCount()-1,FALSE);
PointF points[2]={m_pointF1,m_pointF2};
graph->DrawCurve(&penR,points,2,0.6);
m_pointF1=m_pointF2;
m_Rset.MoveNext();
}
m_Rset.MoveLast();
graphics.DrawImage(&bmp,rect.left-8,rect.top-8,rect.right-8,rect.bottom-8);
}
OnPaint函数里画个两个区域,上面部分代码画的区域出现了很大的偏差,下面部分代码的区域正常。
单步调试出两个Rect值也都是正常的。