为什么我似乎得到了 TEXTMETRIC 结构的 tmHeight 成员的像素大小,而不是逻辑单位?
Why do I seem to get TEXTMETRIC structure's tmHeight member's size in pixel, but not in logical units?
Windows GDI 文档明确指出
All sizes are specified in logical units; that is, they depend on the current mapping mode of the display context.
当我在 WndProc 中做这样的事情时:
HDC hdc = GetDC(hwnd);
TEXTMETRIC textmetric;
GetTextMetrics(hdc, &textmetric);
tmHeight等于16点,也就是
16 * GetDeviceCaps(hdc, LOGPIXELSY) / 72
像素。当然,如果我对这篇文章的理解是正确的:https://docs.microsoft.com/en-us/windows/win32/learnwin32/dpi-and-device-independent-pixels
但是当我用一些文本创建静态编辑控件并将控件高度指定为 16 像素时,它奇怪地匹配文本字体高度。
我的问题是,为什么这个字体应该有 16 * 96 / 72 像素的大小,但实际上适合 16 像素?
根据 TEXTMETRICA 文档:
The TEXTMETRIC structure contains basic information about a physical
font. All sizes are specified in logical units.
所以tmHeight
是逻辑单位。您不必使用以下代码来获取字符的高度。
lfHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
且系统默认映射模式为MM_TEXT。
Each unit in page space is mapped to one pixel; that is, no scaling is
performed at all. When no translation is in effect (this is the
default), page space in the MM_TEXT mapping mode is equivalent to
physical device space. The value of x increases from left to right.
The value of y increases from top to bottom.
所以通过映射变换,字符的像素高度等于静态控件的高度。
Windows GDI 文档明确指出
All sizes are specified in logical units; that is, they depend on the current mapping mode of the display context.
当我在 WndProc 中做这样的事情时:
HDC hdc = GetDC(hwnd);
TEXTMETRIC textmetric;
GetTextMetrics(hdc, &textmetric);
tmHeight等于16点,也就是
16 * GetDeviceCaps(hdc, LOGPIXELSY) / 72
像素。当然,如果我对这篇文章的理解是正确的:https://docs.microsoft.com/en-us/windows/win32/learnwin32/dpi-and-device-independent-pixels
但是当我用一些文本创建静态编辑控件并将控件高度指定为 16 像素时,它奇怪地匹配文本字体高度。
我的问题是,为什么这个字体应该有 16 * 96 / 72 像素的大小,但实际上适合 16 像素?
根据 TEXTMETRICA 文档:
The TEXTMETRIC structure contains basic information about a physical font. All sizes are specified in logical units.
所以tmHeight
是逻辑单位。您不必使用以下代码来获取字符的高度。
lfHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
且系统默认映射模式为MM_TEXT。
Each unit in page space is mapped to one pixel; that is, no scaling is performed at all. When no translation is in effect (this is the default), page space in the MM_TEXT mapping mode is equivalent to physical device space. The value of x increases from left to right. The value of y increases from top to bottom.
所以通过映射变换,字符的像素高度等于静态控件的高度。