Click here to Skip to main content
15,884,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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!
Posted

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;
}
 
Share this answer
 
v5
Comments
Member 10307999 4-Nov-13 9:43am    
Thanks for your reply, merano!
I have added the code you wrote in my code,
and in the CMyApp::InitInstance(), I use your code instead of the original code:

INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);

But the bar is still green... Did I miss something?
Thank you!!
merano 8-Nov-13 19:59pm    
Perhaps you have to handle OnCtlColor() and OnEraseBkgnd()


Here is a Example for the MFC-Way

Dialog Box with gradient background and Color changing progress bar
http://www.codeproject.com/Articles/7866/Dialog-Box-with-gradient-background-and-Color-chan
Member 10307999 9-Nov-13 7:41am    
Thank you,merano.
I will study it!!
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...

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


Where hwndProg is the HWND handle of your progress bar.
 
Share this answer
 
Comments
nv3 4-Nov-13 11:08am    
Ron, I think OP is already using a SendMessage (PBM_SETBARCOLOR, ...
But you added another important aspect: The theme mechanism is probably overriding his settings. Hence the documentation of PBM_SETBARCOLOR contains the important hint:

"When visual styles are enabled, this message has no effect."
Ron Beyer 4-Nov-13 11:23am    
Yup, which is why I added the part about disabling visual styles for that control :)
Member 10307999 5-Nov-13 9:05am    
Mr.nv3, you let me learn a lot about that!
Thank you, too!!
Member 10307999 5-Nov-13 8:58am    
Thanks for your reply, Beyer!
I have linked the uxtheme.lib and include the uxtheme.h in my xxxDlg.cpp,
and want to add the SetWindowTheme funtion in CxxxDlg::OnInitDialog().
but I created the ProgressControl by Wizard. There was not handle.
How can I create the handle about ProgressControl?
Thank you :)
Ron Beyer 5-Nov-13 9:04am    
Pretty sure you would use the GetDlgItem function http://msdn.microsoft.com/en-us/library/windows/desktop/ms645481(v=vs.85).aspx to get a control by its ID. (I would create a link, but its not letting me, so copy/paste the URL into your browser)
Not 100% sure, but check out Application.EnableVisualStyles with regards to this
 
Share this answer
 
Comments
Member 10307999 3-Nov-13 7:34am    
Thanks for your reply, Wombaticus!
But I don't know where the Application.EnableVisualStyles is.
Is it a code or attribute of Progress Control?
Thank you!!
Wombaticus 3-Nov-13 8:46am    
Within Visual Studio you can set this via the project's properties pages, where tehere is a checkbox labelled "Enable XP visual styles" - also see
http://msdn.microsoft.com/en-us/library/system.windows.forms.application.enablevisualstyles(v=vs.110).aspx
and
http://msdn.microsoft.com/en-us/library/5d1acks5(v=vs.110).aspx
Member 10307999 4-Nov-13 9:29am    
Thanks for your reply again!
Ron Beyer 3-Nov-13 20:33pm    
This is not applicable to this question. Application.EnableVisualStyles is for .NET WinForms applications, not MFC.
Member 10307999 4-Nov-13 9:29am    
Thanks for your reply, Beyer!
So the manner cannot use in MFC, right?
>_<

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900