如何改变Button的颜色 我映射了一个WM_CTLCOLOR消息,但是在消息处理函数中设置了一个断点却发现断点没有作用(也就是消息根本没有被发送),大家帮帮忙。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 WM_CTLCOLOR不能修改button颜色http://dev.csdn.net/develop/article/8/8432.shtmhttp://www.codeguru.com/Cpp/controls/buttonctrl/article.php/c5169/ 风格设置 OwnDraw 记不太清,就是自画吧 试试WM_CTLCOLORBTN,另外加上OWNERDRAW属性。不过最好是到网上找个例子,看看别人怎么做的。有很多不错的自定义Button类,例如CButtonST 建立按钮时要设置BS_OWNERDRAW属性标志然后添加WM_DRAWITEM消息响应 下面是消息响应函数, CClassXXX从CDialog派生:void CClassXXX::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) { // TODO: Add your message handler code here and/or call default if(nIDCtl!=IDC_BUTTON4) // IDC_BUTTON4 是你要重画的按钮标识 { CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct); return; } CPen pen(PS_SOLID, 1, RGB(234,30,150)); CBrush brush(RGB(134,130,210)); HPEN hOldPen =(HPEN)::SelectObject(lpDrawItemStruct->hDC, (HPEN)pen); HBRUSH hOldbrush = (HBRUSH)::SelectObject(lpDrawItemStruct->hDC, (HBRUSH)brush); ::Rectangle( lpDrawItemStruct->hDC, lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.top, lpDrawItemStruct->rcItem.right, lpDrawItemStruct->rcItem.bottom ); ::SelectObject(lpDrawItemStruct->hDC, hOldbrush); ::SelectObject(lpDrawItemStruct->hDC, hOldPen);}查看DRAWITEMSTRUCT 结构说明根据不同的按钮状态画出不同的颜色: 判断该结构的itemAction thank you. 好久没用了。 MFC怎样读取一个文本文档的字符串 使用资源模板创建子窗口 atl::Cwindow里调用SetTimer为何不生效? 请问这个程序包含梯度运算了吗? 如何知道硬盘中那个文件被调用或者被写入 如何进行工程改名? 服务中调用RegisterDeviceNotification老是失败,什么原因阿 如何同步鼠标与屏幕 一个简单的问题,有关数据显示! 有关组合框的一个问题 散分,有一些帖子分了n年了,没有人回帖。今天要把它们的分散了。 Bitmap的灰度显示。
http://dev.csdn.net/develop/article/8/8432.shtm
http://www.codeguru.com/Cpp/controls/buttonctrl/article.php/c5169/
不过最好是到网上找个例子,看看别人怎么做的。有很多不错的自定义Button类,例如CButtonST
然后添加WM_DRAWITEM消息响应
下面是消息响应函数, CClassXXX从CDialog派生:void CClassXXX::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your message handler code here and/or call default
if(nIDCtl!=IDC_BUTTON4) // IDC_BUTTON4 是你要重画的按钮标识
{
CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
return;
} CPen pen(PS_SOLID, 1, RGB(234,30,150));
CBrush brush(RGB(134,130,210));
HPEN hOldPen =(HPEN)::SelectObject(lpDrawItemStruct->hDC, (HPEN)pen);
HBRUSH hOldbrush = (HBRUSH)::SelectObject(lpDrawItemStruct->hDC, (HBRUSH)brush); ::Rectangle(
lpDrawItemStruct->hDC,
lpDrawItemStruct->rcItem.left,
lpDrawItemStruct->rcItem.top,
lpDrawItemStruct->rcItem.right,
lpDrawItemStruct->rcItem.bottom
); ::SelectObject(lpDrawItemStruct->hDC, hOldbrush);
::SelectObject(lpDrawItemStruct->hDC, hOldPen);
}查看DRAWITEMSTRUCT 结构说明根据不同的按钮状态画出不同的颜色:
判断该结构的itemAction