1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
const COLORREF colorRed = RGB(255, 0, 0);
class TextWriter
{
private:
HFONT hfont;
COLORREF textColor;
public:
TextWriter() : hfont(NULL), textColor(colorRed)
{
// initialize font here (I prefer CreateFontIndirect to CreateFont,
// as it's easier to deal with unused params using memset.)
LOGFONT logFont;
memset(&logFont, 0, sizeof(logFont));
logFont.lfHeight = -48; // see PS
logFont.lfWeight = FW_BOLD;
strcpy(logFont.lfFaceName, "Broadway");
hfont = CreateFontIndirect(&logFont);
}
~TextWriter()
{
DeleteObject(hfont);
}
void WriteText(HDC _hdc, int _Xpos, int _Ypos, char *_szMessage)
{
// set text color and font
COLORREF oldTextColor = SetTextColor(_hdc, textColor);
HFONT oldHFont = (HFONT)SelectObject(_hdc, hfont);
TextOut(_hdc, _Xpos, _Ypos, _szMessage, strlen(_szMessage));
// restore text color and font
SetTextColor(_hdc, oldTextColor);
SelectObject(_hdc, oldHFont);
}
};
|