Windows Ribbon Framework: How to change font face and size?
Asked Answered
R

3

11

How do you change the font face and font size used by the Windows Ribbon Framwork's UIRibbon?

The font used by the ribbon does not match the font the user has chosen as their Windows preferences - which is the preference my application uses. This means that as the font in Windows gets bigger, the ribbon gets smaller.

Notice how the ribbon gets smaller in each screenshot:

Segoe UI 9pt (Windows default)

alt text

Segoe UI 12pt (what i use)

alt text

Segoe UI 16pt (what customer's use)

alt text

You can see by the time we get to 16pt, the text on the ribbon is quite hard to read.

Background

The user can configure Windows to use their preferred font size, e.g.:

  • 8pt
  • 9pt
  • 12pt

and their preferred font face, e.g.:

  • MS Sans Serif
  • Microsoft Sans Serif
  • Tahoma
  • Segoe UI
  • Calibri

but the Windows Ribbon Framework by default uses a font that is not the user's preference.

Edit: Moved picture up top to catch squirrels attracted by shiny things.
Edit 2: Added another colorful picture, to get a bump.
Edit 3: Editing to get a bump
Edit 4: Adding another different picture to get a bump


The ribbon does allow customizing the colors of the ribbon.

The following code fragment is used to set the UI_PKEY_GlobalBackgroundColor of the ribbon. In this case i use a color that is the user's currently select Aero color scheme:

    IUIFramework framework;
    ...

    TColor glass = Dwm.GetColorizationColor();
    VarCast(v, ColorToUIHSB(glass), UI_PKEY_GlobalBackgroundColor.pid);

    IPropertyStore ps = framework as IPropertyStore;
    ps.SetValue(UI_PKEY_GlobalBackgroundColor, PROPVARIANT(v));
    ps.Commit;

And now the ribbon is now colored to match the color scheme of Windows:

alt text

But i can't find the option to change the font face/size.

Note: While the ribbon may honor the user's DPI settings, that isn't this question.


It works in Outlook 2010

It might be helpful to note that Outlook 2010's ribbon does honor the user's (menu) font preferences. You can get the user's menu font by calling [SystemParametersInfo][6]:

SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0));

ncm.lfMenuFont <---

9pt Outlook 2010

alt text

12pt Outlook 2010

alt text

12pt Outlook 2010

alt text

Notice the ribbon increases in size with the font size? (Which, in these resized screenshots, means that the ribbon does not get perceptually smaller.)

There are two possibilities:

  • Outlook 2010 knows how to adjust the font size in the Windows Ribbon Framework
  • Outlook 2010 does not use the Windows Ribbon Framework

Windows 7 Paint doesn't work

It's also useful to note that Windows Paint in Windows 7 does not honor the user's font preferences. This leads me to believe that it (mspaint) does use the Windows Ribbon Framework, and that the Windows Ribbon Framework doesn't support setting a font size. If if you've actually tried to be helpful, and read all the way down to here, you'll realize this is the correct answer: it's not possible. So if you want a free 300 rep, you add that as an answer.

Edit: Cross-posted to Microsoft

Keywords: Windows Ribbon Framework, change font size, UIRibbon, font face, ribbon ui, scenic ui, scenic ribbon, fluent ribbon, fluent ui, change font windows ribbon, uiribbon.h

Microsoft has a number of Ribbon implementations:


MS Paint doesn't honor menu font preference

Here's a screenshot showing my configured Windows 7 Menu Font setting of 12pt, with msPaint visible, and Outlook 2010 visible for comparison.

alt text


Sample Code

type 
    TfrmRibbonTest = class(TForm, IUIApplication)
      ...
    private
       Fframework: IUIFramework;

       {IUIApplication}
       function  OnViewChanged(viewId: SYSUINT; typeID: UI_VIEWTYPE; const view: IUnknown; verb: UI_VIEWVERB; uReasonCode: SYSINT): HResult; stdcall;
       function  OnCreateUICommand(commandId: SYSUINT; typeID: UI_COMMANDTYPE; out commandHandler: IUICommandHandler): HResult; stdcall;
       function  OnDestroyUICommand(commandId: SYSUINT; typeID: UI_COMMANDTYPE; const commandHandler: IUICommandHandler): HResult; stdcall;
    end;


procedure TForm1.Button1Click(Sender: TObject);
var
   hr: HRESULT;
begin
   Fframework := CreateComObject(CLASS_UIRibbonFramework) as IUIFramework;
   hr := Fframework.Initialize(Self.Handle, Self); //we implement IUIApplication
   OleCheck(hr);
   hr := Fframework.LoadUI(hInstance, 'APPLICATION_RIBBON');
   OleCheck(hr);
end;

function TfrmRibbonTest.OnCreateUICommand(commandId: SYSUINT; typeID: UI_COMMANDTYPE; out commandHandler: IUICommandHandler): HResult;
begin
    Result := S_OK;
end;

function TfrmRibbonTest.OnDestroyUICommand(commandId: SYSUINT; typeID: UI_COMMANDTYPE;
  const commandHandler: IUICommandHandler): HResult;
begin
    Result := S_OK;
end;

function TfrmRibbonTest.OnViewChanged(viewId: SYSUINT; typeID: UI_VIEWTYPE; const view: IUnknown; verb: UI_VIEWVERB; uReasonCode: SYSINT): HResult;
begin
    Result := S_OK;
end;

Windows Ribbon Framework 14pt != 14pt

Here is a screenshot with Windows Menu font configured for 14pt (on a 96dpi machine). Outlook 2010 is 14pt, Photoshop CS3 is 14pt. The Ribbon is...less.

alt text

See also

Ripsaw answered 17/4, 2010 at 18:33 Comment(7)
Always a pleasure to read your shiny questions. Maybe I'll get time over to investigate this.Burd
@Andreas: What the...you were around for my DwmGetColorizationColor question? Update: You were! My god, you are easily distracted by shiney things, aren't you!Ripsaw
This is Delphi? Are you using Ribbons.pas TRibbon, or the MS Ribbon? Are you using it in Prism, or in Delphi (win32)? I think Prism questions should be tagged Delphi-Prism not delphi.Carleton
This is not Delphi's ribbon control. Microsoft has 3 ribbon libraries: the Office Ribbon, the WPF Ribbon, and the Windows Ribbon Framework. i do not know which Microsoft ribbon library Delphi's control wraps (if any). But i am using the Windows Ribbon Framework, and i am using it from Delphi. After 3 months i tagged the question delphi, in an effort to get more eyeballs. Since i am using it in Delphi, the tag is somewhat relevant - and would probably attract the only crowd that uses it.Ripsaw
@Ian Boyd: I think that the TRibbon is a completely custom control, written entirely in Delphi code. Hence, it doesn't wrap any Microsoft control.Burd
Hm... This shoudln't be CW, I think... Someone has been doing too much editing...Burd
@Andreas Rejbrand You're absolutely right. It was only after it actually happened, and i researched into CW, that i realized that i didn't click it by mistake. Of course it's gone through a lot of edits; the question's been up for months! i have to keep editing to prove to people that i'm still interested in an answer.Ripsaw
W
3

Based on the behavior of Windows 7 Paint, this appears to not be possible. :)

Wiener answered 17/4, 2010 at 18:33 Comment(3)
*omg, someone answered! Oh :(* Well, you're a good person for reading the entire question; you're probably going to get the rep for doing so.Ripsaw
Damn, I was going to add this answer :)Hunt
As much as i gained useful information from bepe4711's answer, this answer is the correct one. How to change font face or size? Answer: you cannot.Ripsaw
S
4

I'm not exactly sure.. You're using the Windows Ribbon Framework in Delphi and got this strange behavior?

I've just started playing with the Framework but the Ribbon respects my preferences.

TUIApp = class(TInterfacedObject, IUIApplication)
...
gApp: TUIApp;
uiFrame: IUIFramework;
...
  CoCreateInstance(CLSID_UIRibbonFramework, nil, CLSCTX_INPROC_SERVER, IUIFramework, uiFrame);

  if Succeeded(uiFrame.Initialize(Handle, gApp)) then
  begin
     if not Succeeded(uiFrame.LoadUI(GetModuleHandle(nil), PChar('SIMPLERIBBON_RIBBON')))then
        sleep(5);
  end;

This is all what i do in my test project.

With 9pt: alt text

And with 14pt: alt text

Perhaps you change the wrong option? I've set the font size of the "Menu" element.

If you have further questions just ask...


I've just checked Win7 Paint. It does respect the user preferences. Therefore i guess you did something wrong or really changed the wrong option.


As requested the screenshot: alt text

It looks likes we did the same. This is pretty strange...

Suppositious answered 17/4, 2010 at 18:33 Comment(8)
Can you post a screenshot similiar to that i'll momentarily to my question - showing the Windows 7 Menu font setting, along with mspaint?Ripsaw
i guess....give me exact steps you're using to set your menu font in Windows 7 to 14pt?Ripsaw
i guess i did just what you did... i go to the "advanced appearance settings", select the "menu" item, change the font size and hit "apply"... and instantly (well, it took some moments) the ribbons get resized (except my ribbon; i have to restart my test application)...Suppositious
Well i found the bug. Menu font sizes 6pt..13pt are grouped into the same "size", with the ribbon not getting any larger. Each point size from 14pt up to 24pt (the largest value i can select), the Ribbon gets incrementally larger each setting. But as far as the Ribbon is concerned 9pt, 6pt and 13pt are all the same size. Can you confirm this?Ripsaw
Yes, confirmed somehow. I have a "size group", too. But it is just 6pt..10pt. With 11pt the ribbons on my system gets larger. It seems the threshold is depending on..perhaps another setting.. perhaps dpi?Suppositious
In the end, even though they ribbon might respect the user's Menu preference setting (although with a buggy implementation), it seems there is no way to set the font used by the ribbon. What is your account's DPI set to? Mine is default 96dpi at work (131dpi at home).Ripsaw
Mine is 96dpi, too. I'm not sure if the implementation is buggy. Perhaps the lower font size doesn't meet the strict design guide. Maybe there is something mentioned in the "Office Fluent UI Design Guidelines" (i took a short look at but haven't seen a hint). But yes, it behaves truly strange in a most likely buggy way..... It is not a surprise that you can't manually change the font. To be honest when i have seen your green Ribbon i thought you would use a custom implementation of it. I couldn't imagine that somebody can change the color (because of the strict guideline).Suppositious
My Windows glass is set to the Leaf color scheme, which is green. You'll notice that neither Outlook 2010, Paint, or Wordpad respect the user's (i.e. my) windows color scheme - so i had to do it for them. i can't blame them for respecting my color preferences, maybe the application itself has a user-selectable theme - at least the developer has the option to do it. But the ribbon isn't respecting the user's Windows font preferences, and doesn't allow the developer to do it for them.Ripsaw
W
3

Based on the behavior of Windows 7 Paint, this appears to not be possible. :)

Wiener answered 17/4, 2010 at 18:33 Comment(3)
*omg, someone answered! Oh :(* Well, you're a good person for reading the entire question; you're probably going to get the rep for doing so.Ripsaw
Damn, I was going to add this answer :)Hunt
As much as i gained useful information from bepe4711's answer, this answer is the correct one. How to change font face or size? Answer: you cannot.Ripsaw
H
2

If if you've actually tried to be helpful, and read all the way down to here, you'll realize this is the correct answer: it's not possible. So if you want a free 300 rep, you add that as an answer.

Since I can't post that as an answer (George got in there first :)), and since you seem to desperately need some kind of solution, I'm going to post the only other helpful answer or suggestion I can give to solve your problem: use a different ribbon control. You don't say why you're using this implementation instead of Delphi's own, or even one of the other Microsoft ones.

Two options are:

  • The inbuilt Delphi TRibbon control. I haven't used this in any publicly released apps, but I have in my own small / test programs and it is a little buggy in places. (I've seen odd drawing problems in the shortcut bar thing on the title bar, for example.) This may have improved in Delphi XE. It is possible it suffers from a similar bug. However, it's shipped with Delphi, "free" if you have Delphi, native code, VCL, and being a VCL component comes with the source so you can fix things if necessary.

  • The TMS ribbon control. I haven't used it but I have used another TMS control. That control is good, and their support fixes bugs quickly. (I've had confirmation of a bug in a day, so "immediately" counting timezones, and a new build released in a few days.)

I believe other component vendors may make ribbon components, and I do remember reading of someone making a SpTBXLib modification containing ribbon controls, but I haven't heard much about them. My suggestion is to use the TMS ribbon.

Hunt answered 17/4, 2010 at 18:33 Comment(4)
I personally wouldn't use the TRibbon. It is too buggy. If I recall correctly, I am not very found of the TMS control either. The Microsoft control, on the other hand, is very high-quality, so I understand fully that Ian wants to use this.Burd
The reasons: 1) i'm using Delphi 5. 2) TMS ribbon costs money. 3) i'm asking a question for the good of all man-kind; Delphi, .NET, C++ alike. Everyone should be a good developer, pay their taxes, do the right thing, and respect the user's font settings and color scheme.Ripsaw
Doesn't the MS control require Vista and up? If so then it must be nice to be in an environment where you are able to ignore the ancient workhorse that is XP!Cottingham
@Hunt Heffernan i don't ignore XP users. i just show a really crappy TPanel based mockup.Ripsaw

© 2022 - 2024 — McMap. All rights reserved.