|
我的代码如下:,但一屏时能很正常的显示,到了第二屏就画不出来了
//用于刷新控件显示
void main::InvalidateCtrl()
{
CPen *oldPen;
m_crBackColor=RGB(255,255,255); //控件背景色
m_crTextColor= RGB(122,122,122); //字体颜色
CPen solidPen(PS_SOLID,0,RGB(111,111,111));
CFont xFont,yFont,*oldFont;
CBrush brushBack;
brushBack.CreateSolidBrush(m_crBackColor);
CRect rectClient;
GetClientRect(rectClient);
CClientDC dc(GetDlgItem(IDC_LIST2));
CString str=_T("X坐标");
//创建表格设备环境以及创建相应缓冲区
if (m_tmpDC.GetSafeHdc() == NULL)
{
m_tmpDC.CreateCompatibleDC(&dc);
m_tmpBmp.CreateCompatibleBitmap(&dc,rectClient.Width()+mm*60,rectClient.Height());
m_tmpDC.SelectObject(&m_tmpBmp);
}
//设置背景颜色
m_tmpDC.SetBkColor(m_crBackColor);
m_tmpDC.FillRect(rectClient,&brushBack);
//创建画线设备环境以及创建相应缓冲区
if (m_tmpDCBlock.GetSafeHdc() == NULL)
{
m_tmpDCBlock.CreateCompatibleDC(&dc) ;
m_tmpBmpBlock.CreateCompatibleBitmap(&dc, rectClient.Width()+mm*60, rectClient.Height()) ;
m_tmpDCBlock.SelectObject(&m_tmpBmpBlock) ;
}
m_tmpDCBlock.SetBkColor (m_crBackColor) ;
m_tmpDCBlock.FillRect(rectClient, &brushBack);
CPen newPen(PS_SOLID,1.5,RGB(100,100,100));
// CBrush newBrush(RGB(100,200,0));
CString emp;
pOldPen = m_tmpDCBlock.SelectObject(&newPen);
m_tmpDCBlock.MoveTo(22, 5);
m_tmpDCBlock.LineTo(22, 210);
m_tmpDCBlock.LineTo(635+mm*60,210);
m_tmpDCBlock.SetTextColor(m_crTextColor);
for(int i=1;i<=10;i++)
{
m_tmpDCBlock.MoveTo(22, 20*i-5);
m_tmpDCBlock.LineTo(27,20*i-5);
emp.Format(_T("%d"),i*10);
m_tmpDCBlock.ExtTextOut(1,210-20*i,ETO_CLIPPED,NULL,emp,wcslen(emp),NULL);
}
for(int j=1;j<=10+mm;j++)
{
m_tmpDCBlock.MoveTo(22+60*j, 210);
m_tmpDCBlock.LineTo(22+60*j,205);
emp.Format(_T("%d"),j*2);
emp=emp+" "+"M";
m_tmpDCBlock.ExtTextOut(10+60*j,211,ETO_CLIPPED,NULL,emp,wcslen(emp),NULL);
}
/* 画下面的那三条直线 */
CPen newPen1(PS_SOLID,2,RGB(251,0,250));
CPen newPenBlock(PS_SOLID,2,RGB(56,104,169));
CPen newPenSample(PS_SOLID,2,RGB(136,253,57));
pOldPen = m_tmpDCBlock.SelectObject(&newPen1);
m_tmpDCBlock.MoveTo(40, 230);
m_tmpDCBlock.LineTo(80,230);
m_tmpDCBlock.SelectObject(pOldPen);
m_tmpDCBlock.ExtTextOut(50,235,ETO_CLIPPED,NULL,_T("Lid"),3,NULL);
pOldPenBlock = m_tmpDCBlock.SelectObject(&newPenBlock);
m_tmpDCBlock.MoveTo(90, 230);
m_tmpDCBlock.LineTo(130,230);
m_tmpDCBlock.SelectObject(pOldPenBlock);
m_tmpDCBlock.ExtTextOut(100,235,ETO_CLIPPED,NULL,_T("Block"),5,NULL);
pOldPenBlock = m_tmpDCBlock.SelectObject(&newPenSample);
m_tmpDCBlock.MoveTo(140, 230);
m_tmpDCBlock.LineTo(180,230);
m_tmpDCBlock.SelectObject(pOldPenSample);
m_tmpDCBlock.ExtTextOut(150,235,ETO_CLIPPED,NULL,_T("Sample"),6,NULL);
m_tmpDCBlock.SelectObject(pOldPen );
// m_oldDCBlock.BitBlt(0, 0, rectClient.Width(), rectClient.Height(),
// &m_tmpDCBlock, 0, 0, SRCCOPY) ;
newPen.DeleteObject();
//删除创建的GDI对象
solidPen.DeleteObject();
newPen1.DeleteObject();
newPenSample.DeleteObject();
newPenBlock.DeleteObject();
xFont.DeleteObject();
yFont.DeleteObject();
brushBack.DeleteObject();
}
|
|