建立一个最简单的单文档工程在题目中提到的函数WinApp::OnPaint()\WinMainFrame::OnPaint()\WinView::OnPaint()\WinView::OnDraw()中加入
(OnPaint()对应于各个类添加的WM_PAINT消息,OnDraw()是WinView原有的) CString cx("hello,MFC");
CRect rect;
GetClientRect(&rect);
pDC->SetTextAlign(TA_CENTER);
pDC->TextOut(rect.right/2,rect.bottom/2,cx);只有WinView::OnDraw()看得到显示在文本框里。
这些函数有什么区别为什么会这样?

解决方案 »

  1.   

    OnDraw()中可以绘图,OnPaint()用于重绘。
      

  2.   

    CView::OnDraw
    This method is called by the framework to render an image of the document. The framework calls this method to perform screen display, printing, and print preview, and it passes a different device context in each case. There is no default implementation.
    CWnd::OnPaint
    The framework calls this member function when Windows or an application makes a request to repaint a portion of an application's window.
      

  3.   

    为什么OnPaint()显示不出呢?
    添加到其他函数都没用只有加到OnDraw()中才有显示.
      

  4.   

    有该消息的阐述:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/pantdraw_88ac.asp
      

  5.   

    The framework calls this function to perform screen display, printing, and print preview, and it passes a different device context in each case. There is no default implementation.You must override this function to display your view of the document. You can make graphic device interface (GDI) calls using the CDC object pointed to by the pDC parameter. You can select GDI resources, such as pens or fonts, into the device context before drawing and then deselect them afterwards. Often your drawing code can be device-independent; that is, it doesn't require information about what type of device is displaying the image.To optimize drawing, call the RectVisible member function of the device context to find out whether a given rectangle will be drawn. If you need to distinguish between normal screen display and printing, call the IsPrinting member function of the device context.
      

  6.   

    OnPaint()呢?
    学校的网太烂,上不了MSDN,麻烦mscf(扎西特勒)兄把那篇文章发到
    [email protected]
    谢谢。