MFC: write text using stock font, but bold
This is an easy way to draw some text with a default font.
pDC->SelectObject(GetStockObject(DEFAULT_GUI_FONT开发者_运维问答));
pDC->SetTextColor(::GetSysColor(COLOR_WINDOWTEXT));
pDC->DrawText(text, -1, rc, DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER | DT_END_ELLIPSIS);
How can I do exactly the same, but in bold type... same font but bold? Can it be done without creating custom CFont object?
CFont* pOldFont = pDC->GetCurrentFont();
LOGFONT logFont;
pOldFont->GetLogFont(&logFont);
logFont.lfWeight = FW_BOLD;
CFont newFont;
newFont.CreateFontIndirect(&logFont);
pDC->SelectObject(&newFont);
pDC->DrawText();
pDC->SelectObject(pOldFont);
Get the font data for the stock font into a LOGFONT struct (GetObject() in plain GDI). Change the weight parameter to bold. Use CreateFontIndirect() to make a font from that LOGFONT struct. Select the font into the device context.
Then draw the text as usual.
精彩评论