1:绘制显示字体
void MyDrawText(COLORREF color, CString str, CRect rt, int nSize) |
{ |
//创建字体 |
CDC* pDC = GetDC(); |
CFont font; |
font.CreateFont(nSize,0,0,0,100,FALSE,FALSE,0,ANSI_CHARSET, |
OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY, |
DEFAULT_PITCH&FF_SWISS,_T("宋体"));//Aerial, 宋体 |
pDC->SelectObject(&font); |
//drawtext |
pDC->SetTextColor(color); |
pDC->SetBkMode(TRANSPARENT);//文字背景“透明” |
pDC->DrawText(str , &rt, DT_CENTER | DT_VCENTER); |
pDC->SelectObject(&font); |
font.DeleteObject(); |
ReleaseDC(pDC); |
}
|
2:绘制显示图片
加背景图 |
void CLoginDlg::DrawPng() |
{ |
CImage image; |
CDC *pDC = GetDC(); |
image.Load(_T("skin\\login\\login.png")); |
if (image.IsNull()) |
{ |
MessageBox(_T("图片没加载成功")); |
return; |
} |
//CrossImage(image); |
image.Draw(pDC->m_hDC, m_rtPngBk.left, m_rtPngBk.top); |
image.Destroy(); |
ReleaseDC(pDC); |
} |
3:绘制按键
void DrawBtn()
{
CWnd *pWnd = NULL;
CRect ctBtnAnswer, ctBtnBreak, ctBtn;
ctBtnAnswer = ctBtnBreak = ctBtn = m_rtDisplay;
ctBtn.left += 240;
ctBtn.top += 31;
ctBtn.right = ctBtn.left + 91;
ctBtn.bottom = ctBtn.top + 62;
switch (State)
{
case PHONE_CALLIN:
{
ctBtnAnswer.left += 240;
ctBtnAnswer.top += 31;
ctBtnAnswer.right = ctBtnAnswer.left + 91;
ctBtnAnswer.bottom = ctBtnAnswer.top + 31;
pWnd = GetDlgItem(IDC_BTN_ANSWER);
if (pWnd && (pWnd->m_hWnd))
{
m_btnAnswer.MoveWindow(ctBtnAnswer);
m_btnAnswer.ShowWindow(SW_SHOW);
}
ctBtnBreak.left += 240;
ctBtnBreak.top += 62;
ctBtnBreak.right = ctBtnBreak.left + 91;
ctBtnBreak.bottom = ctBtnBreak.top + 31;
pWnd = GetDlgItem(IDC_BTN_BREAK);
if (pWnd && (pWnd->m_hWnd))
{
m_btnBreak.MoveWindow(ctBtnBreak);
m_btnBreak.ShowWindow(SW_SHOW);
}
}
break;
case PHONE_CALL:
case PHONE_CALLOUT:
{
m_btnAnswer.ShowWindow(SW_HIDE);
ctBtnBreak.left += 240;
ctBtnBreak.top += 46;
ctBtnBreak.right = ctBtnBreak.left + 91;
ctBtnBreak.bottom = ctBtnBreak.top + 31;
pWnd = GetDlgItem(IDC_BTN_BREAK);
if (pWnd && (pWnd->m_hWnd))
{
m_btnBreak.MoveWindow(ctBtnBreak);
m_btnBreak.ShowWindow(SW_SHOW);
}
}
break;
default:
{
m_btnAnswer.ShowWindow(SW_HIDE);
m_btnBreak.ShowWindow(SW_HIDE);
}
break;
}
}
总结:文字主要通过DrawText,控件绘图 通过 GDI对象就是绘画时用的工具。