Tip: Painting the CToolbar's Parent Window (AfxControlBar)

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);
}


Downloads

Comments

  • Inadequate Terminology

    Posted by srelu on 04/24/2008 05:53pm

    The so called parent window of cToolbar is NOT an AfxControlBar. It's a dock bar. There's one dock bar for each side of a window and one more for floating toolbars. They are children of the main window and can be retrieved using their window identifiers: AFX_IDW_DOCKBAR_TOP, AFX_IDW_DOCKBAR_LEFT, AFX_IDW_DOCKBAR_RIGHT, AFX_IDW_DOCKBAR_BOTTOM, AFX_IDW_DOCKBAR_FLOAT The MFC class to handle dock bars is CDockBar. In the MFC source library the class is declared in \mfc\include\afxpriv.h and implemented in mfc\src\bardock.cpp . It's not documented in the MSDN.

    Reply
  • Working

    Posted by krishnakumar.tmr on 04/24/2008 03:53am

    Hi this is good i tried it this but what is the logic can u explain to me

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • On-demand Event Event Date: September 17, 2014 Another day, another end-of-support deadline. You've heard enough about the hazards of not migrating to Windows Server 2008 or 2012. What you may not know is that there's plenty in it for you and your business, like increased automation and performance, time-saving technical features, and a lower total cost of ownership. Check out this webcast and join Rich Holmes, Pomeroy's practice director of virtualization, as he discusses the future state of your servers, …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds