VC 改变对话框某一区域颜色

1. 在OnPaint中添加代码:

void CXXXDlg::OnPaint() 
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
CRect rc;
GetDlgItem(IDC_G9)->GetWindowRect(rc);
ScreenToClient(rc);
CBrush bs(RGB(196,172,182));
CClientDC dc(this);
dc.FillRect(rc,&bs);

}

2. 移动后有时不可见,需要刷新

void CXXXDlg::OnRefresh() 
{
CRect rc;
GetDlgItem(IDC_G9)->GetWindowRect(rc);
ScreenToClient(rc);
InvalidateRect(rc);

}

IDC_G9就是一个Group的控件。改变的就是他的背景色。

VC 改变对话框某一区域颜色_第1张图片

你可能感兴趣的:(VC 改变对话框某一区域颜色)