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

📄 index033.htm

📁 一本不错的VC编程的参考书
💻 HTM
字号:
<html>
<style type="text/css"><!--
.p9 {  font-family: "宋体"; font-size: 9pt}a        {text-transform: none; text-decoration: none;}
a:hover {text-decoration: underline; color: #FF0000;}
--></style>
<body background="../di2001.jpg">
<h3 align="center"><font COLOR="#AOAO99"></font></h3>
<table width="100%" border="1" cellspacing="1">
<tr><td><p align="center"><font color="#FF0000">如何改变对话或窗体视窗的背景颜色</font></td></tr>
<tr><td><p>
</Br>
调用CWinApp : : SetDialogBkColor可以改变所有应用程序的背景颜色。第一个参数指定了背景颜色,第二个参数指定了文本颜色。下例将应用程序对话设置为蓝色背景和黄色文本。<Br>
BOOL CSampleApp : : InitInstance ( )<Br>
{<Br>
&nbsp;…<Br>
</Br>
&nbsp;//use blue dialog with yellow text .<Br>
&nbsp;SetDialogBkColor (RGB (0, 0, 255 ), RGB ( 255 ,255 , 0 ) )<Br>
</Br>
&nbsp;…<Br>
}<Br>
</Br>
需要重画对话(或对话的子控件)时,Windows向对话发送消息WM_CTLCOLOR,通常用户可以让Windows选择绘画背景的刷子,也可重置该消息指定刷子。下例说明了创建一个红色背景对话的步骤。<Br>
</Br>
首先,给对话基类增加一人成员变量<Br>
CBursh :class CMyFormView : public CFormView<Br>
{<Br>
&nbsp;…<Br>
</Br>
&nbsp;private :<Br>
&nbsp;CBrush m_ brush  // background brush<Br>
</Br>
&nbsp;…<Br>
}<Br>
</Br>
其次, 在类的构造函数中将刷子初始化为所需要的背景颜色。<Br>
CMyFormView : : CMyFormView ( )<Br>
{<Br>
&nbsp;// Initialize background brush .<Br>
&nbsp;m_brush .CreateSolidBrush (RGB ( 0, 0, 255) )<Br>
}<Br>
</Br>
最后,使用ClassWizard处理WM_CTLCOLOR消息并返回一个用来绘画对话背景的刷子句柄。注意:由于当重画对话控件时也要调用该函数,所以要检测nCtlColor参量。<Br>
HBRUSH CMyFormView : : OnCtlColor (CDC* pDC , CWnd*pWnd , UINT nCtlColor<Br>
)<Br>
</Br>
{<Br>
&nbsp;// Determine if drawing a dialog box . If we are, return +handle to<Br>
&nbsp;//our own background brush . Otherwise let windows handle it .<Br>
&nbsp;if (nCtlColor = = CTLCOLOR _ DLG )<Br>
&nbsp;return (HBRUSH) m_brush.GetSafeHandle ( )<Br>
&nbsp;return CFormView : : OnCtlColor (pDC, pWnd , nCtlColor<Br>
)<Br>
}<Br>
</Br>
</p></td></tr>
</table>
</body></html>

⌨️ 快捷键说明

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