怎么把DLU转换成像素? [英] How to convert DLU into pixels?

查看:304
本文介绍了怎么把DLU转换成像素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Microsoft在其UI准则中使用对话框长度单位(DLU).如何将它们转换为像素?

Microsoft uses dialog length units (DLU) in their guidelines for UI. How can I convert them into pixels?

据我所知,DLU取决于系统字体大小.您能建议在Delphi for Win32中进行这种转换的一些简单方法吗?

As I know, DLU depending on system font size. Can you advise some simple method of such conversion in Delphi for Win32?

推荐答案

您应使用

You should use the MapDialogRect() function.

以对话框为单位传入RECT,并以像素为单位返回等效的RECT.请注意,您需要对话框的句柄以便为MapDialogRect()提供足够的上下文.该功能需要知道字体才能执行转换.

Pass in a RECT in dialog units, and the equivalent RECT in pixel units is returned. Note that you need a handle to a dialog in order to give MapDialogRect() sufficient context. The function needs to know the font in order to perform the conversion.

如果您很想使用 GetDialogBaseUnits() ,请记住Raymond Chen所说的话, GetDialogBaseUnits是一个缸.

您可以从此项的标题中猜测,GetDialogBaseUnits是一个 缸.由于没有GetDialogBaseUnits的HWND参数,因此它 不知道您要检索哪个对话框的DLU.所以 猜.

As you can guess from the title of this entry, GetDialogBaseUnits is a crock. Since there is no HWND parameter to GetDialogBaseUnits, it doesn't know which dialog box's DLUs you want to retrieve. So it guesses.

它总是猜错了.

GetDialogBaseUnits返回对话框的对话框基本单位, 使用默认的系统字体.但是没有人使用默认的系统字体 还有.它尖叫着老而笨拙".但是它仍然是默认值 兼容性原因. (因此,GetDialogBaseUnits也是如此.)

GetDialogBaseUnits returns the dialog base units for dialog boxes that use the default system font. But nobody uses the default system font any more. It screams "old and dorky". But it remains the default for compatibility reasons. (And therefore so too does GetDialogBaseUnits.)

如果必须从DLU计算像素尺寸,并且没有对话框的句柄,则必须使用此处概述的方法:

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

但是,您在注释中明确指出,对于您的问题,实际上并不需要将DLU转换为像素.您可以使用Delphi的内置表单缩放功能来确保您的表单的大小适合当前的字体缩放比例.

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.

这篇关于怎么把DLU转换成像素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆