Winapi获取以像素为单位的字符串宽度 [英] Winapi get string width in pixels
本文介绍了Winapi获取以像素为单位的字符串宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建一种方法,该方法为我提供以像素为单位的字符串宽度.到目前为止,我的代码:
I'm trying to create a method that gives me the width of a string in pixels. My code so far:
inline void getTextWidth(HWND hwnd char* text) {
SIZE textSize;
GetTextExtentPoint32(GetDC(hwnd), text, strlen(text), &textSize);
return ?;
}
I know that I should use LPtoDP
(MSDN), but at wants points as parameters and not the SIZE that GetTextExtentPoint32 returns.
我该如何转换呢?
推荐答案
SIZE
结构包含高度和宽度.由于您只关心宽度,因此您显然需要 LPtoDP(textSize.cx);
.
The SIZE
structure contains both a height and a width. Since you only care about the width, you apparently want LPtoDP(textSize.cx);
.
这篇关于Winapi获取以像素为单位的字符串宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文