Microsoft uses dialog length units (DLU) in their guidelines for UI. How can I convert them into pixels?
As I know, DLU depending on system font size. Can you advise some simple method of such conversion in Delphi for Win32?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You should use the
MapDialogRect()function.Pass in a
RECTin dialog units, and the equivalentRECTin pixel units is returned. Note that you need a handle to a dialog in order to giveMapDialogRect()sufficient context. The function needs to know the font in order to perform the conversion.In case you are tempted to use
GetDialogBaseUnits(), remember what Raymond Chen said, GetDialogBaseUnits is a crock.If you have to calculate pixel dimensions from DLUs, and you don’t have a handle to a dialog, then you must use the method outlined here: How To Calculate Dialog Base Units with Non-System-Based Font
However, you made it clear in the comments that, for your problem, you do not actually need to convert from DLUs to pixels. You can use Delphi’s built in form scaling to ensure that your forms are sized appropriately for the prevailing font scaling.