Click here to Skip to main content
Licence CPOL
First Posted 27 Mar 2008
Views 21,972
Downloads 345
Bookmarked 9 times

Painting of CToolbar's parent window (AfxControlBar).

By | 27 Mar 2008 | Article
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)

About the Author

Paresh Chitte

Software Developer (Senior)

India India

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Questionhow to limited drawing area?? Pinmemberchenyuntian5:15 5 Sep '09  
Generalpainting PinmemberShorzy4:22 5 Aug '09  
GeneralRe: painting PinmemberParesh Chitte18:44 5 Aug '09  
GeneralThanks a lot! PinmemberMember #408077816:45 12 Aug '08  
GeneralRe: Thanks a lot! PinmemberParesh Chitte18:32 12 Aug '08  
GeneralCorrect way to accomplish this Pinmemberadzm15:03 10 Apr '08  
GeneralRe: Correct way to accomplish this PinmemberParesh Chitte18:23 10 Apr '08  
GeneralSometimes you bring tears to my eyes PinmemberJim Crafton4:00 28 Mar '08  

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.

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