{"id":413,"date":"2014-07-24T07:00:00","date_gmt":"2014-07-24T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2014\/07\/24\/when-i-send-a-wm_getfont-message-to-a-window-why-dont-i-get-a-font\/"},"modified":"2014-07-24T07:00:00","modified_gmt":"2014-07-24T07:00:00","slug":"when-i-send-a-wm_getfont-message-to-a-window-why-dont-i-get-a-font","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20140724-00\/?p=413","title":{"rendered":"When I send a WM_GETFONT message to a window, why don&#039;t I get a font?"},"content":{"rendered":"<p>A customer reported that the <code>WM_GET&shy;FONT<\/code> message was not working. Specifically, they sent the message to a window, and they can plainly see that the window is rendering with a particular font, yet the <code>WM_GET&shy;FONT<\/code> message returns 0. Why isn&#8217;t the window returning the correct font handle?\n The <code>WM_SET&shy;FONT<\/code> and <code>WM_GET&shy;FONT<\/code> messages are not mandatory. A window may choose to support them, or it may choose not to, or it may even choose to support one but not the other. (Though if it supports <code>WM_SET&shy;FONT<\/code>, it probably ought to support <code>WM_GET&shy;FONT<\/code>.)\n For example, our <a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2003\/07\/25\/54582.aspx\"> scroll bar program<\/a> creates a custom font for the items in the list, but it does not implement the <code>WM_SET&shy;FONT<\/code> or <code>WM_GET&shy;FONT<\/code> messages. If you try to change the font via <code>WM_SET&shy;FONT<\/code>, nothing happens. If you ask for the font via <code>WM_GET&shy;FONT<\/code>, you get nothing back.\n A control might ignore your attempt to change the font if it already has its own notion of what font it should be using. Or maybe the control shows content in multiple fonts, so the concept of &#8220;the&#8221; font does not map well to the render model. (What would <code>WM_GET&shy;FONT<\/code> on an HTML control return?) Or maybe the control doesn&#8217;t use GDI fonts at all. (Maybe it uses Direct&shy;Write.)\n That&#8217;s one of the reasons why <a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2008\/09\/12\/8945692.aspx\"> the rules for the <code>WM_SET&shy;FONT<\/code><\/a> are set up the way they are. Since there is no way to tell whether a window did anything in response to the <code>WM_SET&shy;FONT<\/code> message, there would be no way to know whether responsibility for destroying the font should be transferred to the control or retained by the caller.<\/p>\n<p> Controls that are designed to be used in dialog boxes are the ones most likely to support the <code>WM_SET&shy;FONT<\/code> message, since that&#8217;s the message the dialog manager uses to tell each control the font specified in the dialog box template. The hope is that all of the controls will respect that font, so that the controls on the dialog box have a consistent appearance. But there&#8217;s nothing preventing a control from saying, &#8220;Screw you. I&#8217;m drawing with OCR-A and there&#8217;s nothing you can do to stop me.&#8221; <\/p>\n","protected":false},"excerpt":{"rendered":"<p>A customer reported that the WM_GET&shy;FONT message was not working. Specifically, they sent the message to a window, and they can plainly see that the window is rendering with a particular font, yet the WM_GET&shy;FONT message returns 0. Why isn&#8217;t the window returning the correct font handle? The WM_SET&shy;FONT and WM_GET&shy;FONT messages are not mandatory. [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-413","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>A customer reported that the WM_GET&shy;FONT message was not working. Specifically, they sent the message to a window, and they can plainly see that the window is rendering with a particular font, yet the WM_GET&shy;FONT message returns 0. Why isn&#8217;t the window returning the correct font handle? The WM_SET&shy;FONT and WM_GET&shy;FONT messages are not mandatory. [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/413","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=413"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/413\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}