美化MFC控件,OnCtlColor() in MFC

1.//声明句柄刷子
    afx_msg    HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);


2.写函数体,各种控件的美化

HBRUSH CGetMarketDataDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor){
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);       //NOTE!!:here is CDialog
 
// TODO: Change any attributes of the DC here

// TODO: Change any attributes of the DC here
if(nCtlColor==CTLCOLOR_LISTBOX)//列表框
{
//pDC->SetBkMode(TRANSPARENT);//设置透明
pDC->SetTextColor(RGB(0,0,0));//改变文本
pDC->SetBkColor(RGB(0,233,220));//改变背景
HBRUSH b=CreateSolidBrush(RGB(0,233,220));
return b;
}
else if(nCtlColor==CTLCOLOR_SCROLLBAR)
{
//pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(0,0,0));
pDC->SetBkColor(RGB(0,180,220));
HBRUSH b=CreateSolidBrush(RGB(0,180,220));
return b;
}


else if(nCtlColor==CTLCOLOR_EDIT)//改变编辑框
{
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(0,0,0));
pDC->SetBkColor(RGB(0,180,220));
HBRUSH b=CreateSolidBrush(RGB(0,180,220));
return b;
}
else if(nCtlColor==CTLCOLOR_STATIC)//静态文本
{
//pDC->SetTextColor(RGB(0,0,0));
pDC->SetBkColor(RGB(0,180,220));
HBRUSH b=CreateSolidBrush(RGB(0,180,220));
return b;
}
else if(nCtlColor==CTLCOLOR_DLG)//对话框
{
//pDC->set
pDC->SetTextColor(RGB(0,0,0));
pDC->SetBkColor(RGB(0,0,0));
HBRUSH b=CreateSolidBrush(RGB(0,0,0));
return b;
}
else if(nCtlColor==CTLCOLOR_BTN){
pDC->SetTextColor(RGB(0,0,0));
pDC->SetBkColor(RGB(0,180,220));
HBRUSH b=CreateSolidBrush(RGB(0,180,220));
return b;
}
else if(nCtlColor==CTLCOLOR_MSGBOX){
pDC->SetTextColor(RGB(0,0,0));
pDC->SetBkColor(RGB(0,180,220));
HBRUSH b=CreateSolidBrush(RGB(0,180,220));
return b;
}
// TODO: Return a different brush if the default is not desired
// TODO: Return a different brush if the default is not desired
return hbr;
}


3.添加OnCtlColor()的消息映射

BEGIN_MESSAGE_MAP(CGetMarketDataDlg, CDialogEx)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()

    ON_WM_CTLCOLOR() //OnCtlColor()的消息映射
    ON_WM_QUERYDRAGICON()  
    ON_BN_CLICKED(ID_BN_START, &CGetMarketDataDlg::OnBnClickedBnStart)
    ON_BN_CLICKED(ID_BN_STOP, &CGetMarketDataDlg::OnBnClickedBnStop)
    ON_BN_CLICKED(IDOK, &CGetMarketDataDlg::OnBnClickedOk)
END_MESSAGE_MAP()  


附上MSDN连接:http://msdn.microsoft.com/zh-cn/library/0wwk06hc.aspx

你可能感兴趣的:(map,mfc,控件,对话框)