开发者

Finding width of text

开发者 https://www.devze.com 2023-01-16 07:17 出处:网络
I am setting the font for a control like this: HDC hdc = GetDC(NULL); int lfHeight = -MulDiv(szFont, GetDeviceCaps(hdc, LOGPIXELSY), 72);

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

精彩评论

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