我用MFC去改变文本框的颜色却发现无法改变?

我的消息映射函数

afx_msg HBRUSH OnCtlColor(CDC *pDC,CWnd *pWnd,UINT nCtlColor);

我的函数实现

HBRUSH CMFCTestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    // TODO: Change any attributes of the DC here
       if (pWnd->GetDlgCtrlID() == IDC_EDIT1)
        {
            pDC->SetTextColor(RGB(255,0,0));  //设置字体颜色
            pDC->SetBkMode(TRANSPARENT); //设置字体背景为透明
            // TODO: Return a different brush if the default is not desired
            return (HBRUSH)::GetStockObject(BLACK_BRUSH);  // 设置背景色
        }
        else
            return hbr;
}

我这里有一个IDC_EDIT1的文本框控件,但是颜色并没有改变,不知道是为什么?我刚开始使用MFC

阅读 3k
1 个回答

先把这一行代码注释试试, 如果不行.再回复我;

// return (HBRUSH)::GetStockObject(BLACK_BRUSH); // 设置背景色

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题