Windows Ribbon Framework:如何更改字体和大小?
如何更改 Windows Ribbon Framwork 的 UIRibbon?
功能区使用的字体与用户选择作为其 Windows 首选项的字体不匹配 - 这是我的应用程序使用的首选项。这意味着随着 Windows 中的字体变大,功能区会变小。
请注意每个屏幕截图中的功能区如何变小:
Segoe UI 9pt(Windows 默认)
Segoe UI 12pt(我使用的) )
Segoe UI 16pt(客户的用途)
您可以看到,当我们达到 16pt 时,功能区上的文本很难阅读。
背景
用户可以将 Windows 配置为使用他们喜欢的字体大小,例如:
- 8pt
- 9pt
- 12pt
和他们喜欢的字体,例如:
- MS Sans Serif
- Microsoft Sans Serif
- Tahoma
- Segoe UI
- Calibri
但默认情况下,Windows 功能区框架使用不用户偏好的字体。
编辑:将图片移至顶部以捕捉被闪亮物体吸引的松鼠。
编辑2:添加了另一张彩色图片,以获得凹凸。
编辑 3: 进行编辑以获得凹凸
编辑4:添加另一张不同的图片以获得凹凸功能
区确实允许自定义功能区的颜色。
以下代码片段用于设置功能区的UI_PKEY_GlobalBackgroundColor
。在本例中,我使用用户当前选择的 Aero 配色方案的颜色:
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;
现在功能区的颜色与 Windows 的配色方案相匹配:
但我找不到更改字体/大小的选项。
注意:虽然功能区可能遵循用户的 DPI 设置,但这不是这个问题。
它适用于 Outlook 2010
注意到 Outlook 2010 的功能区确实尊重用户(菜单)字体首选项可能会有所帮助。您可以通过调用[SystemParametersInfo][6]
来获取用户的菜单字体:
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0));
ncm.lfMenuFont <---
9pt Outlook 2010
12 磅 Outlook 2010
12 磅 Outlook 2010
注意到功能区随着字体大小而增大了吗? (在这些调整大小的屏幕截图中,这意味着功能区不会在视觉上变小。)
有两种可能性:
- Outlook 2010 知道如何在 Windows 功能区框架中调整字体大小
- Outlook 2010 不使用 Windows 功能区框架
Windows 7 画图不起作用
值得注意的是,Windows 7 中的 Windows Paint 确实不尊重用户的字体首选项。这让我相信它(mspaint)确实使用了 Windows Ribbon Framework,并且 Windows Ribbon Framework 不支持设置字体大小。如果您确实尝试过提供帮助,并一直阅读到这里,您就会意识到这是正确的答案:这是不可能的。因此,如果您想要免费的 300 次代表,您可以将其添加为答案。
编辑: 交叉发布到 Microsoft
关键字: Windows Ribbon Framework、更改字体大小、UIRibbon、字体、功能区 ui、风景 ui、风景功能区、流畅功能区、流畅 ui、更改字体窗口功能区、uiribbon.h
Microsoft 有许多功能区实现:
- Windows 功能区框架 - 原生
- MFC 的 CMFCRibbonBar - MFC
- 功能区 (WPF) - WPF
- ribbon.codeplex.com - WinForms(不受支持)
MS Paint 不支持菜单字体首选项
以下屏幕截图显示了我配置的 Windows 7 菜单字体
示例代码
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
这是带有 Windows Menu 字体的屏幕截图配置为 14pt(在 96dpi 机器上)。 Outlook 2010 是 14pt,Photoshop CS3 是 14pt。功能区...更少。
另请参阅
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)
Segoe UI 12pt (what i use)
Segoe UI 16pt (what customer's use)
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:
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
12pt Outlook 2010
12pt Outlook 2010
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:
- Windows Ribbon Framework - native
- CMFCRibbonBar for MFC - MFC
- Ribbon (WPF) - WPF
- ribbon.codeplex.com - WinForms (unsupported)
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.
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.
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不太确定..您在 Delphi 中使用 Windows Ribbon Framework 并得到了这种奇怪的行为?
我刚刚开始使用框架,但功能区尊重我的喜好。
这就是我在测试项目中所做的全部工作。
9分:
14pt:
也许您更改了错误的选项?我已经设置了“菜单”元素的字体大小。
如果您还有其他问题,请询问...
我刚刚检查了 Win7 画图。它确实尊重用户的偏好。因此我猜你做错了什么或者确实改变了错误的选项。
按照要求截图:
看起来我们也做了同样的事情。这很奇怪......
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.
This is all what i do in my test project.
With 9pt:
And with 14pt:
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:
It looks likes we did the same. This is pretty strange...
根据 Windows 7 Paint 的行为,这似乎是不可能的。 :)
Based on the behavior of Windows 7 Paint, this appears to not be possible. :)
由于我无法将其作为答案发布(乔治首先进入那里:)),并且由于您似乎迫切需要某种解决方案,因此我将发布仅其他有用的答案或者我可以给出解决您问题的建议:使用不同的功能区控件。您没有说明为什么使用此实现而不是 Delphi 自己的实现,甚至是其他 Microsoft 实现之一。
两个选项是:
内置 Delphi TRibbon 控件。我没有在任何公开发布的应用程序中使用过它,但我在自己的小/测试程序中使用过它,并且它在某些地方有点问题。 (例如,我在标题栏上的快捷方式栏上看到了奇怪的绘图问题。)这个 可能在 Delphi XE 中有所改进。它可能遇到类似的错误。然而,它是随 Delphi 一起提供的,如果您有 Delphi、本机代码、VCL,并且作为 VCL 组件附带源代码,那么它是“免费”的,因此您可以在必要时修复问题。
TMS 功能区控件。我没有使用过它,但我使用过另一个 TMS 控件。这种控制很好,他们的支持可以快速修复错误。 (我在一天内就确认了一个错误,因此“立即”计算时区,并在几天内发布了新版本。)
我相信其他组件供应商可能会制作功能区组件,而且我确实记得读过有人制作了SpTBXLib 修改包含功能区控件,但我还没有听说过它们。我的建议是使用 TMS 功能区。
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.