win32 static control to change the text size

HWND static_ = CreateWindow(L"STATIC", NULL, WS_CHILD | WS_VISIBLE | SS_LEFT, 100, 100, 100, 16, hWnd, NULL, hInst, NULL);

LOGFONT do;
font.lfHeight = 16 ;
font.lfWidth = 0;
font.lfEscapement = 0 ;
font.lfOrientation = 0 ;
font.lfWeight = FW_BOLD;
font.lfItalic = true;
font.lfUnderline = false;
font.lfStrikeOut = false;
font.lfEscapement = 0 ;
font.lfOrientation = 0 ;
font.lfOutPrecision = OUT_DEFAULT_PRECIS;
font.lfClipPrecision = CLIP_STROKE_PRECIS | CLIP_MASK | CLIP_TT_ALWAYS | CLIP_LH_ANGLES;
font.lfQuality = ANTIALIASED_QUALITY;
font.lfPitchAndFamily = VARIABLE_PITCH | FF_DONTCARE;

HFONT hFont = ::CreateFontIndirect(&font);
SendMessage(static_, WM_SETFONT, (WPARAM)hFont, TRUE);

Because the program detects the system default font, so change the font size style, we just need to create a font, we need to define the style, such as height, weight, etc., created using WM_SETFONT set up, last used SetWindowText () to control adding text.

 

Development: Use GetTextExtentPoint32 can detect the height and width of the string.

usage:

const wchar_t* szTemp = L"This is my font.";
SIZE sizeFont;
GetTextExtentPoint32(hdc, szTemp, (int)wcslen(szTemp), &sizeFont);

Guess you like

Origin www.cnblogs.com/strive-sun/p/12221708.html