CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 1999
    Posts
    58

    Painting the background...

    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?


  2. #2
    Join Date
    May 1999
    Location
    Toronto, Ontario, Canada
    Posts
    155

    Re: Painting the background...

    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)


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured