Click to See Complete Forum and Search --> : coloring window


Septimiu
September 10th, 1999, 05:46 AM
I have a dialog based application in VC++5.0
I use mfc.
I have to change the entire window color at a button click e.g.
I use OnCtlColor but the frames (thick borders)remains unchanged, in the same gray color.

Please help me.

Thomas Ascher
September 10th, 1999, 06:08 AM
You must paint the borders of a window in the function OnNcPaint(), because the borders don't belong to the windows client area and OnCtlColor only works for the client area.

Septimiu
September 13th, 1999, 02:35 AM
I've implemented OnNcPaint() but the frames are becaming transparent.
How should look the implementation?
I've tried
CPaintDC dc(this); // device context for painting
CBrush ncbrush;
ncbrush.CreateSolidBrush(RGB(255,255,0));
dc.FillRect(NULL, &ncbrush);


but it doesn't vork.
thank you.

Thomas Ascher
September 13th, 1999, 04:50 AM
You must use CWindowDC instead of CPaintDC. CPaintDC may only be used in OnPaint. And you must give the rectangle to paint in for the FillRect function.

CWindowDC dc(this);
CBrush brush;
CRect rc;
brush.CreateSolidBrush(RGB(255, 255, 0));
GetWindowRect(&rc); // paint whole non-client area in desired color
rc.OffsetRect(-rc.left, -rc.top);
dc.FillRect(&rc, &brush);
// you must also draw the caption bar yourself...