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

📄 subject_51248.htm

📁 一些关于vc的问答
💻 HTM
字号:
<p>
序号:51248 发表者:Ollif 发表日期:2003-08-30 14:08:36
<br>主题:请问如何设置一个控件的前景和背景色?
<br>内容:比如控件的ID为IDC_STATIC,有没有这样的函数:<BR>GetCtrlDC(IDC_STATIC)<BR>多谢
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:iamhere 回复日期:2003-08-31 00:35:50
<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>ps:奇怪,怎么有那么多人问这个问题啊?<BR><BR>
<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 + -