VC++6.0改变按钮颜色及文字颜色(1)
来源:互联网 发布:域名有 什么作用 编辑:程序博客网 时间:2024/06/05 15:44
比较好的方法是设计一个CColorButton类,然后重载DrawItem函数,不过,这之前需要在PreSubclassWindow
中设置控件的属性为BS_OWNERDRAW,创建自有风格Button.
void CColorButton::PreSubclassWindow()
{// TODO: Add your specialized code here and/or call the base class
ModifyStyle(0,BS_OWNERDRAW);
CButton::PreSubclassWindow();
}
void CColorButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your code to draw the specified item
CDC dc;
RECT rect;
dc.Attach(lpDrawItemStruct ->hDC); // Get the Button DC to CDC
rect = lpDrawItemStruct->rcItem; //Store the Button rect to our local rect.
dc.Draw3dRect(&rect,RGB(255,255,255),RGB(0,0,0));
dc.FillSolidRect(&rect,m_Color);//Here you can define the required color to appear on the Button.
UINT state=lpDrawItemStruct->itemState; //This defines the state of the Push button either pressed or not.
if((state & ODS_SELECTED))
{
dc.DrawEdge(&rect,EDGE_SUNKEN,BF_RECT);
}
else
{
dc.DrawEdge(&rect,EDGE_RAISED,BF_RECT);
}
//dc.SetBkColor(RGB(100,100,255)); //Setting the Text Background color
dc.SetBkMode(TRANSPARENT);
dc.SetTextColor(m_TextColor); //Setting the Text Color
TCHAR buffer[MAX_PATH]; //To store the Caption of the button.
ZeroMemory(buffer,MAX_PATH ); //Intializing the buffer to zero
::GetWindowText(lpDrawItemStruct->hwndItem,buffer,MAX_PATH); //Get the Caption of Button Window
dc.DrawText(buffer,&rect,DT_CENTER|DT_VCENTER|DT_SINGLELINE);//Redraw the Caption of Button Window
dc.Detach(); // Detach the Button DC
}
以上.- VC++6.0改变按钮颜色及文字颜色(1)
- VC6.0 改变按钮颜色及文字颜色(2)
- VC6.0改变按钮颜色及文字颜色(3)
- 按钮点击改变文字颜色
- radiobutton 文字颜色改变
- 孙鑫VC学习笔记:第十讲画图 改变对话框及控件的文字/背景颜色
- 孙鑫VC学习笔记:第十讲画图 改变对话框及控件的文字/背景颜色
- 按钮改变文字大小颜色
- Axure8.0 按钮选中时改变颜色和文字
- VC : 改变控件颜色
- Vc改变界面颜色
- VC 中改变ListCtrl每一行的文字颜色
- 改变导航栏的背景,导航栏上的文字的颜色,按钮的颜色
- 改变标签的文字颜色
- API改变文字的颜色
- 改变文本框内文字颜色
- 改变状态栏文字的颜色
- 改变UITextFile水印文字颜色
- POJ 2063 Investment
- silverlight开发实例(Prism+MVVM+RIA)(二)--创建shell及用户登录
- Resubmitting Rejected FOCS paper to STOC
- Excel2003打开文件报只读错误
- android4.04在210上运行
- VC++6.0改变按钮颜色及文字颜色(1)
- Flash音乐控制详解
- Eclipse常用技巧总结:热键,自定义模版及其他
- Android选择联系人+返回对应手机号码(转载并加以修正完善)
- ViewPager多页面滑动切换以及动画效果
- Flash Builder快捷键
- android开发中出现的错误集(不断更新)
- New C# Features in the .NET Framework 4
- C/C++字符串和数字互换方案收集★