一、加入字体
CDC *pdc=GetDC();
CFont cfont;
cfont.CreateFont(height,width,0,0,700,FALSE,0,0,0,0,0,0,0,"Arial"); //创建字体
SelectObject(*pdc,cfont);
pdc->SetBkMode(TRANSPARENT);//字体背景透明
pdc->TextOut(); //在指定坐标写
pdc->DrawText(); //在矩形框里写
二、加入背景
1.bitmap background:
(1)创建位图
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP1);
(2)创建兼容DC
CDC dcCompatible;
dcCompatible.CreateCompatibleDC(pDC);
(3)将位图选到兼容DC中
dcCompatible.SelectObject(&bitmap);
(4)将兼容DC中的位图贴到当前DC中。在WM_EraseBkgnd()中调用,但不能再调用基类的擦除背景函数。也可以在OnDraw函数中完成,但效率低,图像会闪烁,因为它先擦除背景,慢。
pDC->BitBlt(rect.left,rect.top,rect.Width(),rect.Height(),&dcCompatible,0,0,SRCCOPY);
OnEraseBkgnd(CDC* pDC)
{
CBitmap bmp;
bmp.LoadBitmap(IDB_BG); ///加载位图,IDB_BG是位图资源的ID
CBrush m_brushBackground;
m_brushBackground.CreatePatternBrush(&bmp); ///创建位图画刷
CRect rect;
GetClientRect(&rect); //得到背景矩形框
pDC->FillRect(rect,&m_brushBackground); //用背景画填充区域
return TRUE;
}
2.color background:
CBrush m_bluebrush;
m_bluebrush.CreateSolidBrush(RGB(15,255,255)); //创建颜色刷
CDC *pdc=GetDC();
CRect rect1(0,0,100,100);
pdc->FillRect(&rect1,&m_bluebrush); //颜色刷与矩形窗绑定
....
m_bluebrush.DeleteObject();