Changing windows background in MFC - Programmer

This is a discussion on Changing windows background in MFC - Programmer ; Hello, I need some help changing the client window background in an MFC app. I've created a very simple MFC application. The main window is a CFrameWnd class. I run the app and the window background is white. Is there ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Changing windows background in MFC

  1. Changing windows background in MFC

    Hello,

    I need some help changing the client window background in an MFC app.
    I've created a very simple MFC application. The main window is a
    CFrameWnd class. I run the app and the window background is white. Is
    there anyway to replace the default "white" background with some other
    color? If this were not an MFC app, I could just modify the
    hbrBackground member of the WNDCLASS object before the class is
    registered. I am also aware of the ability to use PreCreateWindow to
    modify some of the window creation properties, but I cannot find a
    means to modify the background default color.

    Any help or insites would be greatly appreciated.

    Thanks,

    Brandon


  2. Re: Changing windows background in MFC

    bnjchambers wrote:
    > Hello,
    >
    > I need some help changing the client window background in an MFC app.
    > I've created a very simple MFC application. The main window is a
    > CFrameWnd class. I run the app and the window background is white. Is
    > there anyway to replace the default "white" background with some other
    > color? If this were not an MFC app, I could just modify the
    > hbrBackground member of the WNDCLASS object before the class is
    > registered. I am also aware of the ability to use PreCreateWindow to
    > modify some of the window creation properties, but I cannot find a
    > means to modify the background default color.
    >
    > Any help or insites would be greatly appreciated.
    >
    > Thanks,
    >
    > Brandon
    >


    Handle the WM_ERASEBGND message, fill the window in your function, and
    do not call the base class OnEraseBgnd. Note that if you have a
    CView-derived class you need to do it there, not in the CFrameWnd.

    --
    Scott McPhillips [VC++ MVP]


  3. Re: Changing windows background in MFC

    Thanks


  4. Re: Changing windows background in MFC

    "bnjchambers" wrote in message
    news:1120418710.518474.321210@z14g2000cwz.googlegr oups.com...
    >
    > I need some help changing the client window background in an MFC app.
    > I've created a very simple MFC application. The main window is a
    > CFrameWnd class. I run the app and the window background is white. Is
    > there anyway to replace the default "white" background with some other
    > color?


    Override WM_ERASEBACKGROUND in CMainFrame, and do something like:

    BOOL CMainFrame::OnEraseBkgnd(CDC* pDC)
    {
    CRect rect;
    GetClientRect (&rect);
    pDC->FillSolidRect (rect, m_rgbDesiredColor);

    // processed message
    return TRUE;
    }



+ Reply to Thread