1 ////////////////////////////////////////////////////////////////
2 // Copyright 1998 Paul DiLascia
3 // If this code works, it was written by Paul DiLascia.
4 // If not, I don't know who wrote it.
10 // CCoolBar encapsulates IE common coolbar (rebar) for MFC. To use it,
12 // * derive your own CMyCoolBar from CCoolBar
13 // * implement OnCreateBands to create whatever bands you want
14 // * instantiate CMyCoolBar in your frame window as you would a toolbar
15 // * create and load it, etc from CMainFrame::OnCreate
17 // See MBTest for example of how to use.
19 class CTRL_EXT_CLASS CCoolBar : public CControlBar {
24 BOOL Create(CWnd* pParentWnd, DWORD dwStyle,
25 DWORD dwAfxBarStyle = CBRS_ALIGN_TOP,
26 UINT nID = AFX_IDW_TOOLBAR);
29 BOOL GetBarInfo(LPREBARINFO lp)
30 { ASSERT(::IsWindow(m_hWnd));
31 return (BOOL)SendMessage(RB_GETBARINFO, 0, (LPARAM)lp); }
33 BOOL SetBarInfo(LPREBARINFO lp)
34 { ASSERT(::IsWindow(m_hWnd));
35 return (BOOL)SendMessage(RB_SETBARINFO, 0, (LPARAM)lp); }
37 BOOL GetBandInfo(int iBand, LPREBARBANDINFO lp)
38 { ASSERT(::IsWindow(m_hWnd));
39 return (BOOL)SendMessage(RB_GETBANDINFO, iBand, (LPARAM)lp); }
41 BOOL SetBandInfo(int iBand, LPREBARBANDINFO lp)
42 { ASSERT(::IsWindow(m_hWnd));
43 return (BOOL)SendMessage(RB_SETBANDINFO, iBand, (LPARAM)lp); }
45 BOOL InsertBand(int iWhere, LPREBARBANDINFO lp)
46 { ASSERT(::IsWindow(m_hWnd));
47 return (BOOL)SendMessage(RB_INSERTBAND, (WPARAM)iWhere, (LPARAM)lp); }
49 BOOL DeleteBand(int nWhich)
50 { ASSERT(::IsWindow(m_hWnd));
51 return (BOOL)SendMessage(RB_DELETEBAND, (WPARAM)nWhich); }
54 { ASSERT(::IsWindow(m_hWnd));
55 return (int)SendMessage(RB_GETBANDCOUNT); }
58 { ASSERT(::IsWindow(m_hWnd));
59 return (int)SendMessage(RB_GETROWCOUNT); }
61 int GetRowHeight(int nWhich)
62 { ASSERT(::IsWindow(m_hWnd));
63 return (int)SendMessage(RB_GETROWHEIGHT, (WPARAM)nWhich); }
65 // Call these handy functions from your OnCreateBands to do stuff
66 // more easily than the Windows way.
68 BOOL InsertBand(CWnd* pWnd, CSize szMin, int cx = 0,
69 LPCTSTR lpText=NULL, int iWhere=-1, BOOL bNewRow =FALSE);
70 void SetColors(COLORREF clrFG, COLORREF clrBG);
71 void SetBackgroundBitmap(CBitmap* pBitmap);
72 void Invalidate(BOOL bErase = TRUE); // invalidates children too
74 static BOOL bTRACE; // Set TRUE to see extra diagnostics in DEBUG code
77 // YOU MUST OVERRIDE THIS in your derived class to create bands.
78 virtual BOOL OnCreateBands() = 0; // return -1 if failed
80 // Virtual fn called when the coolbar height changes as a result of moving
81 // bands around. Override only if you want to do something different.
82 virtual void OnHeightChange(const CRect& rcNew);
84 // overrides to fix problems w/MFC. No need to override yourself.
85 virtual CSize CalcFixedLayout(BOOL bStretch, BOOL bHorz);
86 virtual CSize CalcDynamicLayout(int nLength, DWORD nMode);
87 virtual void OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler);
90 afx_msg int OnCreate(LPCREATESTRUCT lpcs);
91 afx_msg void OnPaint();
92 afx_msg void OnHeightChange(NMHDR* pNMHDR, LRESULT* pRes);
93 afx_msg BOOL OnEraseBkgnd(CDC* pDC);
96 DECLARE_DYNAMIC(CCoolBar)
100 // Programmer-friendly REBARINFO initializes itself.
102 class CRebarInfo : public REBARINFO {
105 memset(this, 0, sizeof(REBARINFO));
106 cbSize = sizeof(REBARINFO);
111 // Programmer-friendly REBARBANDINFO initializes itself.
113 class CRebarBandInfo : public REBARBANDINFO {
116 memset(this, 0, sizeof(REBARBANDINFO));
117 cbSize = sizeof(REBARBANDINFO);