最近有用到,紀錄一下:
1.在Dialog類別中加入:
CBrush m_brush;
CFont m_font;
在 OnInitDialog() Function 中加入:
m_font.CreatePointFont(150,"字型");
m_brush.CreateSolidBrush(RGB(255,0,0));
2.增加 WM_CTLCOLOR:
在Dialog 類別中增加:afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) ;
在 MESSAGE_MAP中增加: ON_WM_CTLCOLOR()
3.增加對應的Function:
HBRUSH CDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (pWnd->GetDlgCtrlID() == 0x200 ||
pWnd->GetDlgCtrlID() == IDC_STATIC/*要設定顏色的static text*/)
{
pDC->SetBkColor(RGB(255,0,0));
pDC->SetBkMode(TRANSPARENT);
pDC->SelectObject(&m_font);
return m_brush;
}
return hbr;
}