Click here to Skip to main content
14,660,264 members
Articles » Desktop Development » Toolbars & Docking windows » General
Article
Posted 27 Mar 2008

Stats

45.2K views
855 downloads
11 bookmarked

Painting of CToolbar's parent window (AfxControlBar).

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

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

 
GeneralCorrect way to accomplish this Pin
adzm10-Apr-08 15:03
Memberadzm10-Apr-08 15:03 
GeneralRe: Correct way to accomplish this Pin
Paresh Chitte10-Apr-08 18:23
MemberParesh Chitte10-Apr-08 18:23 

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

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