{"id":40573,"date":"2004-02-17T07:00:00","date_gmt":"2004-02-17T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2004\/02\/17\/getdialogbaseunits-is-a-crock\/"},"modified":"2021-07-29T21:34:42","modified_gmt":"2021-07-30T04:34:42","slug":"getdialogbaseunits-is-a-crock","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20040217-00\/?p=40573","title":{"rendered":"GetDialogBaseUnits is a crock"},"content":{"rendered":"<p>There are two functions that let you convert dialog units (DLUs) to pixels. One is <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/api\/winuser\/nf-winuser-getdialogbaseunits\"> GetDialogBaseUnits<\/a>, which returns the base units directly (leaving you to do the math), and another is <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/api\/winuser\/nf-winuser-mapdialogrect\"> MapDialogRect<\/a>, which takes a rectangle in DLUs and returns a rectangle in pixels.<\/p>\n<p>What&#8217;s the difference?<\/p>\n<p>As you can guess from the title of this entry, GetDialogBaseUnits is a crock. Since there is no HWND parameter to GetDialogBaseUnits, it doesn&#8217;t know which dialog box&#8217;s DLUs you want to retrieve. So it guesses.<\/p>\n<p>And it always guesses wrong.<\/p>\n<p>GetDialogBaseUnits returns the dialog base units for dialog boxes that use the default system font. <i>But nobody uses the default system font any more<\/i>. <span style=\"font-family: System;\">It screams &#8220;old and dorky&#8221;.<\/span> But it remains the default for compatibility reasons. (And therefore so too does GetDialogBaseUnits.)<\/p>\n<p>Everybody selects a custom font for their dialog box, usually &#8220;MS Sans Serif 8&#8221; or possibly &#8220;Tahoma&#8221; if they are one of those hip Windows 2000 folks.<\/p>\n<p>That is why you <i>must<\/i> use MapDialogRect. The MapDialogRect function accepts a dialog box handle so it can use the correct font.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Each dialog can have different base units, so it&#8217;s meaningless to have a global converter.<\/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-40573","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Each dialog can have different base units, so it&#8217;s meaningless to have a global converter.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/40573","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=40573"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/40573\/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=40573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=40573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=40573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}