聪明文档网

聪明文档网

最新最全的文档下载
当前位置: 首页> ScreenToClient等4个函数的区别

ScreenToClient等4个函数的区别

时间:2018-07-02 02:12:23    下载该word文档

ClientToScreenScreenToClient,DPtoLP函数和LPtoDP函数

CPaintDC 、CWindowDC、 CClientDC、 CDC的区别与联系

CPaintDC CWindowDC CClientDC CDC

关系图:

一句话概括:

CPaintDC            无效区dc,      相当于BeginPaint,   EndPaint 
CClientDC          客户区dc,      相当于GetDC,   ReleaseDC 
CWindowDC      整窗口dc,      相当于GetWindowDC,   ReleaseDC 
CDC                     任何dc,          相当于CreateDC,   DeleteDC

 一、CPaintDC

 Mfc自动生成的OnPaint函数都会定义一个CPaintDC类型的变量。

如: 

[cpp] 

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

11.

12.

13.

14.

15.

16.

17.

18.

19.

20.

21.

22.

23.

24.

25.

26.

27.

28.

29.

30.

31.

32.

33.

MSDN上的解释:

The CPaintDC class is a device-context class derived from CDC. It performs a CWnd::BeginPaint at construction time and CWnd::EndPaint at destruction time.

(翻译:CPaintDC继承自CDC,它在构造函数中执行CWnd::BeginPaint,在析构函数中调用CWnd::EndPaint

 A CPaintDC object can only be used when responding to aWM_PAINT message, usually in yourOnPaintmessage-handler member function.

(翻译:CPaintDC对象通常当响应WM_PAINT消息时在OnPaint消息处理函数中被使用。)

题外话,这个英文按照中国人的逻辑来说应该这样表达:

when responding to a WM_PAINT message, a CPaintDC object can only be used usually in yourOnPaintmessage-handler member function.

 二、CClientDC

MSDN上的解释:

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 aCClientDC object is the client area of a window.

(翻译:CClientDC继承自CDC,它在构造函数中调用GetDC,在析构函数中调用ReleaseDC.这意味着与CClientDC对象联系的DC是窗口的客户区。)

 三、CWindowDC

The CWindowDC class is derived from CDC. It calls the Windows functionsGetWindowDC at construction time andReleaseDC at destruction time. This means that aCWindowDC object accesses the entire screen area of aCWnd (both client and nonclient areas).( 翻译:获取整个屏幕区域,包括客户区和非客户区。)

 

CSDN:

CPaintDC只能在OnPaint()中使用,CClientDC只和客户区有关,可以在任何地方使用。

 CPaintDC代表整个窗口,而CClientDC代表窗口的客户区(不包括标题栏、边框),要选择合适的DC进行绘制。

 CPaintDC一般是用在OnPaint()函数里的。CPaintDC对象一构造,消息队列中的WM_PAINT会被取走,而CClientDC是用在非OnPaint()函数里画图的。

CClientDCWM_PAINT消息没有从消息队列中清除,CPaintDC结束时会自动清除该消息。

 CPaintDC是一个特殊的设备环境封闭类,它主要处理windowswm_paint消息。CClientDC可以自动调用GetDCReleaseDC函数。CwindowDC是从CDC类继承,用于得到桌面窗口设备环境指针。

CclinetDC用于窗口客户区,CwindowDC用于整个窗口,包括非客户区。

 

OnPaint中用CPaintDC仅仅对需要刷新的地方进行重绘。

> 往一个对话框上画图,在OnPaint()里是不是只能用   CPaintDC? 
恰恰相反,CPaintDC是推荐只用在OnPaint中的。诚如   i_noname(晚九朝五)   所言:它的范围是WM_PAINT消息所要重画的区域大小,因为这个类的构造函数中调用了BeginPaint,析构函数中调用了EndPaint。这两个API是针对WM_PAINT消息使用的,所以不要把CPaintDC用在非对WM_PAINT消息响应的函数中

CPaintDCCClientDCCWindowDCCMetaFileDC类的主要特点及区别

免费下载 Word文档免费下载: ScreenToClient等4个函数的区别

  • 29.8

    ¥45 每天只需1.0元
    1个月 推荐
  • 9.9

    ¥15
    1天
  • 59.8

    ¥90
    3个月

选择支付方式

  • 微信付款
郑重提醒:支付后,系统自动为您完成注册

请使用微信扫码支付(元)

订单号:
支付后,系统自动为您完成注册
遇到问题请联系 在线客服

常用手机号:
用于找回密码
图片验证码:
看不清?点击更换
短信验证码:
新密码:
 
绑定后可用手机号登录
请不要关闭本页面,支付完成后请点击【支付完成】按钮
遇到问题请联系 在线客服