VC如何通过菜单选项改变窗口背景颜色
展开全部
SetClassLong(m_hWnd,GCL_HBRBACKGROUND,(LONG)GetStockObject(BLACK_BRUSH));
设置窗口背景色
SetBkColor(RGB(0,0,255));
设置控件背景色
示例:(设置控件背景色)
HBRUSH CSettingDlg::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_LINE_STYLE)
{
pDC->SetTextColor(RGB(255,0,0));
pDC->SetBkMode(TRANSPARENT);
//pDC->SetBkColor(RGB(0,0,255));
return m_brush;
}
if(pWnd->GetDlgCtrlID()==IDC_LINE_WIDTH)
{
//pDC->SetTextColor(RGB(255,0,0));
//pDC->SetBkColor(RGB(0,0,255));
}
if(pWnd->GetDlgCtrlID()==IDC_TEXT)
{
pDC->SetTextColor(RGB(255,0,0));
pDC->SetBkColor(RGB(0,0,255));//pDC->SetBkMode(TRANSPARENT);
pDC->SelectObject(&m_font);
}
if(pWnd->GetDlgCtrlID()==IDOK)
{
pDC->SetTextColor(RGB(255,0,0));
return m_brush;
}
// TODO: Return a different brush if the default is not desired
return hbr;
//return m_brush;
}
设置窗口背景色
SetBkColor(RGB(0,0,255));
设置控件背景色
示例:(设置控件背景色)
HBRUSH CSettingDlg::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_LINE_STYLE)
{
pDC->SetTextColor(RGB(255,0,0));
pDC->SetBkMode(TRANSPARENT);
//pDC->SetBkColor(RGB(0,0,255));
return m_brush;
}
if(pWnd->GetDlgCtrlID()==IDC_LINE_WIDTH)
{
//pDC->SetTextColor(RGB(255,0,0));
//pDC->SetBkColor(RGB(0,0,255));
}
if(pWnd->GetDlgCtrlID()==IDC_TEXT)
{
pDC->SetTextColor(RGB(255,0,0));
pDC->SetBkColor(RGB(0,0,255));//pDC->SetBkMode(TRANSPARENT);
pDC->SelectObject(&m_font);
}
if(pWnd->GetDlgCtrlID()==IDOK)
{
pDC->SetTextColor(RGB(255,0,0));
return m_brush;
}
// TODO: Return a different brush if the default is not desired
return hbr;
//return m_brush;
}
更多追问追答
追问
这么复杂???
追答
不复杂的,这里我设置了好几个控件的背景色;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询