admin管理员组文章数量:1357653
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
1 Answer
Reset to default 1According 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.
本文标签: windowsInconsistency in DLUspixels ratioStack Overflow
版权声明:本文标题:windows - Inconsistency in DLUspixels ratio - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744007484a2574960.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论