home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / advanced / oldbars / toolbar.h < prev   
Encoding:
C/C++ Source or Header  |  1998-03-27  |  3.5 KB  |  110 lines

  1. // toolbar.h : definition of old backward compatible CToolBar
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #ifndef _TOOLBAR_H_
  14. #define _TOOLBAR_H_
  15.  
  16. struct AFX_TBBUTTON;        // private to implementation
  17.  
  18. HBITMAP AFXAPI AfxLoadSysColorBitmap(HINSTANCE hInst, HRSRC hRsrc);
  19.  
  20. class COldToolBar : public CControlBar
  21. {
  22.     DECLARE_DYNAMIC(COldToolBar)
  23.  
  24. // Construction
  25. public:
  26.     COldToolBar();
  27.     BOOL Create(CWnd* pParentWnd,
  28.             DWORD dwStyle = WS_CHILD | WS_VISIBLE | CBRS_TOP,
  29.             UINT nID = AFX_IDW_TOOLBAR);
  30.  
  31.     void SetSizes(SIZE sizeButton, SIZE sizeImage);
  32.                 // button size should be bigger than image
  33.     void SetHeight(int cyHeight);
  34.                 // call after SetSizes, height overrides bitmap size
  35.     BOOL LoadBitmap(LPCTSTR lpszResourceName);
  36.     BOOL LoadBitmap(UINT nIDResource);
  37.     BOOL SetButtons(const UINT* lpIDArray, int nIDCount);
  38.                 // lpIDArray can be NULL to allocate empty buttons
  39.  
  40. // Attributes
  41. public: // standard control bar things
  42.     int CommandToIndex(UINT nIDFind) const;
  43.     UINT GetItemID(int nIndex) const;
  44.     virtual void GetItemRect(int nIndex, LPRECT lpRect) const;
  45.     UINT GetButtonStyle(int nIndex) const;
  46.     void SetButtonStyle(int nIndex, UINT nStyle);
  47.  
  48. public:
  49.     // for changing button info
  50.     void GetButtonInfo(int nIndex, UINT& nID, UINT& nStyle, int& iImage) const;
  51.     void SetButtonInfo(int nIndex, UINT nID, UINT nStyle, int iImage);
  52.  
  53. // Implementation
  54. public:
  55.     virtual ~COldToolBar();
  56.     virtual CSize CalcFixedLayout(BOOL bStretch, BOOL bHorz);
  57.  
  58. #ifdef _DEBUG
  59.     virtual void AssertValid() const;
  60.     virtual void Dump(CDumpContext& dc) const;
  61. #endif
  62.  
  63. protected:
  64.     inline AFX_TBBUTTON* _GetButtonPtr(int nIndex) const;
  65.     void InvalidateButton(int nIndex);
  66.     void UpdateButton(int nIndex);
  67.     void CreateMask(int iImage, CPoint offset,
  68.         BOOL bHilite, BOOL bHiliteShadow);
  69.  
  70.     // for custom drawing
  71.     struct DrawState
  72.     {
  73.         HBITMAP hbmMono;
  74.         HBITMAP hbmMonoOld;
  75.         HBITMAP hbmOldGlyphs;
  76.     };
  77.     BOOL PrepareDrawButton(DrawState& ds);
  78.     BOOL DrawButton(CDC* pDC, int x, int y, int iImage, UINT nStyle);
  79.     void EndDrawButton(DrawState& ds);
  80.  
  81. protected:
  82.     CSize m_sizeButton;         // size of button
  83.     CSize m_sizeImage;          // size of glyph
  84.     int m_cxSharedBorder;       // shared x border between buttons
  85.     int m_cySharedBorder;       // shared y border between buttons
  86.     HBITMAP m_hbmImageWell;     // glyphs only
  87.     int m_iButtonCapture;       // index of button with capture (-1 => none)
  88.     HRSRC m_hRsrcImageWell;     // handle to loaded resource for image well
  89.     HINSTANCE m_hInstImageWell; // instance handle to load image well from
  90.  
  91.     virtual void DoPaint(CDC* pDC);
  92.     virtual void OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler);
  93.     virtual int HitTest(CPoint point);
  94.     virtual int OnToolHitTest(CPoint point, TOOLINFO* pTI) const;
  95.  
  96.     //{{AFX_MSG(COldToolBar)
  97.     afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  98.     afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  99.     afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  100.     afx_msg void OnCancelMode();
  101.     afx_msg void OnSysColorChange();
  102.     //}}AFX_MSG
  103.     DECLARE_MESSAGE_MAP()
  104. };
  105.  
  106. // define CToolBar to COldToolBar for convenience
  107. #define CToolBar COldToolBar
  108.  
  109. #endif //!_TOOLBAR_H_
  110.