MFC修改界面和控件颜色

重新ON_WM_PAINT()、ON_WM_CTLCOLOR()消息对应的函数OnPaint()、OnCtlColor()

(一)OnPaint()

//CDialogEx::OnPaint();
        CRect   rect;
        CPaintDC   dc(this);
        GetClientRect(rect);
        dc.FillSolidRect(rect, RGB(217, 226, 241));   //设置为浅蓝色背景
(二)OnCtlColor()

HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);

	// TODO:  在此更改 DC 的任何特性
	if (nCtlColor == CTLCOLOR_BTN)          //更改按钮颜色
	{
		//pDC->SetBkMode(TRANSPARENT);
		pDC->SetTextColor(RGB(0, 0, 0));
		pDC->SetBkColor(RGB(1, 121, 255));
		HBRUSH b = CreateSolidBrush(RGB(121, 121, 255));
		return b;
	}
	else if (nCtlColor == CTLCOLOR_SCROLLBAR)  //
	{
		//pDC->SetBkMode(TRANSPARENT);
		pDC->SetTextColor(RGB(0, 0, 0));
		pDC->SetBkColor(RGB(233, 233, 220));
		HBRUSH b = CreateSolidBrush(RGB(233, 233, 220));
		return b;
	}
	else if (nCtlColor == CTLCOLOR_EDIT)   //更改编辑框
	{
		//pDC->SetBkMode(TRANSPARENT);
		pDC->SetTextColor(RGB(0, 0, 0));
		pDC->SetBkColor(RGB(246, 246, 246));
		HBRUSH b = CreateSolidBrush(RGB(246, 246, 246));
		return b;
	}
	else if (nCtlColor == CTLCOLOR_STATIC)  //更改静态文本
	{
		pDC->SetTextColor(RGB(0, 0, 0));
		pDC->SetBkColor(RGB(217, 226, 241));
		HBRUSH b = CreateSolidBrush(RGB(217, 226, 241));
		return b;
	}
	else if (nCtlColor == CTLCOLOR_DLG)   //更改对话框背景色
	{
		pDC->SetTextColor(RGB(0, 0, 0));
		pDC->SetBkColor(RGB(166, 254, 1));
		HBRUSH b = CreateSolidBrush(RGB(213, 226, 240));
		return b;
	}

	// TODO:  如果默认的不是所需画笔,则返回另一个画笔
	return hbr;
最终界面图:

MFC修改界面和控件颜色_第1张图片

你可能感兴趣的:(MFC修改界面和控件颜色)