4-7 字体与输出文字

字体与输出文字

1.TextOut

最简单的输出字体的方式

BOOL TextOutW(
[in] HDC hdc,
[in] int x,
[in] int y,
[in] LPCWSTR lpString,
[in] int c
);

2.DrawText

在一个矩形中输出字体

int DrawText(
[in] HDC hdc,
[in, out] LPCTSTR lpchText,
[in] int cchText,
[in, out] LPRECT lprc,
[in] UINT format
);

3.SetTextColor

设置文字颜色

COLORREF SetTextColor(
[in] HDC hdc,
[in] COLORREF color
);

4.SetBkMode

设置文字背景透明

int SetBkMode(
[in] HDC hdc,
[in] int mode //常用TRANSPARENT设置透明
);

5.CreateFont

创建字体并投入使用

HFONT CreateFontW(
[in] int cHeight,
[in] int cWidth,
[in] int cEscapement,
[in] int cOrientation,
[in] int cWeight,
[in] DWORD bItalic,
[in] DWORD bUnderline,
[in] DWORD bStrikeOut,
[in] DWORD iCharSet,
[in] DWORD iOutPrecision,
[in] DWORD iClipPrecision,
[in] DWORD iQuality,
[in] DWORD iPitchAndFamily,
[in] LPCWSTR pszFaceName
);

//案例
HFONT hFont = CreateFont(45, 0, 0, 0, 0, 0, 0, 0, GB2312_CHARSET, 0, 0, 0, 0, TEXT("张山海锐线简体"));