首页 > 代码库 > CProgressCtrl::SetBarColor无效的缘由

CProgressCtrl::SetBarColor无效的缘由

写一个格斗游戏,想用CProgressCtrl作血条和魔法条,需要设置颜色,网上找到2种本质一样的方法:

// 创建进度条
m_leftHp.Create(WS_CHILD | WS_VISIBLE | PBS_SMOOTH, CRect(80, 20, 400, 45), this, 123); 

方法1:

m_leftHp.SendMessage(PBM_SETBKCOLOR, 0, RGB(10, 10, 10));

方法2:

m_leftHp.SetBarColor(RGB(255, 0, 0));

说这些代码放到OnCreate()里,我照例做了都不行,在网上搜了N边,问了几个网站无果的情况下,到MSDN找CProgressCtrl::SetBarColor函数,发现Example里有段注释:

// Set the progress bar color to red, green, blue, or  
// the system default. The SetBarColor method has an  
// effect only if the Windows system theme is Classic.

Classic Style……我忽然明白了,之前为了创建的按钮什么的好看点,在stdafx.h里添加了如下代码:

// 使用带主题的控件
//#if defined _M_IA64 // 安腾平台
//#pragma comment(linker, "/MANIFESTDEPENDENCY:" //"\"type='Win32' " //"name='Microsoft.Windows.Common-Controls' version='6.0.0.0' " //"processorArchitecture='IA64' " //"publicKeyToken='6595B64144CCF1DF'\"")
//#elif defined _M_AMD64 // 64位平台
//#pragma comment(linker, "/MANIFESTDEPENDENCY:" //"\"type='Win32' " //"name='Microsoft.Windows.Common-Controls' version='6.0.0.0' " //"processorArchitecture='AMD64' " //"publicKeyToken='6595B64144CCF1DF'\"")
//#elif defined _M_IX86 // 32位平台
//#pragma comment(linker, "/MANIFESTDEPENDENCY:" //"\"type='Win32' " //"name='Microsoft.Windows.Common-Controls' version='6.0.0.0' " //"processorArchitecture='X86' " //"publicKeyToken='6595B64144CCF1DF'\"")
//#elif defined _M_ARM // ARM平台
//#pragma comment(linker, "/MANIFESTDEPENDENCY:" //"\"type='Win32' " //"name='Microsoft.Windows.Common-Controls' version='6.0.0.0' " //"processorArchitecture='ARM' " //"publicKeyToken='6595B64144CCF1DF'\"")
//#else // 其它平台
//#pragma comment(linker, "/MANIFESTDEPENDENCY:" //"\"type='Win32' " //"name='Microsoft.Windows.Common-Controls' version='6.0.0.0' " //"processorArchitecture='*' " //"publicKeyToken='6595B64144CCF1DF'\"")
//#endif // MANIFEST

这样设置后,就不是Classic Style了,取之,进度条就有颜色了……

可是……如何在不改变风格的情况下设置进度条颜色呢?我还没找到答案……