惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cisco Talos Blog
Cisco Talos Blog
阮一峰的网络日志
阮一峰的网络日志
云风的 BLOG
云风的 BLOG
D
Docker
Vercel News
Vercel News
IT之家
IT之家
Recent Announcements
Recent Announcements
Last Week in AI
Last Week in AI
V
Visual Studio Blog
Engineering at Meta
Engineering at Meta
腾讯CDC
Google DeepMind News
Google DeepMind News
I
InfoQ
博客园 - 三生石上(FineUI控件)
Apple Machine Learning Research
Apple Machine Learning Research
The GitHub Blog
The GitHub Blog
博客园 - Franky
The Cloudflare Blog
A
About on SuperTechFans
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
T
Tenable Blog
P
Proofpoint News Feed
Recorded Future
Recorded Future
Security Latest
Security Latest
H
Hackread – Cybersecurity News, Data Breaches, AI and More
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 聂微东
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Google Online Security Blog
Google Online Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Simon Willison's Weblog
Simon Willison's Weblog
The Last Watchdog
The Last Watchdog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
U
Unit 42
The Hacker News
The Hacker News
Martin Fowler
Martin Fowler
T
Threat Research - Cisco Blogs
NISL@THU
NISL@THU
F
Full Disclosure
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理
Hugging Face - Blog
Hugging Face - Blog
V
V2EX
Project Zero
Project Zero

博客园 - 流云

编译时找不到xxx.pch [ZT] SQL Server 中四种匹配符的含义[ZT] TAB ORDER按回车键下个控件自动获得焦点 VC获取系统时间、程序运行时间 - 流云 - 博客园 VC常用数据类型使用转换详解 [转] - 流云 - 博客园 VC遍历文件夹下所有文件和文件夹 - 流云 - 博客园 获得指针(文档、视图、框架) 让对话框中的菜单变灰(根据可用性而显示) 获取 本机 SQL SERVER 服务器名 - 流云 用VC++修改注册表----让我们踏出第一步(适合初学者) VC+ADO 连接ACCESS和SQL SERVER的方法 动态链接库DLL的编写和调用(四则表达式计算) SQL SERVER 数据库备份还原 列表控件ListCtrl的使用 文本读写 CStdioFile流文件 文件读写 CFile 字体对话框FontDialog 颜色对话框ColorDialog VC获取系统时间、程序运行时间
对话框与其控件的颜色
流云 · 2005-05-29 · via 博客园 - 流云

要改变对话框的一般颜色,可以在C***App的InitInstance函数里加入如下代码:
SetDialogBkColor(RGB(
0,255,255),RGB(255,0,0));//背景青蓝、文字红色

但是这样不能改变对话框中的图形控件的颜色;
每个控件在dialog中都是一个窗口,当要绘制控件时,会发出一个WM_CTLCOLOR消息给它的父窗口(对话框本身).消息映射及响应函数如下:
ON_WM_CRLCOLOR()  //反映WM_CTLCOLOR消息
afx_msg HBRUSH CWnd::OnCrlColor(CDC* pDC,CWnd* pWnd,UINT nCtlColor);
//
nCtlColor类型:
CTLCOLOR_DLG对话框本身,不含有所有的控件
CTLCOLOR_STATIC 所有包含static text控件的设置(也包括无效的edit box、combo box的eidt box)
CTLCOLOR_EDIT     edit box与combo box的eidt box部分
CTLCOLOR_LIST     list box与combo box的edit box部分
CTLCOLOR_SCROLLBAR  Scroll bar的空白区

我们也可以单独改变某一个控件的颜色.OnCtrlColor函数的pWnd成员变量是各控件的窗口指针,以pWnd->GetDlgCtrlID()可以获得调用此函数的控件ID,将它与已知ID比较,就可以改变这个控件的颜色。另外一个作法是比较pWnd;例如:如果一个edit box控件的成员变量m_edit1被声明为CEdit类,那么把m_edit1.m_hWnd与pWnd->m_hWnd比较,也可以知道是哪个控件.
下面是一个例子:

HBRUSH C***Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
    HBRUSH hbr 
= CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
    
    
// TODO: Change any attributes of the DC here
if(nCtlColor== CTLCOLOR_LISTBOX)
 {
  HBRUSH m_hbrush;
  m_hbrush
=CreateSolidBrush(RGB(0,0,0));
  pDC
->SetBkMode(TRANSPARENT);
  pDC
->SetTextColor(RGB(255,255,255));
  
return m_hbrush;
 }
CBrush m_cBrush;
    m_cBrush.CreateSolidBrush(RGB(
0,255,255));
    
switch(nCtlColor)
    {
    
case CTLCOLOR_DLG:
        
return m_cBrush;
        
break;
    
case CTLCOLOR_STATIC:
        pDC
->SetTextColor(RGB(255,0,0));
        pDC
->SetBkColor(RGB(0,255,255));
        
return (HBRUSH)m_cBrush;
        
break;
    }
    DeleteObject(m_cBrush);
    
// TODO: Return a different brush if the default is not desired
    return hbr;
}