
HDC hdc = ::GetDC(m_hWnd);
LOGFONT lf = { 0 };
lf.lfWeight = 16; //平均宽度
lf.lfHeight = 40;//字体高度
lf.lfCharSet = GB2312_CHARSET;//字符集
lstrcpy(lf.lfFaceName, _T("宋体"));
HFONT hfont = ::CreateFontIndirect(&lf);//创建逻辑字体
HFONT holdfont = (HFONT)SelectObject(hdc, hfont);
COLORREF oldcolor=GetTextColor(hdc);//获取DC中的文本颜色
COLORREF color1= SetTextColor(hdc, RGB(0,0,255));//设置指定DC中的文字颜色
int i=SetBkMode(hdc,TRANSPARENT);//设置指定DC的背景混合模式
RECT rect = { 50,50,400,400 };
TCHAR ch[] = _T("GDI练习");
BOOL b=TextOut(hdc,100,100,ch, _tcslen(ch));//绘制文本
/*
参数1:HDC hdc
参数2:int nXStart 字符串的开始位置 x坐标
参数3:int nYStart 字符串的开始位置 y坐标
参数4:LPCTSTR lpString 字符串
参数5:int cbString 字符串中字符的个数
返回值:如果函数调用成功,返回值为非零值。
如果函数调用失败,返回值为0
*/
SetTextColor(hdc, color1);//还原
SelectObject(hdc, holdfont);
DeleteObject(hfont);
