4

Why isn't MapDialogRect mapping dialog rectangles? - The Old New Thing

 3 years ago
source link: https://devblogs.microsoft.com/oldnewthing/20211021-00/?p=105818
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Why isn’t MapDialogRect mapping dialog rectangles?

Raymond

October 21st, 2021

A customer wanted to convert dialog box units to pixels, and since Get­Dialog­Base­Units is a crock, they switched to using Map­Dialog­Rect. However, they found that Map­Dialog­Rect wasn’t working either: It always returned FALSE. What’s going on?

Upon closer inspection, what’s going on is that the customer’s code wasn’t passing a dialog box handle as the first parameter to the Map­Dialog­Rect function. It was their program’s top-level window, which wasn’t a dialog.

The size of a dialog unit depends on the dialog, so the Map­Dialog­Rect function needs to know which dialog’s dialog units you want use for the conversion.

By analogy, if you have instructions like “Go exactly 17 paces north,” and you want to convert that to meters, you need to know the stride of the person who wrote those directions.

If the thing you pass to the Map­Dialog­Rect function isn’t even a dialog box at all, then the function fails with ERROR_WINDOW_NOT_DIALOG. That’s like asking someone to convert paces to meters, and saying “I got the measurements from that cave over there.” That cave tells you nothing about the stride length of the person who did the measuring.

If you don’t have a dialog box, then there’s nothing for Map­Dialog­Rect 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 Map­Dialog­Rect 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.


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK