开发者

Finding width of text

I am setting the font for a control like this:

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);

The cont开发者_如何学运维rol is a static. How would I find the width of the text in the static for a given string?


Use GetTextExtentPoint32. You'll need to select the font into the DC first.


CDC::GetTextExtent() and CDC::GetOutputTextExtent() should help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜