在下初学VC,不知道下面的语句是什么意思:
void CView::OnPaint()
{
   CPaintDC dc(this);   //(1)
   OnPreparDC(&dc);   //(2)
   OnDraw(&dc);   //(3)
}第一句是通过当前的窗口构造一个对象dc吧?和CClientDC dc(this)有什么区别呢?
还有啊,第(2)(3)句是什么意思呢?
   先谢过给位了~

解决方案 »

  1.   

    A CPaintDC object can only be used when responding to aWM_PAINT message, usually in your OnPaint message-handler member function.
    --------------------------
    CClientDC :The CClientDC class is derived from CDC and takes care of calling the Windows functionsGetDC at construction time andReleaseDC at destruction time. This means that the device context associated with a CClientDC object is the client area of a window.
      

  2.   

    OnPrepareDC :
    Called by the framework before the OnDraw member function is called for screen display and before the OnPrint member function is called for each page during printing or print preview. The default implementation of this function does nothing if the function is called for screen display. However, this function is overridden in derived classes, such as CScrollView, to adjust attributes of the device context; consequently, you should always call the base class implementation at the beginning of your override. 
    --------------------
    楼主要学会使用MSDN查询
      

  3.   

    CPaintDC CClientDC CWindowDC
    这个3个比较混
    1.CPaintDC 是WM_PAINT消息专属的,好处是自动调用和释放,不用用户担心其他资源
    2.CClientDC 是视图的整个DC,需要ReleaseDC自己来释放资源。不然内存泄露
    3.CWindowDC 这个DC包括整个窗体的边框和标题的,上面2个没这个功能。
    OnPreparDC(&dc); 其实就是再屏幕显示之前调用的一个固定函数。让你在屏幕显示之前干一点事情罢了。
    一般都不复写的OnDraw(&dc)的话应该就是实实在在的你的绘图实现了。是个虚函数,一般都自己实现的。
      

  4.   

    LZ 首先要对GDI编程有个系统的了解哦,你的问题涉及到GDI当中的 设备描述表(DC) ,其中的知识细节不是一两句话能够概述的,LZ可以看下别人总结的一些东西:http://blog.csdn.net/byxdaz/article/details/5949590PS:首先要从Windows GDI学习着手,在这基础之上再了解MFC对于GDI封装的这些东西吧
      

  5.   

    很简单,
    你可以这样理解,在一个大大的画布上画画(paintdc),而他中间呢还贴了一个小画布(clientdc)
    不同的是,你在哪个布上画而已,理解了吗