In the past, I rarely used VC for UI work. When I started to use VC for UI, I encountered some confusing problems.
In the dialog box editor, I initially thought that all the control length units were in pixels, and later I found that the size of the control show was significantly larger than that of the corresponding pixel, only query data can find that these lengths are in the unit of dlu.
What is dlu and dlu is the abbreviation of dialog unit, which literally means the unit of the dialog box,
How is dlu defined? This is related to the basic unit of the dialog base unit-dialog box. The basic unit of the dialog box is related to the font selected in the dialog box, the horizontal dialog base unit of the unit is probably the prime number of all characters in the font.Average width(Pixel unit), the pixel Prime Number of the vertical dialog base unit is probably all characters in the fontAverage Length(Pixel unit ).
The prime number of horizontal dlu is horizontal dlbu/4, while the prime number of horizontal dlu is vertical dlbu/8.
Aha, this is really complicated, but in general, horizontal dlu and vertical dlu are the same. When the system font and font size are 8, A dlu corresponds1.5Pixel. As for the use of other fonts and sizes, there are related APIs that can be calculated, but it is really troublesome. Fortunately, there is no chance to use it. You can check msdn if necessary.
Why is the unit of dlu used in the dialog box Editor (the length of the record to the RC resource file is also in the unit of dlu)? Naturally, when the font of the dialog box is changed,ProgramWhen loading the dialog box, the relationship between the dlu and the pixel is calculated, so as to dynamically define the size of the dialog box and the control, avoiding changing the font resulting in the string exceeding the preset length and thus invisible to the subsequent part.