1.画背景颜色
HDC hdc=::GetDC(h1);
RECT rt;
rt.top=0;
rt.left=20;
rt.bottom=1;
rt.right=500;
//GetClientRect(h1, &rt);
HBRUSH hBrush=CreateSolidBrush(RGB(0,0,0));
hBrush=(HBRUSH)SelectObject(hdc, hBrush);
PatBlt(hdc, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, PATCOPY);
hBrush=(HBRUSH)SelectObject(hdc, hBrush);
DeleteObject(hBrush);
::ReleaseDC(h1,hdc);
2.画背景图
CDC memdc;
memdc.CreateCompatibleDC(&dc);//创建兼容DC
CBitmap bkg;
bkg.LoadBitmap(IDB_BITMAP1);//载入位图
BITMAP bkginfo;
bkg.GetBitmap(&bkginfo);//获取位图信息
memdc.SelectObject(&bkg);
RECT rect;
GetWindowRect(&rect);//获取对话框信息
dc.StretchBlt(0,0,rect.right-rect.left,rect.bottom-rect.top,&memdc,0,0,bkginfo.bmWidth,bkginfo.bmHeight,SRCCOPY);
3.输出文字
RECT rt1;
//lf.lfCharSet=GB2312_CHARSET;
//strcpy(lf.lfFaceName,"雅黑");
lf.lfHeight=lfHeight;
lf.lfItalic=false;
rt1.left=left;
rt1.top=top;
rt1.bottom=bottom;
rt1.right=right;
HDC hdc1 = ::GetDC(h1);
//SetBkMode(hdc1,TRANSPARENT);
SetBkColor(hdc1,RGB(bgR,bgG,bgB));
SetTextColor(hdc1,RGB(lfR,lfG,lfB));
HFONT hFont=CreateFontIndirect(&lf);
HFONT hOldFont=(HFONT)::SelectObject(hdc1,hFont);//设置新字体
DrawText(hdc1, s, lstrlen(s), &rt1,
DT_SINGLELINE |DT_VCENTER | DT_LEFT);// DT_CENTER);
hFont=(HFONT)::SelectObject(hdc1,hOldFont);//恢复原来的字体.
DeleteObject(hFont);
DeleteObject(hOldFont);
::ReleaseDC(h1,hdc1);
4.画背景图
OnEraseBkgnd(CDC *pDC)
{
CRect rc;
mVideoWindow.GetWindowRect(&rc);
ScreenToClient(&rc);
pDC->ExcludeClipRect(&rc);
CRect rect;
GetClientRect(&rect);//加载背景位图
//下边加入获取绝对路径:
CString szSysPath_T,strFullPath;
strFullPath =m_Path;
strFullPath+=_T("\\img\\bg.bmp");
CFile file;
file.Open( strFullPath,CFile::modeRead);
int len = file.GetLength();
char *buf = new char[len];
file.Read(buf,len);
file.Close();
CBrush brush;
const void *buf2 = buf + sizeof(BITMAPFILEHEADER);
brush.CreateDIBPatternBrush(buf2,DIB_RGB_COLORS);
pDC-> SelectObject(&brush);
pDC-> FillRect(rect,&brush);
delete []buf;
return TRUE;
//return CDialog::OnEraseBkgnd(pDC);
}
5.画图