

Why isn't MapDialogRect mapping dialog rectangles? - The Old New Thing
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.

Why isn’t MapDialogRect
mapping dialog rectangles?
Raymond
October 21st, 2021
A customer wanted to convert dialog box units to pixels, and since GetDialogBaseUnits
is a crock, they switched to using MapDialogRect
. However, they found that MapDialogRect
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 MapDialogRect
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 MapDialogRect
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 MapDialogRect
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 MapDialogRect
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 MapDialogRect
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
-
47
sketch-isometric - Generate Isometric views from Artboards and Rectangles in Sketch app.
-
45
flatbush - A very fast static spatial index for 2D points and rectangles in JavaScript
-
45
Flatbush A really fast static spatial index for 2D points and rectangles in JavaScript. An efficient implementation of the
-
40
Update note : Tom Elliott updated this tutorial for iOS 12, Xcode 10 and Swift 4.2. Ray Wenderlich wrote the original. This is the first in a series of Core Graphics tutorials that wi...
-
20
Note: I’m publishing this with inadequate visuals, as it’s been stuck in my queue for 3 weeks and I want to get it out there. I’d like to return to making proper images, but make no promises when. For now, a quic...
-
9
Packaging rectangles with a given width and length advertisements I have a tree with rectangles in the leaf nodes, and a 'V' or a 'H' in internal n...
-
2
An S-curved arrow is a smooth curve that connects two boxes (or rectangles) like this:Draw an S-CurveTo draw the curve, one thing that came to my mind was “
-
3
More than making rectangles
-
10
Why Hard Work Isn’t a Good ThingThe proper purpose of work is to get stuff done, not virtue signal about what good people we are
-
4
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK