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的控制元件。改變的就是他的背景色。