Click here to Skip to main content
Click here to Skip to main content

Painting of CToolbar's parent window (AfxControlBar).

, 27 Mar 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
Background painting of CToolbar's parent window (AfxControlBar).

Introduction

I was trying to paint the background color (paint entire window) of CToolbar. In that, I could paint only the toolbar window and not the entire area of the toolbar window which is "AfxControlBar" (CToolbar's parent window). Then I found the solution for painting the "AfxControBar", and I thought I should share the solution with you all.

Using the code

In your application, override OnNotify member function in your CMainFrame to handle the WM_NOTIFY message for painting the AfxControlBar.

In MainFrm.h file, declare the following member variable and member function:

class CMainFrame : public CMDIFrameWnd 
{ 
    ..... 
    CBrush m_BrushDocBar;
    
    BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult); 
    ..... 
}

In MainFrm.cpp, in constructor create a solid brush as follows,

CMainFrame::CMainFrame()
{
    m_BrushDocBar.CreateSolidBrush(RGB(0, 255, 255));
}

In MainFrm.cpp, provide the definition of OnNotify()function as follows,

BOOL CMainFrame::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
    LPNMHDR pnmh = (LPNMHDR) lParam; 
    if(pnmh->hwndFrom == m_wndToolBar.m_hWnd)
    {
        LPNMTBCUSTOMDRAW lpNMCustomDraw = (LPNMTBCUSTOMDRAW) lParam;
        CRect rect;
        CWnd* pWnd = m_wndToolBar.GetParent();
        TCHAR szClassName[200];
        GetClassName(pWnd->m_hWnd, szClassName, 200);
        CString strTemp = szClassName;
        if(strTemp.Find(_T("AfxControlBar")) >= 0)
        {
            SetClassLong(pWnd->m_hWnd, GCL_HBRBACKGROUND, (LONG)m_BrushDocBar.GetSafeHandle());
        }
    }
    return CMDIFrameWnd::OnNotify(wParam, lParam, pResult);
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Paresh Chitte
Software Developer (Senior)
India India
No Biography provided

Comments and Discussions

 
Questionit didn't work when I rebuild the project in my computer with vs2008 Pinmembershangcangriluo20-Aug-13 17:23 
AnswerRe: it didn't work when I rebuild the project in my computer with vs2008 PinmemberParesh Chitte18-Sep-13 2:17 
Questionhow to limited drawing area?? Pinmemberchenyuntian5-Sep-09 6:15 
Generalpainting PinmemberShorzy5-Aug-09 5:22 
GeneralRe: painting PinmemberParesh Chitte5-Aug-09 19:44 
GeneralThanks a lot! PinmemberMember #408077812-Aug-08 17:45 
GeneralRe: Thanks a lot! PinmemberParesh Chitte12-Aug-08 19:32 
GeneralCorrect way to accomplish this Pinmemberadzm10-Apr-08 16:03 
GeneralRe: Correct way to accomplish this PinmemberParesh Chitte10-Apr-08 19:23 
GeneralSometimes you bring tears to my eyes PinmemberJim Crafton28-Mar-08 5:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150123.1 | Last Updated 27 Mar 2008
Article Copyright 2008 by Paresh Chitte
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid