{"id":188,"date":"2011-04-30T12:45:00","date_gmt":"2011-04-30T01:45:00","guid":{"rendered":"http:\/\/blog.quppa.net\/2011\/05\/01\/windows-theme-fonts\/"},"modified":"2011-04-30T12:45:00","modified_gmt":"2011-04-30T01:45:00","slug":"windows-theme-fonts","status":"publish","type":"post","link":"https:\/\/www.quppa.net\/blog\/2011\/04\/30\/windows-theme-fonts\/","title":{"rendered":"Windows Theme Fonts"},"content":{"rendered":"<blockquote><p><a href=\"https:\/\/github.com\/Quppa\/WindowsThemeFonts\" title=\"GitHub: WindowsThemeFonts\">View source on GitHub.<\/a><\/p><\/blockquote>\n<p><strong>Update:<\/strong> See <a title=\"Quppa&#39;s Blog: Windows Theme Fonts Redux &amp; Sample Code\" href=\"https:\/\/www.quppa.net\/blog\/2011\/10\/24\/windows-theme-fonts-redux-sample-code\/\">this post<\/a> for a sample implementation in WPF.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"Task Dialog (Aero)\" border=\"0\" alt=\"Screenshot of Task Dialog (Aero)\" src=\"https:\/\/www.quppa.net\/blog\/wp-content\/uploads\/TaskDialog.png\" width=\"398\" height=\"172\" \/><\/p>\n<p>Have you ever wondered how to access the various font colours and styles found throughout Windows, such as that of the \u2018<font style=\"font-family: &#39;Segoe UI&#39;, sans-serif; color: #003399; font-size: 12pt\">Main Instruction<\/font>\u2019 text in the <a title=\"MSDN: Task Dialog\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb787471(v=vs.85).aspx\">Task Dialog<\/a> shown above?<\/p>\n<p>If you are using WPF, the <a title=\"MSDN: SystemFonts Class\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.systemfonts.aspx\">SystemFonts class<\/a> might sound promising at first. However, this class only exposes the following: the icon font, caption font, small caption font, menu font, message font and status font. These aren\u2019t very exciting \u2013 in fact, they are all simply 9pt Segoe UI in Windows Vista\/7 Aero. (Aside: early Windows 8 builds use 11pt Segoe UI Semilight as the caption (and small caption) font.) For those using Win32 directly, the SystemFonts class wraps around <strike>the <\/strike><a title=\"MSDN: SystemParametersInfo Function\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms724947(v=vs.85).aspx\"><strike>SystemParametersInfo function<\/strike><\/a><strike> (specifically with the messages <\/strike><a title=\"MSDN: NONCLIENTMETRICS Structure\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ff729175(v=VS.85).aspx\"><strike>SPI_GETNONCLIENTMETRICS<\/strike><\/a><strike> and SPI_GETICONTITLELOGFONT)<\/strike> the <a title=\"MSDN: GetThemeSysFont Function\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb759783(v=vs.85).aspx\">GetThemeSysFont function<\/a>.<\/p>\n<p>MSDN offers some <a title=\"MSDN: Fonts - Guidelines: Fonts and colors\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa511282.aspx#colors\">guidance<\/a> on default fonts and colours in Windows Vista\/7: apparently \u2018Main Instruction\u2019 text is 12pt #003399 Segoe UI. This table, while helpful, is not comprehensive, and in general it\u2019s not a good idea to hard-code this kind of thing, as themes\/visual styles are liable to change.<\/p>\n<p>The keys lie in the <a title=\"MSDN: Visual Styles Reference\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb773178(v=vs.85).aspx\">Visual Styles APIs<\/a>, introduced in Windows XP. In particular, the <a title=\"MSDN: GetThemeFont Function\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb759745(v=vs.85).aspx\">GetThemeFont function<\/a> and <a title=\"MSDN: GetThemeColor Function\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb773397(v=vs.85).aspx\">GetThemeColor function<\/a> (with the TMT_TEXTCOLOR <a title=\"MSDN: Property Identifiers\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb773213(v=vs.85).aspx\">property identifier<\/a>), both found in UxTheme.dll. We simply need to specify the \u2018<a title=\"MSDN: Parts and States\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb773210(v=vs.85).aspx\">part and state<\/a>\u2019 of the control in question (these are defined in Vsstyle.h and Vssym32.h). \u2018Main Instruction\u2019 text, for example, is referenced by the TEXT_MAININSTRUCTION part in the TEXTSTYLE class.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"Task Dialog (Classic)\" border=\"0\" alt=\"Screenshot of Task Dialog (Classic)\" src=\"https:\/\/www.quppa.net\/blog\/wp-content\/uploads\/TaskDialogClassic.png\" width=\"366\" height=\"129\" \/><\/p>\n<p>Regrettably, visual styles APIs only work when visual styles are enabled (who\u2019d have thought it?). That is to say, we can\u2019t rely on them with classic themes (Windows Classic and the High Contrast themes).<\/p>\n<p>I emailed the very knowledgeable <a title=\"Larry Osterman&#39;s WebLog\" href=\"http:\/\/blogs.msdn.com\/b\/larryosterman\/\">Larry Osterman<\/a> about this, and he was kind enough to respond:<\/p>\n<blockquote>\n<p>AeroStyle.xml tells which metrics to ask for which theme parts (for the OS that matches the version of the SDK it\u2019s in), but there\u2019s no theme API support for classic modes.<\/p>\n<p>Basically they get the metric they\u2019re looking for from the AeroStyle.xml file.<\/p>\n<\/blockquote>\n<p>AeroStyle.xml is included in the latest versions of the <a title=\"Microsoft Windows Software Development Kit\" href=\"http:\/\/msdn.microsoft.com\/en-us\/windows\/bb980924\">Windows SDK<\/a>. It contains the same classes and parts and states mentioned earlier in an XML format. The \u2018MainInstruction\u2019 part in the \u2018TextStyle\u2019 class looks like this, for instance:<\/p>\n<pre class=\"lang:xml decode:true \">&lt;class name=&quot;TextStyle&quot;&gt;\n    &lt;part name=&quot;MainInstruction&quot;&gt;\n        &lt;caption&gt;\n            &lt;TextColor&gt;0 51 153&lt;\/TextColor&gt;\n            &lt;Font&gt;Segoe UI, 12, Quality:ClearType&lt;\/Font&gt;\n            &lt;ClassicValue type=&quot;TextColor&quot;&gt;WindowText&lt;\/ClassicValue&gt;\n            &lt;ClassicValue type=&quot;Font&quot;&gt;CaptionFont&lt;\/ClassicValue&gt;\n        &lt;\/caption&gt;\n    &lt;\/part&gt;\n    ...\n&lt;\/class&gt;<\/pre>\n<p>Of interest are the \u2018ClassicValue\u2019 elements. When visual styles are disabled, it seems that \u2018<font style=\"font-family: &#39;Microsoft Sans Serif&#39;, sans-serif; font-size: 9pt\"><strong>Main Instruction<\/strong><\/font>\u2019 text uses the caption font (8pt bold Microsoft Sans Serif, as it happens).<\/p>\n<p>In closing: you can use <a title=\"MSDN: GetThemeFont Function\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb759745(v=vs.85).aspx\">GetThemeFont<\/a> and <a title=\"MSDN: GetThemeColor Function\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb773397(v=vs.85).aspx\">GetThemeColor<\/a> if visual styles are enabled, but you will need look at AeroStyle.xml and hard-code the classic theme fall-back values.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>View source on GitHub. Update: See this post for a sample implementation in WPF. Have you ever wondered how to access the various font colours and styles found throughout Windows, such as that of the \u2018Main Instruction\u2019 text in the Task Dialog shown above? If you are using WPF, the SystemFonts class might sound promising &hellip; <a href=\"https:\/\/www.quppa.net\/blog\/2011\/04\/30\/windows-theme-fonts\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Windows Theme Fonts&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,9],"tags":[11,56,148,160,164,165,166,170,185],"class_list":["post-188","post","type-post","status-publish","format-standard","hentry","category-programming","category-windows","tag-aero","tag-fonts","tag-themes","tag-uxtheme","tag-visual-styles","tag-vsstyle","tag-vssym32","tag-win32","tag-wpf"],"_links":{"self":[{"href":"https:\/\/www.quppa.net\/blog\/wp-json\/wp\/v2\/posts\/188","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.quppa.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.quppa.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.quppa.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.quppa.net\/blog\/wp-json\/wp\/v2\/comments?post=188"}],"version-history":[{"count":0,"href":"https:\/\/www.quppa.net\/blog\/wp-json\/wp\/v2\/posts\/188\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.quppa.net\/blog\/wp-json\/wp\/v2\/media?parent=188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.quppa.net\/blog\/wp-json\/wp\/v2\/categories?post=188"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.quppa.net\/blog\/wp-json\/wp\/v2\/tags?post=188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}