在下初学VC,不知道下面的语句是什么意思:
void CView::OnPaint()
{
CPaintDC dc(this); //(1)
OnPreparDC(&dc); //(2)
OnDraw(&dc); //(3)
}第一句是通过当前的窗口构造一个对象dc吧?和CClientDC dc(this)有什么区别呢?
还有啊,第(2)(3)句是什么意思呢?
先谢过给位了~
void CView::OnPaint()
{
CPaintDC dc(this); //(1)
OnPreparDC(&dc); //(2)
OnDraw(&dc); //(3)
}第一句是通过当前的窗口构造一个对象dc吧?和CClientDC dc(this)有什么区别呢?
还有啊,第(2)(3)句是什么意思呢?
先谢过给位了~
解决方案 »
- 打开对话框修改默认目录的问题。
- UDP发送数据,在阻塞模式下,多发几次,就会出问题!!大家帮我看看!
- 关于HGLOBAL的小问题
- 怎么更改一个ole对象的图标啊?
- 在浏览器中,如何得到当前光标所在位置的图片的链接地址
- 谁有从位图到GIF的转换模块,C++或VB的都行?
- 请帮个忙(急) 怎样把CString 转unsigned char ,,我没有分了,请帮个忙吧
- 请问如何在OnPreparePrinting函数中获取当前打印设置的页面宽和高?
- 菜鸟问个问题?如何创建一个跟记事本功能一样的新建功能。
- 关于指针的强制转换问题(概念性的)
- 想招个做D3D的,为什么简历进来都是做数据库的呢?吐槽一下!
- 找师父
--------------------------
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.
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个比较混
1.CPaintDC 是WM_PAINT消息专属的,好处是自动调用和释放,不用用户担心其他资源
2.CClientDC 是视图的整个DC,需要ReleaseDC自己来释放资源。不然内存泄露
3.CWindowDC 这个DC包括整个窗体的边框和标题的,上面2个没这个功能。
OnPreparDC(&dc); 其实就是再屏幕显示之前调用的一个固定函数。让你在屏幕显示之前干一点事情罢了。
一般都不复写的OnDraw(&dc)的话应该就是实实在在的你的绘图实现了。是个虚函数,一般都自己实现的。
你可以这样理解,在一个大大的画布上画画(paintdc),而他中间呢还贴了一个小画布(clientdc)
不同的是,你在哪个布上画而已,理解了吗