Click to See Complete Forum and Search --> : Painting the background...


sanket
April 21st, 1999, 05:40 PM
In my SDI application, when it comes up, I want to paint the background

.

I tried using SetBkColor (RGB(....)) in WM_PAINT handler but didn't seem to work. Any clue how can I get this done?

Safai Ma
April 21st, 1999, 07:31 PM
There are two way to paint a window with a solid color.

1) handle erase background (WM_ERASEBKGND)
2) handle paint (WM_PAINT)

In both cases, you need to get the rectangle of the window and do a fill rect.

void CSomeWnd::OnPaint() (or int CSomeWnd::OnEraseBkgnd())
{
CPaintDC dc(this);
CRect rect;
GetClientRect(&rect);
dc.FillRect(&rect, (HBRUSH)GetStockObject(WHITE_BRUSH));
}



If you want to use a color that is not available from GetStockObject, you have to create you own brush like the following and use it in place of GetStockObject.

CBrush brush(RGB(r,g,b));



(I don't have the documentation with me, so the function parameters maybe a little bit off, check the online help for sure)