{"id":105818,"date":"2021-10-21T07:00:00","date_gmt":"2021-10-21T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=105818"},"modified":"2021-10-21T06:25:52","modified_gmt":"2021-10-21T13:25:52","slug":"20211021-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20211021-00\/?p=105818","title":{"rendered":"Why isn&#8217;t <CODE>MapDialogRect<\/CODE> mapping dialog rectangles?"},"content":{"rendered":"<p>A customer wanted to convert dialog box units to pixels, and since <a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20040217-00\/?p=40573\"> <code>Get\u00adDialog\u00adBase\u00adUnits<\/code> is a crock<\/a>, they switched to using <code>Map\u00adDialog\u00adRect<\/code>. However, they found that <code>Map\u00adDialog\u00adRect<\/code> wasn&#8217;t working either: It always returned <code>FALSE<\/code>. What&#8217;s going on?<\/p>\n<p>Upon closer inspection, what&#8217;s going on is that the customer&#8217;s code wasn&#8217;t passing a dialog box handle as the first parameter to the <code>Map\u00adDialog\u00adRect<\/code> function. It was their program&#8217;s top-level window, which wasn&#8217;t a dialog.<\/p>\n<p>The size of a dialog unit depends on the dialog, so the <code>Map\u00adDialog\u00adRect<\/code> function needs to know <i>which<\/i> dialog&#8217;s dialog units you want use for the conversion.<\/p>\n<p>By analogy, if you have instructions like &#8220;Go exactly 17 paces north,&#8221; and you want to convert that to meters, you need to know the stride of the person who wrote those directions.<\/p>\n<p>If the thing you pass to the <code>Map\u00adDialog\u00adRect<\/code> function isn&#8217;t even a dialog box at all, then the function fails with <code>ERROR_<\/code><code>WINDOW_<\/code><code>NOT_<\/code><code>DIALOG<\/code>. That&#8217;s like asking someone to convert paces to meters, and saying &#8220;I got the measurements from that cave over there.&#8221; That cave tells you nothing about the stride length of the person who did the measuring.<\/p>\n<p>If you don&#8217;t have a dialog box, then there&#8217;s nothing for <code>Map\u00adDialog\u00adRect<\/code> to use as a basis for calculation. Either find (or create) a dialog box whose font matches the one you want to map, or replicate the calculations of <code>Map\u00adDialog\u00adRect<\/code> without an actual dialog box: Get the font for your hypothetical dialog box and determine the average character dimensions for that font, and then plug them into the formulas given in the documentation.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Maybe you don&#8217;t have a dialog.<\/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-105818","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Maybe you don&#8217;t have a dialog.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/105818","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=105818"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/105818\/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=105818"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=105818"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=105818"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}