MFC中绘图函数总结(summary of common painting functions in MFC)

Function                Relative message         Functionality                                                             Calling order    

OnNCPaint           WM_NCPAINT                Paint nonclient area(window frame by default)                0

OnEraseBkgnd     WM_ERASEBKGND         Erase a window background                                            1

OnPaint                WM_PAINT                     Repaint a window rect(usually the client area)                2

DrawItem             WM_DRAWITEM             In place of OnPaint draws an owner-draw control          2

OnCtlColor           WM_CTLCOLOR              Change a control’s color(in parent)                                  3

CtlColor                WM_CTLCOLOR              Change a control’s color(in child)                                     3

   

Note:

1.    OnPaint cannot coexist with DrawItem,when you put them together the latter is ignored.

2.    We can change a control’s text by using SetFont,but has no direct way of altering its color.And that’s how WM_CTLCOLOR   comes to the rescue.Windows supplies two ways to modify a child control,and both ways request the child to send its parent

a message(WM_CTLCOLOR) which contains its DC information.Then based on the parent’s reaction,we got our two ways:

A.   The parent responds to the message in OnCtlColor,then calls CDC::SetTextColor or CDC::SetBkColor to change control text font attributes.Finally it must return a HBRUSH which is to be used for painting the control background.

B.   The parent can choose not to handle the message but return it to the child by using a special macro in MFC which goes like ON_WM_CTLCOLOR_REFLECT,then the child can do some changes in CtlColor responding to the message.

3.    Both OnCtlColor and CtlColor are called when a child control is about to be drawn.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值