面对现实,超越自己
逆水行舟,不进则退
posts - 269,comments - 32,trackbacks - 0

添加消息响应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表示静态控件
{
   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 王海光 阅读(11037) 评论(0)  编辑 收藏 引用 所属分类: MFC

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理