无法更改进度控制的颜色 [英] Can't change the color of Progress Control

查看:52
本文介绍了无法更改进度控制的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我创建了一个Progress控件,并通过向导创建了[CProgressCtrl m_pro]。

我想改变Progress Control的颜色,所以我在CxxxDlg :: OnInitDialog中添加了代码:



COLORREF clrBar = RGB(255,0,0);

m_pro.SendMessage(PBM_SETBARCOLOR,0,(LPARAM)clrBar);




但它不起作用......颜色没变。

我错过了什么(也许是Progress Control的属性)?



感谢您的帮助,
谢谢!

Hi all,

I have created a Progress control, and created [CProgressCtrl m_pro] by Wizard.
I want to change the color of Progress Control so I added the code in CxxxDlg::OnInitDialog :

COLORREF clrBar = RGB(255, 0, 0);
m_pro.SendMessage(PBM_SETBARCOLOR, 0, (LPARAM) clrBar);


But it's not working...The color was not change.
Did I miss something(maybe the attribute of Progress Control)?

Thanks for your help,
thank you!

推荐答案

这是启用C ++ Visual-Styles的代码


$ b stdafx.h中的$ b:

Here is the Code to enable Visual-Styles for C++

in stdafx.h:
#include <commctrl.h>

#pragma comment (lib, "comctl32.lib ")
    
// Ensure that version 6 of ComCtl32.dll is used:
#pragma comment(linker, "\"/manifestdependency:type='win32'\
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")







BOOL CMyApp::InitInstance()
{
    INITCOMMONCONTROLSEX CommonControls;
    CommonControls.dwSize = sizeof (INITCOMMONCONTROLSEX);
    CommonControls.dwICC = ICC_STANDARD_CLASSES;
    InitCommonControlsEx (&CommonControls);

   ...

   return TRUE;
}


您需要使用SendMessage API向进度条控件发送消息。 这是一个答案 [ ^ ]如何改变颜色。



第二次看它虽然它几乎与你正在做的一样,所以你可能需要添加这样的东西来禁用你的进度条的主题。你必须包括uxtheme.h和uxtheme.lib ...



You need to send a message to the progressbar control using the SendMessage API. Here is an answer[^] on StackOverflow that shows pretty well how to change the color.

On second look though its almost exactly the same that you are doing, so you may need to add something like this to disable themeing for your progress bar. You will have to include uxtheme.h and uxtheme.lib...

SetWindowTheme(hwndProg, _T(""), _T(""));





其中 hwndProg 是进度条的HWND句柄。



Where hwndProg is the HWND handle of your progress bar.


不是100%肯定,但请查看与此相关的Application.EnableVisualStyles
Not 100% sure, but check out Application.EnableVisualStyles with regards to this


这篇关于无法更改进度控制的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆