如何更改进度条颜色? [英] How to change the progress bar color?

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

问题描述

我在更改进度条的颜色时遇到问题。最初我为该进度控件创建了一个实例,并在OnInitDialog()中我尝试更改进度条的颜色(最初进度条颜色为绿色颜色)。现在,我尝试使用OnInitDialog()中的这段代码将条形颜色设置为红色,如下所示:



I am having problem in changing the color of the progress bar.Initially I created an instance for that progress control and in the OnInitDialog() I am trying change the color of the progress bar (Initially the progress bar color is in green color). Now,I tried setting the bar color to red using this piece of code in the OnInitDialog() as follows,

BOOL OnInitDialog()
{
    CPropertyPage::OnInitDialog();
    m_ProgressBar->SetRange32(0,100);
    m_ProgressBar->SetPos(50);
    m_ProgressBar->SetBarColor(RGB(255,0,0));
    return TRUE;
}



这是我必须改变条形颜色的东西,我正在使用windows7操作系统。我观察到的一件事是什么时候我将主题更改为windows classic然后我能够看到我设置的颜色(在本例中为红色)。但是,如果我再回到windows7航空主题,那么又会出现绿色。



此外我甚至在这里检查了SetBkColor方法也遇到了我面临的同样问题当我使用SetBarColor()时。



任何人都可以建议我在所有类型的主题中更改条形颜色的可能方法(我认为如果它支持所有主题会很好一种主题)。


This is the thing I had to change the bar color ,and I am using windows7 OS .One thing what I observed is when I changed the theme to "windows classic" then I am able to see the color I had set (in this case red). But again if I get back to the windows7 aero theme then again green color is coming.

Moreover I even checked for SetBkColor method here also facing the same issue that I faced when I used SetBarColor().

Can anyone suggest me the possible way to change bar color in all types of theme (I think that would be fine if it support all kind of themes).

推荐答案

请参阅 http://msdn.microsoft.com/en-us/library/bb398776.aspx [ ^ ]。首先要检查文档是否值得。
See the Remarks section at http://msdn.microsoft.com/en-us/library/bb398776.aspx[^]. It's always worth checking the documentation first.


尝试其他一些链接 -

带渐变背景和颜色变化进度条的对话框 [ ^ ]

http://www.functionx.com/visualc/controls/progressbar.htm [ ^ ]
Some other links to try -
Dialog Box with gradient background and Color changing progress bar[^]
http://www.functionx.com/visualc/controls/progressbar.htm[^]


请查看是否这是值得。



进度条颜色由当前系统主题决定;没有提供自定义功能。如果用户具有Windows经典主题集,则进度条将填充系统突出显示颜色。如果用户具有Aero主题集,则使用Aero进度条样式,确实使用绿色。



如果要更改进度条的呈现方式,您需要更改系统范围的主题。当然,这不是应用程序应该做的事情 - 用户会做的事情是因为他们更喜欢不同的主题。例如,他们可能会安装一个具有蓝色进度条的主题。网上有很多例子。生成这些主题很容易;你只需在资源编辑器中打开aero.msstyle文件并修改它用来显示进度条的图像。



然而,Aero风格的进度条确实有三个不同的状态:正常,暂停和错误。在正常状态下,它充满绿色。在暂停状态下,它充满黄色,并且在错误状态下,它充满红色。



样本的航空式进度条,每个设置为一个不同的州

1)绿色进度条

2)浅黄色酒吧

3)红色进度条



但是你不应该只是因为你想让它成为某种颜色而改变进度条的状态 - 这三种状态除了它们的颜色之外还具有特定的语义含义。理论上,颜色甚至可以改变以适应不同的区域(虽然我怀疑它们是)。考虑一下Windows用户体验指南对进度条的看法;具体来说:



进度条颜色



1)仅使用红色或黄色进度条指示进度状态,而不是任务的最终结果。红色或黄色进度条表示用户需要采取某些操作来完成任务。如果条件无法恢复,请将进度条保留为绿色并显示错误消息。



2)当用户可恢复的情况发生时,将进度条变为红色阻止取得进一步进展。显示一条消息来解释问题并推荐一个解决方案。

3)将进度条变为黄色,表示用户已暂停任务或者有条件阻碍进度,但进度是仍在发生(例如,网络连接不良)。如果用户已暂停,请将暂停按钮标签更改为恢复。如果进度受阻,请显示消息以解释问题并推荐解决方案。



如果您已决定更改进度条的状态适合您的情况,您可以通过将PBM_SETSTATE消息发送到控制窗口来实现:



SendMessage(hwndProgressBar,PBM_SETSTATE,PBST_ERROR,0);



当然,它仅在启用Aero主题时有效。 经典式进度条没有任何结果。



谢谢。
Please have a look if this is worth.

The progress bar color is determined by the current system theme; there is no provided customization capability. If the user has the "Windows Classic" theme set, the progress bar fills with the system highlight color. If the user has the Aero theme set, then the Aero progress bar styles are used, which does indeed with green.

If you want to change how progress bars are rendered, you will need to change the system-wide theme. Of course, this is not something an application should do—it is something that the user would do because they prefer a different theme. For example, they might install a theme that has blue progress bars. There are plenty of examples online. It is easy to generate these themes; you simply open the aero.msstyle file in a resource editor and modify the images it uses to display progress bars.

However, the Aero-style progress bar does have three different states: normal, paused, and error. In the normal state, it is filled with green. In the paused state, it is filled with yellow, and in the error state, it is filled with red.

sample of Aero-style progress bars, each set to a different state
1)Green progress bar
2)Light Yellowish bar
3)Red Progress bar

But you shouldn't change the state of the progress bar just because you want it to be a certain color—the three states have specific semantic meanings aside from their colors. In theory, the colors could even be changed to fit different locales (although I doubt they are). Consider what the Windows User Experience Guidelines have to say on progress bars; specifically:

Progress bar colors

1)Use red or yellow progress bars only to indicate the progress status, not the final results of a task. A red or yellow progress bar indicates that users need to take some action to complete the task. If the condition isn't recoverable, leave the progress bar green and display an error message.

2)Turn the progress bar red when there is a user recoverable condition that prevents making further progress. Display a message to explain the problem and recommend a solution.
3)Turn the progress bar yellow to indicate either that the user has paused the task or that there is a condition that is impeding progress but progress is still taking place (as, for example, with poor network connectivity). If the user has paused, change the Pause button label to Resume. If progress is impeded, display a message to explain the problem and recommend a solution.

If you've decided that changing the state of the progress bar is appropriate for your situation, you can do it by sending the the PBM_SETSTATE message to the control window:

SendMessage(hwndProgressBar, PBM_SETSTATE, PBST_ERROR, 0);

Of course, it only works when the Aero theme is enabled. Nothing will happen to the "Classic"-style progress bars.

Thank you.


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

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