⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_62681.htm

📁 vc
💻 HTM
字号:
<p>
序号:62681 发表者:李强-01 发表日期:2003-11-28 09:40:22
<br>主题:如何设置static控件的字体与颜色
<br>内容:下面是设置字体的一段代码,我修改了字体高度(20改成了40)与粗度(400改成了800),结果却没有反应,不知为什么.另外再添加什么代码,可以设置颜色,烦请高手增加一些代码.<BR><BR>cfnt.CreateFont(&nbsp;&nbsp;20,&nbsp;&nbsp;0,&nbsp;&nbsp;&nbsp;&nbsp;//字体高度、宽度<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0,&nbsp;&nbsp;0,&nbsp;&nbsp;&nbsp;&nbsp;//文本倾斜度、字体倾斜度<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 400,&nbsp;&nbsp;&nbsp;&nbsp;//字体粗度<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0,&nbsp;&nbsp;&nbsp;&nbsp;0,&nbsp;&nbsp;&nbsp;&nbsp;0,&nbsp;&nbsp;&nbsp;&nbsp;//非斜体字、无下划线、无删除线<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ANSI_CHARSET,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //所用字符集为ANSI_CHARSET<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OUT_DEFAULT_PRECIS,&nbsp;&nbsp;&nbsp;&nbsp;//删除精度为默认值<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CLIP_DEFAULT_PRECIS,&nbsp;&nbsp;&nbsp;&nbsp;//裁剪精度为默认值<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DEFAULT_QUALITY,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//输出质量为默认值<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DEFAULT_PITCH|FF_DONTCARE ,&nbsp;&nbsp;&nbsp;&nbsp;//字间距与字体系列为默认值<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_T(&#34;隶书&#34;));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//字体名称<BR><BR>m_stat1.SetFont(&amp;cfnt);<BR><BR><BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:zzjhsj 回复日期:2003-11-28 10:12:24
<br>内容:cfnt需要在m_stat1整个生存期有效,如果SetFont后Font被delete了,嘿嘿,就不会有反应了<BR>颜色?处理 WM_CTLCOLORSTATIC
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:kobo 回复日期:2003-11-28 10:17:00
<br>内容:内容:在对话框中处理WM_CTLCOLOR消息<BR><BR>给你看看MSDN中的例子吧:<BR>// This OnCtlColor handler will change the color of a static control<BR>// with the ID of IDC_MYSTATIC. The code assumes that the CMyDialog<BR>// class has an initialized and created CBrush member named m_brush.<BR>// The control will be painted with red text and a background<BR>// color of m_brush.<BR><BR>HBRUSH CZilchDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) <BR>{<BR>&nbsp;&nbsp; // Call the base class implementation first! Otherwise, it may<BR>&nbsp;&nbsp; // undo what we're trying to accomplish here.<BR>&nbsp;&nbsp; HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);<BR><BR>&nbsp;&nbsp; // Are we painting the IDC_MYSTATIC control? We can use<BR>&nbsp;&nbsp; // CWnd::GetDlgCtrlID() to perform the most efficient test.<BR>&nbsp;&nbsp; if (pWnd-&gt;GetDlgCtrlID() == IDC_MYSTATIC)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Set the text color to red<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;SetTextColor(RGB(255, 0, 0));<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Set the background mode for text to transparent <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// so background will show thru.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;SetBkMode(TRANSPARENT);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Return handle to our CBrush object<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hbr = m_brush;<BR>&nbsp;&nbsp; }<BR><BR>&nbsp;&nbsp; return hbr;<BR>}<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:hurtmanzc 回复日期:2003-11-28 10:33:02
<br>内容:给你个例子,参考一下:
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:tiger_bai 回复日期:2003-11-28 11:56:16
<br>内容:看看这<BR>http://www.vccode.com/file_show.php?id=137
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:李强-01 回复日期:2003-11-29 18:28:51
<br>内容:请楼上的hurtmanzc老兄告诉我怎么生成的CStatic派生类CXColorStatic控件,多谢了
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:浪际天涯 回复日期:2003-12-01 10:56:46
<br>内容:不用生成控件呀,你在对话框上拖一个Static Text,给它添加变量的时候基类为CXColorStatic,然后在CXColorStatic的构造函数中加一些对颜色等的初始化设置,就OK了
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -