寻找文字的宽度

时间:2010-09-12 03:00:49

标签: c++ winapi

我正在为这样的控件设置字体:

HDC hdc = GetDC(NULL);
int lfHeight = -MulDiv(szFont, GetDeviceCaps(hdc, LOGPIXELSY), 72);
ReleaseDC(NULL, hdc);
HFONT font = CreateFont(lfHeight, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Font.c_str());
SendMessage(hwnd,WM_SETFONT,(WPARAM)font,0);

控件是静态的。如何在给定字符串的静态中找到文本的宽度?

2 个答案:

答案 0 :(得分:2)

使用GetTextExtentPoint32。您需要先在DC中选择字体。

答案 1 :(得分:0)

CDC :: GetTextExtent()和CDC :: GetOutputTextExtent()应该有帮助。