Click here to Skip to main content
16,020,182 members
Please Sign up or sign in to vote.
4.67/5 (3 votes)
See more:
hi, i'm using vs2010 and have an MFC app with a ribbon bar

i'm using CMFCRibbonSlider but i think this is a general question for any ribbon control

i would like to change the look of the slider. i'm using it as a volume control slide and want the slider part to look like a stretched out triangle (like vlc's volume control) and the zoom buttons to look like small speaker and big speaker

normally i would make a derived class from CMFCRibbonSlider and override OnDrawRibbonSliderZoomButton for example but all the controls in my app are created like this
MIDL
m_wndRibbonBar.Create(this);
m_wndRibbonBar.LoadFromResource(IDR_RIBBON);

from the resources so i have no way that i can think of to change any of the behavior of the control.

do you think there is a way to somehow add your own customs controls to the ribbon and still use the ribbon designer vs. creating the ribbon programmatically?

for example, suppose i get the crate do its job but after creating i somehow override CMFCRibbonSlider::OnDraw(CDC* pDC) and point it to my own version of CMFCRibbonSlider::OnDraw(CDC* pDC)where i can do whatever i want.

it this legitimate c++ programming? how would one override a class at runtime?

P.S. i tried simply writing my own On Draw function
C#
void CMFCRibbonSlider::OnDraw(CDC* pDC)
{
    TRACE("this is my CMFCRibbonSlider::OnDraw\n");
}


which compiles (strangely) but does not get called

[edit: moved form answer]
The question is: How to get the ribbon designer to recognize the new class?
[/end of edit]
Posted
Updated 28-Aug-12 5:37am
v4

You need to create your own class derived from the CMFCRibbonSlider and override the functions that you want to handle.
 
Share this answer
 
Comments
Maciej Los 28-Aug-12 11:36am    
Cooment from OP:
i know i can do that but the question is how to get the ribbon designer to recognize the new class?
i don't want to have to code the ribbon layout in c code, i like the ribbon designer GUI
Richard MacCutchan 28-Aug-12 13:33pm    
I don't know of any way to change the designer as it is part of Visual Studio and not easily customisable. You could always try looking at the VCProjectEngine namespace to see if it's possible.
I had the exact same problem and got the answer by asking on an MSDN forum. Like you, I could not figure out how use a to derived a ribbon control class, especially when using the ribbon designer, since the ribbon controls are instantiated deep within MFC. The solution was easy once pointed out to me: After the ribbon has been created, enumerate the child windows to find the up-down control(s), then subclass them and intercept the UDN_DELTAPOS. You can see the full answer by searching on the MSDN forums for my forum name, johnsssl. Oh, after getting the up-down control's window, you get its parent window, and subclass the parent, since the control notifications go to the parent.
 
Share this answer
 
v2

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