checkbox用settextcolor改变文字颜色失败

gorilar 2014-09-28 07:25:46
我在对话框上新建了个checkbox,之后重载了窗口的on_wm_ctlcolor消息,在LRESULT C**Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HRESULT hbr = baseDialog::OnCtlColor(pDC, pWnd, nCtlColor);
UINT uID = pWnd->GetDlgCttlID();
if(uID == IDC_CHECK1)
{
pDC->SetTextColor(RGB(255, 0, 0));
}
if(uID == IDC_STATIC1)
{
pDC->SetTextColor(RGB(255, 0, 0));
}
}

结果static的文本变化了,而checkbox的文本颜色没有变化.问下高手,怎么办,为什么。
...全文
1578 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2014-09-29
  • 打赏
  • 举报
回复
CCheckListBox::DrawItem virtual void DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct ); Parameters lpDrawItemStruct A long pointer to a DRAWITEMSTRUCT structure that contains information about the type of drawing required. Remarks Called by the framework when a visual aspect of an owner-drawn checklist box changes. The itemAction and itemState members of the DRAWITEMSTRUCT structure define the drawing action that is to be performed. By default, this function draws a default checkbox list, consisting of a list of strings each with a default-sized checkbox to the left. The checkbox list size is the one specified in Create. Override this member function to implement drawing of owner-draw checklist boxes that are not the default, such as checklist boxes with lists that aren't strings, with variable-height items, or with checkboxes that aren't on the left. The application should restore all graphics device interface (GDI) objects selected for the display context supplied in lpDrawItemStruct before the termination of this member function. If checklist box items are not all the same height, the checklist box style (specified in Create) must be LBS_OWNERVARIABLE, and you must override the MeasureItem function. CCheckListBox Overview | Class Members | Hierarchy Chart See Also CCheckListBox::Create, CCheckListBox::MeasureItem
-小仙- 2014-09-29
  • 打赏
  • 举报
回复
http://stackoverflow.com/questions/15214237/checkbox-change-the-text-color
-小仙- 2014-09-29
  • 打赏
  • 举报
回复
There are three solutions: 1) Disable theme for you checkbox using SetWindowTheme function. Then handle WM_CTLCOLORSTATIC message and change color using SetTextColor. 2) Use ownerdrawing. Set BS_OWNERDRAW style, as you already knew, to your checkbox. Then handle WM_DRAWITEM message and draw checkbox by yourself. DrawThemeBackground can help to draw themed checkbox. 3) Use customdraw. Handle NM_CUSTOMDRAW notify and draw checkbox on CDDS_PREPAINT stage. http://social.msdn.microsoft.com/Forums/zh-CN/cd6e7637-3550-4d1c-9b11-4f0f0965675f/change-checkbox-text-color-win32?forum=vcgeneral
gorilar 2014-09-29
  • 打赏
  • 举报
回复
感谢ldle_、 Trueman_onlyme、 赵老师。 不过由于赶时间,我贴了个static上去假装checkbox,看起来视觉效果差不多,在重载下onLButtonDown,模拟下选中和取消状态。 我找时间 自绘下,用过自绘checkbox的ctlcolor,不过由于背景问题放弃了。我再试试drawitem或onpaint 谢谢!
阿呆_ 2014-09-28
  • 打赏
  • 举报
回复
checkbox实际上是button,只有owner-draw的button才会给parent发WM_CTLCOLOR
gorilar 2014-09-28
  • 打赏
  • 举报
回复
我用的是vc6

15,980

社区成员

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

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