您的位置:首页 > 其它

VS2008下改变radio控件字体颜色存在的问题

2012-01-24 18:02 369 查看
通过OnCtlColor函数试图改变radio控件字体的颜色为白色,代码如下:

HBRUSH CXXXDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

if( pWnd ->GetDlgCtrlID() == IDC_RADIO1_ONE)
{
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(255,255,255));	//白色字体
return HBRUSH(GetStockObject(HOLLOW_BRUSH));

}
return hbr;
}


运行程序,发现无法改变Radio控件的颜色,程序运行截图如下:



经过试验,发现当程序使用的DLLs是通过Manifest指定,Radio Button就不能改变其字体颜色,不过界面有XP风格,如上图所示。

经过试验发现可以使用如下方法改变Radio Button的文本颜色:

使用"open"按钮来打开编译后生成的exe文件,打开后如下图所示:



打开RT_MANIFEST展开项“1”的内容,内容如下:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.VC90.DebugCRT" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.VC90.DebugMFC" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="x86" publicKeyToken="6595b64144ccf1df" language="*"></assemblyIdentity>
</dependentAssembly>
</dependency>
</assembly>


上面的XML格式的文件是Visual Studio 2008自动生成的,从最后部分的蓝色标记可以看出,加载的comctl32.dll 是从C:\WINDOWS\WinSxS\ 文件夹下加载的。当把这部分删除,再运行程序发现radio button的颜色变成白色了。

注:comctl32.dll 在WinSxS文件夹下x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.6028_x-ww_61e65202文件夹下。



删除操作截图:



执行后效果:



但是这种方法有一个问题,虽然radio控件的字体颜色改变了,但其界面的xp风格却没有了。

不知道大家有没有好的方法改变Radio Button的文本颜色, 而且最好还有保留XP风格,代码越简洁越好啊。

参考:http://topic.csdn.net/u/20071008/19/DE3A4292-558E-4D91-BED9-D9DC27BDBBAF.html

~~~~~~~~~~~~~~~~~~~~~

RT_MANIFEST是什么文件?

DentistryDoctor:通过Mainfest可以指定CommonControl的版本

Since Windows XP, Windows reserves a new type of resource RT_MANIFEST for SxS manifests.

Within the RT_MANIFEST resource, Windows reserves ID 1-16. A binary cannot have two IDs of resource type RT_MANIFEST within 1-16. Windows will refuse to load such binary in Windows XP/Windows Server 2003.

Only three IDs are used today in Windows.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐