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.
精彩评论