Mainframe Color 
Author Message
 Mainframe Color

Hi,
How do I change the background color of Mainframe in a SDI application?
I have put a handler for WM_ERASEBKGND message.
But, it does not seem to work.

BOOL CMainFrame::OnEraseBkgnd(CDC* pDC)
{
         // Set brush to desired background color
      CBrush backBrush(RGB(255, 128, 128));

      // Save old brush
      CBrush* pOldBrush = pDC->SelectObject(&backBrush);

      CRect rect;
      int status = pDC->GetClipBox(&rect);     // Erase the area needed

    pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(),
          PATCOPY);

      pDC->PatBlt(rect.left, rect.top, 100,100,
          PATCOPY);

      pDC->SelectObject(pOldBrush);
      return TRUE;

Quote:
}      

regards,
Deepu.


Sat, 25 Oct 2003 17:42:46 GMT  
 Mainframe Color
Hi, Deepu!



Quote:
> Hi,
> How do I change the background color of Mainframe in a SDI application?
> I have put a handler for WM_ERASEBKGND message.
> But, it does not seem to work.

Normally, the MainFrame's background is completely covered by the View in an SDI application. See if
MSDN Article  Q103786, "HOWTO: Change Window Background Color with Foundation Classes", helps you
solve this one.

Jeff...
--
Please post all follow-ups to the newsgroup only.



Sat, 25 Oct 2003 18:05:17 GMT  
 Mainframe Color
Hello Deepu

the problem in your code is that you are creating backBrush on the stack
when the function terminates backBrush is destroyed
make backBrush a member of your CMainFrame class

Nish

p.s. are you the same deepu chandy who was my junior in Loyola School? If so
this is me Nish [Nishant]



Quote:
> Hi,
> How do I change the background color of Mainframe in a SDI application?
> I have put a handler for WM_ERASEBKGND message.
> But, it does not seem to work.

> BOOL CMainFrame::OnEraseBkgnd(CDC* pDC)
> {
> // Set brush to desired background color
>       CBrush backBrush(RGB(255, 128, 128));

>       // Save old brush
>       CBrush* pOldBrush = pDC->SelectObject(&backBrush);

>       CRect rect;
>       int status = pDC->GetClipBox(&rect);     // Erase the area needed

>     pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(),
>           PATCOPY);

>       pDC->PatBlt(rect.left, rect.top, 100,100,
>           PATCOPY);

>       pDC->SelectObject(pOldBrush);
>       return TRUE;
> }

> regards,
> Deepu.



Sat, 25 Oct 2003 19:38:11 GMT  
 Mainframe Color
That should not matter as the brush is not needed after this call and he is
setting the selecting the old brush back.

--
Ajay Kalra [MVP - VC++]

Note: Please post all replies to newsgroup only.


Quote:
> Hello Deepu

> the problem in your code is that you are creating backBrush on the stack
> when the function terminates backBrush is destroyed
> make backBrush a member of your CMainFrame class

> Nish

> p.s. are you the same deepu chandy who was my junior in Loyola School? If
so
> this is me Nish [Nishant]



> > Hi,
> > How do I change the background color of Mainframe in a SDI application?
> > I have put a handler for WM_ERASEBKGND message.
> > But, it does not seem to work.

> > BOOL CMainFrame::OnEraseBkgnd(CDC* pDC)
> > {
> > // Set brush to desired background color
> >       CBrush backBrush(RGB(255, 128, 128));

> >       // Save old brush
> >       CBrush* pOldBrush = pDC->SelectObject(&backBrush);

> >       CRect rect;
> >       int status = pDC->GetClipBox(&rect);     // Erase the area needed

> >     pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(),
> >           PATCOPY);

> >       pDC->PatBlt(rect.left, rect.top, 100,100,
> >           PATCOPY);

> >       pDC->SelectObject(pOldBrush);
> >       return TRUE;
> > }

> > regards,
> > Deepu.



Sat, 25 Oct 2003 22:31:36 GMT  
 Mainframe Color
Mainframe is always covered in SDI by the view. You may want to paint the
view instead.

--
Ajay Kalra [MVP - VC++]

Note: Please post all replies to newsgroup only.



Quote:
> Hi,
> How do I change the background color of Mainframe in a SDI application?
> I have put a handler for WM_ERASEBKGND message.
> But, it does not seem to work.

> BOOL CMainFrame::OnEraseBkgnd(CDC* pDC)
> {
> // Set brush to desired background color
>       CBrush backBrush(RGB(255, 128, 128));

>       // Save old brush
>       CBrush* pOldBrush = pDC->SelectObject(&backBrush);

>       CRect rect;
>       int status = pDC->GetClipBox(&rect);     // Erase the area needed

>     pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(),
>           PATCOPY);

>       pDC->PatBlt(rect.left, rect.top, 100,100,
>           PATCOPY);

>       pDC->SelectObject(pOldBrush);
>       return TRUE;
> }

> regards,
> Deepu.



Sat, 25 Oct 2003 22:30:49 GMT  
 Mainframe Color

Quote:
> Mainframe is always covered in SDI by the view. You may want to paint the
> view instead.

Sure about that ???? I can think about code, that does not use a view....so
what I think is he has 2 possibilities:

1.) register his own window class with AfxRegisterWndClass (......) there he
can set a background brush for his window
2.) if he does not want a brush, but a bitmap or stuff like that or maybe
want to dynamicly update the color: he must overwrite the OnPaint and the
OnEraseBkgnd functions (not sure about OnEraseBkgnd so far) and connect them
via ON_WM_PAINT () and ON_WM_ERASEBKGND (). This should help him.

regards,

sascha



Sun, 26 Oct 2003 04:53:20 GMT  
 Mainframe Color
I should have used the word, usually as opposed to always. However, in his
case, one of the reasons he may not be seeing the background is because view
is covering it up. As far your suggestion is concerned, he is already
overriding OnEraseBkgnd and still not seein the change.

--
Ajay Kalra [MVP - VC++]

Note: Please post all replies to newsgroup only.


Quote:
> > Mainframe is always covered in SDI by the view. You may want to paint
the
> > view instead.

> Sure about that ???? I can think about code, that does not use a
view....so
> what I think is he has 2 possibilities:

> 1.) register his own window class with AfxRegisterWndClass (......) there
he
> can set a background brush for his window
> 2.) if he does not want a brush, but a bitmap or stuff like that or maybe
> want to dynamicly update the color: he must overwrite the OnPaint and the
> OnEraseBkgnd functions (not sure about OnEraseBkgnd so far) and connect
them
> via ON_WM_PAINT () and ON_WM_ERASEBKGND (). This should help him.

> regards,

> sascha



Sun, 26 Oct 2003 07:27:57 GMT  
 Mainframe Color
Yep... I read that :) But he isn#t overriding OnPaint() so far... I am not
sure, when EraseBkgnd is called ( i think only, when a total new Paint is
needed (like when the window was moved or stuff). But normally you overwrite
both : OnEraseBkgnd (well I do not really know, why the hell i am
overwriting this one all the time, because there i normally do a "FillRect
(clientrect)", which I do in OnPaint also, but it seems to be wanted <g>

So OnEraseBkgnd is called before (!) OnPaint. (Thats for sure so far...) If
he overwrites the erasebkgnd function, there will be another bkgnd drawn
(this is what i really do believe :) but if he doesn't overwrite the onpaint
function, there will be many things, that can be drawn over his nice
background (such things as a total FillRect of the clientrect) :)

regards,

SAscha


Quote:
> I should have used the word, usually as opposed to always. However, in his
> case, one of the reasons he may not be seeing the background is because
view
> is covering it up. As far your suggestion is concerned, he is already
> overriding OnEraseBkgnd and still not seein the change.

> --
> Ajay Kalra [MVP - VC++]

> Note: Please post all replies to newsgroup only.



> > > Mainframe is always covered in SDI by the view. You may want to paint
> the
> > > view instead.

> > Sure about that ???? I can think about code, that does not use a
> view....so
> > what I think is he has 2 possibilities:

> > 1.) register his own window class with AfxRegisterWndClass (......)
there
> he
> > can set a background brush for his window
> > 2.) if he does not want a brush, but a bitmap or stuff like that or
maybe
> > want to dynamicly update the color: he must overwrite the OnPaint and
the
> > OnEraseBkgnd functions (not sure about OnEraseBkgnd so far) and connect
> them
> > via ON_WM_PAINT () and ON_WM_ERASEBKGND (). This should help him.

> > regards,

> > sascha



Sun, 26 Oct 2003 17:44:06 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. How to change MAINFRAME color

2. how to change the color of the MainFrame in SDI or MDI

3. Background color 'empty' MDI-mainframe

4. back color in mainframe

5. how to change the color of the Mainframe

6. Detecting Color Pallete ( 16 colors , or 256 colors, or Hi color) URGENT

7. convert color from argb to known color

8. need an algorithm for converting 32-bit color to 16-bit color

9. Caption bar color & CSliderCtrl Color

10. # of colors in color palette?

11. Background Color, Text Color

12. newbie Q: Color palette dialog and colored listbox

 

 
Powered by phpBB® Forum Software