添加消息響應WM_CTLCOLOR,
Static代碼如下:
HBRUSH CTest1Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
CFont m_font; //聲明變量
m_font.CreatePointFont(600,"華文行楷"); //設置字體大小和類型
if(pWnd->GetDlgCtrlID()==IDC_STATIC01)//可以用CTLCOLOR_STATIC表示靜態(tài)控件
{
pDC->SelectObject(&m_font); //設置字體
pDC->SetTextColor(RGB(0,0,255)); //設置字體顏色
pDC->SetBkMode(TRANSPARENT); //屬性設置為透明
return (HBRUSH)::GetStockObject(NULL_BRUSH); //不返回畫刷
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
Radio和Check代碼如下
HBRUSH CLoginDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
//HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
HBRUSH hbr = ::CreateSolidBrush(#f9f9f9);
// TODO: Change any attributes of the DC here
if (pWnd->GetDlgCtrlID() == IDC_RADIO_REALNAME ||
pWnd->GetDlgCtrlID() == IDC_RADIO_ANONYMOUS ||
pWnd->GetDlgCtrlID() == IDC_CHECK_SELFSELECT)
{
pDC->SetBkMode(TRANSPARENT);
CRect rc;
pWnd->GetWindowRect(&rc);
ScreenToClient(&rc);
CDC* dc = GetDC();
pDC->BitBlt(0,0,rc.Width(),rc.Height(),dc,rc.left,rc.top,SRCCOPY); //把父窗口背景先畫到按鈕上
ReleaseDC(dc);
hbr = (HBRUSH) ::GetStockObject(NULL_BRUSH);
}
}
posted on 2013-08-18 16:54
王海光 閱讀(11268)
評論(0) 編輯 收藏 引用 所屬分類:
MFC