控件重绘问题!

小金8 2007-04-20 10:05:24

按钮控件的重绘问题,怎么样才能使按钮CButton控件 改变背景色和字体颜色?
查询了好多资料,都没有找到方法!希望高手们帮助!如何才能实现,最好给个例子;)!
...全文
363 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
小金8 2007-04-20
  • 打赏
  • 举报
回复
CWnd::OnCtlColor
afx_msg HBRUSH OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor );
这个好像不好用,我试过了!
syy64 2007-04-20
  • 打赏
  • 举报
回复
CWnd::OnCtlColor
afx_msg HBRUSH OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor );

Return Value

OnCtlColor must return a handle to the brush that is to be used for painting the control background.

Parameters

pDC

Contains a pointer to the display context for the child window. May be temporary.

pWnd

Contains a pointer to the control asking for the color. May be temporary.

nCtlColor

Contains one of the following values, specifying the type of control:

CTLCOLOR_BTN Button control


CTLCOLOR_DLG Dialog box


CTLCOLOR_EDIT Edit control


CTLCOLOR_LISTBOX List-box control


CTLCOLOR_MSGBOX Message box


CTLCOLOR_SCROLLBAR Scroll-bar control


CTLCOLOR_STATIC Static control
Remarks

The framework calls this member function when a child control is about to be drawn. Most controls send this message to their parent (usually a dialog box) to prepare the pDC for drawing the control using the correct colors.

To change the text color, call the SetTextColor member function with the desired red, green, and blue (RGB) values.

To change the background color of a single-line edit control, set the brush handle in both the CTLCOLOR_EDIT and CTLCOLOR_MSGBOX message codes, and call the CDC::SetBkColor function in response to the CTLCOLOR_EDIT code.

OnCtlColor will not be called for the list box of a drop-down combo box because the drop-down list box is actually a child of the combo box and not a child of the window. To change the color of the drop-down list box, create a CComboBox with an override of OnCtlColor that checks for CTLCOLOR_LISTBOX in the nCtlColor parameter. In this handler, the SetBkColor member function must be used to set the background color for the text.

Note This member function is called by the framework to allow your application to handle a Windows message. The parameters passed to your function reflect the parameters received by the framework when the message was received. If you call the base-class implementation of this function, that implementation will use the parameters originally passed with the message and not the parameters you supply to the function.

CWnd Overview | Class Members | Hierarchy Chart

See Also CDC::SetBkColor
lzd 2007-04-20
  • 打赏
  • 举报
回复
http://www.1to2.us/VC-a33964.htm
ouyh12345 2007-04-20
  • 打赏
  • 举报
回复
子类化CButton,在DrawItem里改变背景色和字体颜色

google一下子类化,很多资料的
xia_wu619 2007-04-20
  • 打赏
  • 举报
回复
如果是Button,背景颜色不能通过OnCtlColor改变吧~~
http://www.vckbase.com/article/buttonctrl/0001.htm
你看看这个,或许会有帮助~
mynamelj 2007-04-20
  • 打赏
  • 举报
回复
只是改变背景色的话OnCtlColor就可以,不需要重绘

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧