GDI实战中,目标是设置对话框边框的颜色,结果变成了整个界面的颜色,如何做?
void CCaptionDlg::DrawColorTitle(CRect rect, COLORREF col1, COLORREF col2,CDC* pDC)
{
int cx = rect.Width();
int red = GetRValue(col2) - GetRValue(col1);
int green = GetGValue(col2) - GetGValue(col1);
int blue = GetBValue(col2) - GetBValue(col1);
int i = 0;
while (i < cx)
{
int r = GetRValue(col1) + i*red / cx;
int g = GetGValue(col1) + i*green / cx;
int b = GetBValue(col1) + i*blue / cx;
CPen pen(PS_SOLID,1,RGB(r,g,b));
pDC->SelectObject(pen);
pDC->MoveTo(i,0);
pDC->LineTo(i,rect.bottom);
++i;
}
}
void CCaptionDlg::OnNcPaint()
{
CWindowDC dc(this);
CRect rect,rt;
GetWindowRect(rect);
rect.OffsetRect(-rect.left,-rect.top);
rt = rect;
rt.bottom = 30;
//dc.Rectangle(rt);
DrawColorTitle(rect,RGB(115,158,115),RGB(165,186,190),&dc);
dc.SetTextColor(RGB(255,0,0));
dc.SetBkMode(TRANSPARENT);
dc.DrawText(_T("欢迎使用本软件"),rt,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
}
我的本意是把对话框的边框变成渐变色,但是运行后变成了整个界面都变成了渐变色,问题出在哪里?