OnDraw 文字如何重绘 打开提取文本时,文本框不显示文字,但只要手动去拉动放大缩小文本框,就会显示
加了Invalidate()后    就会不断的闪烁   求教~
void CReadboView::OnDraw(CDC* pDC)
{
 CReadboDoc* pDoc = GetDocument();
 ASSERT_VALID(pDoc);
 CRect cr;
 // TODO: add draw code for native data here
 CString str1;
 CMainFrame *ph = (CMainFrame *) AfxGetMainWnd();
 CString fileName = ph->filename;
 static int i=1;
 if(fileName!="")
 {
 FILE *pFile=fopen(fileName,"r");
 //MessageBox("fuck");
 GetClientRect( &cr );
 int seekf = ( cr.bottom - cr.top ) * ( cr.right - cr.left ) ;
 char *pBuf;
 fseek(pFile,0,SEEK_END);
 int len=ftell(pFile);
 if ( len < seekf ) seekf = len;
 pBuf=new char[len+1];
 rewind(pFile);
 fread(pBuf,1,155,pFile);
 pBuf[155]=0;
 //CString str ; 
 //str.Format("%d",cr.right);
 //MessageBox(str);
 //pDC->BeginPath();
// Invalidate(FALSE);
 pDC->DrawText(pBuf,CRect(0,0,cr.right,cr.bottom),DT_WORDBREAK );
 //pDC->EndPath();
 UpdateData(FALSE);
 /*((CReadboView)(AfxGetMainWnd()->GetActiveView()))->*/
 //UpdateWindow();
// fclose(pFile);
 }
}新手一个   可以的话 详细点  谢谢~

解决方案 »

  1.   

    http://social.msdn.microsoft.com/Forums/zh-CN/vbasiczhchs/thread/e909978c-01e9-44e1-8a3d-f84ba6c060f7
      

  2.   

    你Debug下调试一下,看看OnDraw中的执行情况,另外你的文件打开在OnDraw中执行,觉得不是很合理
      

  3.   

    打开文件,你可以在程序一开始,就先打开,把文件里的内容都读取到内存中,然后,在OnDraw()中显示,在OnDraw()中没必要加 Invalidate 来刷新。另外,如果不用 invalidate 还感觉背景闪烁的话,可以用 双缓冲来显示,这样可以有效去掉背景闪烁的弊端。
      

  4.   

    写在另一个方法里,比如在初始化的时候,获取到pBuf中。
    在OnDraw中,执行你的pDC->DrawText(pBuf,CRect(0,0,cr.right,cr.bottom),DT_WORDBREAK );
      

  5.   

    用局部刷新 InvalidateRect 或 双缓冲
      

  6.   

    Invalidate 不应该放在Ondraw 放进去闪是肯定的。因为系统会不断的调用Ondraw然后不断的清空画布,不闪基本不可能。。