最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

windows - Inconsistency in DLUspixels ratio - Stack Overflow

programmeradmin2浏览0评论

Microsoft claims that MapDialogRect converts DLUs to pixels using baseunitX/4 and baseunitY/8 coefficients returned by GetDialogBaseUnits.

However, I don't see these coefficients in my tests.

For example, I have a button of 50x14 DLUs in a dialog using MS Shell Dlg font (8x16). Display scaling is 100%, DPI awareness is not enabled for the process.

Calling GetDialogBaseUnits, I get 8 for X and 16 for Y, so the coefficients should be 2,2.

But calling MapDialogRect for a rectangle of 50x14 DLUs, I get a rectangle of 75x23 pixels, so the actual coefficients are 1.5,1.5. Button size in pixels is the same.

I tested this in XP, Win 7 and Win 10, with the same results.

Why the coefficients used by MapDialogRect don't correspond to base units returned by GetDialogBaseUnits?

Microsoft claims that MapDialogRect converts DLUs to pixels using baseunitX/4 and baseunitY/8 coefficients returned by GetDialogBaseUnits.

However, I don't see these coefficients in my tests.

For example, I have a button of 50x14 DLUs in a dialog using MS Shell Dlg font (8x16). Display scaling is 100%, DPI awareness is not enabled for the process.

Calling GetDialogBaseUnits, I get 8 for X and 16 for Y, so the coefficients should be 2,2.

But calling MapDialogRect for a rectangle of 50x14 DLUs, I get a rectangle of 75x23 pixels, so the actual coefficients are 1.5,1.5. Button size in pixels is the same.

I tested this in XP, Win 7 and Win 10, with the same results.

Why the coefficients used by MapDialogRect don't correspond to base units returned by GetDialogBaseUnits?

Share Improve this question asked Mar 29 at 18:28 Eugene MuzychenkoEugene Muzychenko 3261 silver badge5 bronze badges 7
  • 2 From the documentation: The system font is used only if the dialog box template fails to specify a font. Most dialog box templates specify a font; as a result, this function is not useful for most dialog boxes. – Luke Commented Mar 29 at 22:33
  • I understand this. But the documentation of MapDialogRect says "the function retrieves the current horizontal and vertical base units for the dialog box, then applies the following formulas". Where does the function get these units from? – Eugene Muzychenko Commented Mar 30 at 9:50
  • 1 For a dialog box that does not use the system font, the base units are the average width and height, in pixels, of the characters in the dialog's font. You can use the GetTextMetrics and GetTextExtentPoint32 functions to calculate these values for a selected font. However, by using the MapDialogRect function, you can avoid errors that might result if your calculations differ from those performed by the system. – Luke Commented Mar 30 at 10:52
  • 2 devblogs.microsoft/oldnewthing/20040217-00/?p=40573 – Luke Commented Mar 30 at 18:28
  • 2 devblogs.microsoft/oldnewthing/20221103-00/?p=107350 – Luke Commented Mar 30 at 18:28
 |  Show 2 more comments

1 Answer 1

Reset to default 1

According to the blog provided by Luke: GetDialogBaseUnits is a crock

Since there is no HWND parameter to GetDialogBaseUnits, it doesn’t know which dialog box’s DLUs you want to retrieve.

That is why you must use MapDialogRect. The MapDialogRect function accepts a dialog box handle so it can use the correct font.

发布评论

评论列表(0)

  1. 暂无评论