win32改变静态控件的文本大小
作者:互联网
HWND static_ = CreateWindow(L"STATIC", NULL, WS_CHILD | WS_VISIBLE | SS_LEFT, 100, 100, 100, 16, hWnd, NULL, hInst, NULL); LOGFONT font; 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);
因为程序会检测系统默认的字体,所以改变字体的大小样式,我们只需要创建一个font,定义我们需要的样式,比如高度,粗细等等,创建完毕后使用WM_SETFONT设置,最后使用SetWindowText()给控件添加文本。
拓展: 使用GetTextExtentPoint32可以检测字符串的高度和宽度。
用法:
const wchar_t* szTemp = L"This is my font."; SIZE sizeFont; GetTextExtentPoint32(hdc, szTemp, (int)wcslen(szTemp), &sizeFont);
标签:控件,font,CLIP,szTemp,NULL,win32,100,文本 来源: https://www.cnblogs.com/strive-sun/p/12221708.html