一个字体,大小,颜色可定义的自绘静态框控件-XColorStatic 类
来源:互联网 发布:彩虹6号围攻帧数优化 编辑:程序博客网 时间:2024/06/15 13:12
翻译来源:https://www.codeproject.com/Articles/5242/XColorStatic-a-colorizing-static-control
- 下载演示项目 - 32.2 Kb
介绍
XColor Static是一种通用控件,允许在对话框中显示漂亮的文本。该演示向您展示了可能的文本和图标显示类型:
XColorstatic API
以下是完整的方法列表:CXColorStatic
void SetBackgroundColor(COLORREF rgb, BOOL bRedraw = TRUE);void SetTextColor(COLORREF rgb, BOOL bRedraw = TRUE);void SetBold(BOOL bFlag, BOOL bRedraw = TRUE);void SetFont(LPCTSTR lpszFaceName, int nPointSize, BOOL bRedraw = TRUE);void SetFont(LOGFONT *pLogFont, BOOL bRedraw = TRUE);void SetFont(CFont *pFont, BOOL bRedraw = TRUE);void SetIcon(HICON hIcon, BOOL bRedraw = TRUE);void SetMargins(int x, int y) { m_nXMargin = x; m_nYMargin = y; }
如何使用
要将XColor Static集成到应用程序中,首先需要将以下文件添加到您的项目中:
- XColorstatic.cpp
- XColor static.h
- FontSize.cpp
- FontSize.h
然后使用资源编辑器将静态控件添加到对话框中,并使用类向导将成员变量附加到该控件。请注意,添加静态控件时,您必须将其命名为除。IDC_STATIC
接下来,包含头文件XColor static .H在对话框的头文件。然后用。现在你准备开始使用XColor Static。
用法
BOOL CXColorStaticTestDlg::OnInitDialog(){CDialog::OnInitDialog();// Add "About..." menu item to system menu.// IDM_ABOUTBOX must be in the system command range.ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX < 0xF000);CMenu* pSysMenu = GetSystemMenu(FALSE);if (pSysMenu != NULL){CString strAboutMenu;strAboutMenu.LoadString(IDS_ABOUTBOX);if (!strAboutMenu.IsEmpty()){pSysMenu->AppendMenu(MF_SEPARATOR);pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);}}// Set the icon for this dialog. The framework does this automatically// when the application's main window is not a dialogSetIcon(m_hIcon, TRUE);// Set big iconSetIcon(m_hIcon, FALSE);// Set small iconm_Banner.SetTextColor(RGB(0,0,255), FALSE);m_Banner.SetBackgroundColor(RGB(155,115,255), FALSE); m_Banner.SetBold(TRUE, FALSE);m_Banner.SetFont(_T("Comic Sans MS"), 20, FALSE);HICON hIcon = AfxGetApp()->LoadIcon(IDI_SHERLOCK);m_Icon.SetIcon(hIcon);m_Icon.SetBackgroundColor(RGB(201,201,255), FALSE);m_Text1.SetWindowText(_T("To Sherlock Holmes she is always THE woman. I have seldom heard ")_T("him mention her under any other name. In his eyes she eclipses ")_T("and predominates the whole of her sex. It was not that he felt ")_T("any emotion akin to love for Irene Adler."));m_Text1.SetMargins(15, 0);m_Text1.SetFont((LPCTSTR)NULL, 10, FALSE);m_Text2.SetBold(TRUE, FALSE);m_Text2.SetFont(_T("Arial"), 14, FALSE);m_Text2.SetWindowText(_T("But wait... There's MORE!!!"));m_Text2.SetMargins(15, 0);m_Text3.SetFont((LPCTSTR)NULL, 10, FALSE);m_Text3.SetWindowText(_T("One night -- it was on the twentieth of March, 1888 -- I was ")_T("returning from a journey to a patient (for I had now returned to ")_T("civil practice), when my way led me through Baker Street. As I ")_T("passed the well-remembered door, which must always be associated ")_T("in my mind with my wooing, and with the dark incidents of the ")_T("Study in Scarlet, I was seized with a keen desire to see Holmes ")_T("again, and to know how he was employing his extraordinary powers."));m_Text3.SetMargins(15, 0);m_Text3.SetFont((LPCTSTR)NULL, 10, FALSE);m_Text4.SetMargins(15, 0);LOGFONT lf;CFont *pFont = m_Text4.GetFont();pFont->GetLogFont(&lf);lf.lfItalic = TRUE;_tcscpy(lf.lfFaceName, _T("Verdana"));m_Text4.SetFont(&lf, FALSE);return TRUE; // return TRUE unless you set the focus to a control}
该软件发布到公共领域。您可以随意使用任何您喜欢的方式。如果您修改它或扩展它,请考虑发布新的代码在这里供大家分享。该软件按“原样”提供,没有明示或默示的保证。对于此软件可能导致的任何损坏或业务损失,我不承担任何责任。
修订记录
版本1.0 - 2003年10月17日
- 首次公开发布。
评论和讨论
![一般 一般](https://codeproject.global.ssl.fastly.net/script/Forums/Images/msg_general.gif)
![会员 会员](https://codeproject.global.ssl.fastly.net/App_Themes/CodeProject/Img/icn-member-16.gif)
![](https://codeproject.global.ssl.fastly.net/script/Forums/Images/t.gif)
透明度是我在许多演示类型Dialog Apps中的一个目标。
以前的解决方案有效,但在某些情况下需要太多的背景知识。
这是一个简单的解决方案,让文本画在已经存在的背景上。
要打开“静态”控件的“透明度”,请使用“对话框编辑器”将“透明度”的“扩展样式”复选框设置为“true” - 将“关闭”默认为具有完整背景的常规“不透明”文本。
首先在OnPaint中,成员函数的顶部现在将如下所示:
void CXColorStatic :: OnPaint()
{
CPaintDC dc(this); //设备上下文绘制
dc.SaveDC();
dc.SetTextColor(m_rgbText);
if(!(GetExStyle()&
WS_EX_TRANSPARENT)) {
dc.SetBkColor(m_rgbBackground);
dc.SetBkMode(TRANSPARENT);
}
else
{
dc.SetBkMode(TRANSPARENT);
}
dc.SelectObject(m_pBrush);
CRect rect;
GetClientRect(RECT);
...(其余与以前一样)
第二个设置EraseBackground :
BOOL CXColorStatic :: OnEraseBkgnd(CDC * pDC)
{
if(!(GetExStyle()&WS_EX_TRANSPARENT))
{
CRect cr;
GetClientRect(CR);
pDC-> FillRect(&cr,m_pBrush);
}
return TRUE; //的CStatic :: OnEraseBkgnd(PDC);
}
Wayne L. Burgess
译者见解:
实现透明度以上方法在属性框设置 TRANSPARENT=TRUE,这就需要一个一个控件去修改;如果是动态创建,可以增加WS_EX_TRANSPARENT,在
void CXColorStatic::PreSubclassWindow()
{
TRACE(_T("in CXColorStatic::PreSubclassWindow\n"));
ModifyStyleEx(0, WS_EX_TRANSPARENT);
// get current font
已修改的源码案例:http://download.csdn.net/detail/greless/9898892
- 一个字体,大小,颜色可定义的自绘静态框控件-XColorStatic 类
- MFC改变静态控件字体的大小
- iOS 一个控件内字符显示不同的字体,大小和颜色
- 如何更改静态文本控件的字体与颜色
- 静态控件上显示不同的字体及颜色
- MFC静态文本控件如何设置字体--大小和颜色及背景色
- 在一个UILabel上改变字体的颜色或大小
- MFC中修改静态文本控件的颜色和大小
- Android ui 字体 控件大小 颜色
- MFC 可以设置背景色、字体、字体颜色、透明背景的 Static 静态文本控件
- MFC 可以设置背景色、字体、字体颜色、透明背景的 Static 静态文本控件
- MFC--设置静态文本框的文字的字体、大小和颜色
- 设置控件的颜色,字体
- 调整控件字体的大小
- 动态设置编辑框的大小、 文本字体、颜色等
- MFC——设置静态文本 大小 字体格式 颜色
- iOS开发-UI控件:修改textField的placeholder的字体颜色、大小
- 换行的字体的设置大小颜色
- 设计模式-代理模式
- iOS UI图像,页面性能
- Linux下使用sleep
- JAVA学习之旅--新路伊始
- POJ1860_通过SPFA寻找无限正循环
- 一个字体,大小,颜色可定义的自绘静态框控件-XColorStatic 类
- 漫步最优化十三——驻点
- Luogu P2333 [SCOI2006]一孔之见 计算几何
- Java内存溢出异常(OOM)完全指南
- 最大公约数
- php学习笔记--session回话
- Spring+SpringMVC+hibernate整合开发
- basic C++ knowledge prepared for data structure (1)
- python mysql插入数据报错:TypeError: %d format: a number is required, not str