home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 21 / IOPROG_21.ISO / SOFT / DEMOT.ZIP / Src / Include / CoolMenu.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-23  |  4.2 KB  |  119 lines

  1. ////////////////////////////////////////////////////////////////
  2. // 1997 Microsoft Systems Journal. 
  3. // If this code works, it was written by Paul DiLascia.
  4. // If not, I don't know who wrote it.
  5. //
  6.  
  7. #if !defined(COOLMENU_H_INCLUDED)
  8. #define COOLMENU_H_INCLUDED
  9.  
  10. #if _MSC_VER >= 1000
  11. #pragma once
  12. #endif // _MSC_VER >= 1000
  13.  
  14. #include "SubClass.h"
  15.  
  16. namespace PxLib
  17. {
  18.     extern void FillRect(CDC& dc, const CRect& rc, COLORREF color);
  19.     extern void DrawEmbossed(CDC& dc, CImageList& il, int i,
  20.         CPoint p, BOOL bColor=FALSE);
  21.     extern HBITMAP LoadSysColorBitmap(LPCTSTR lpResName, BOOL bMono=FALSE);
  22.     inline HBITMAP LoadSysColorBitmap(UINT nResID, BOOL bMono=FALSE) {
  23.         return LoadSysColorBitmap(MAKEINTRESOURCE(nResID), bMono);
  24.     }
  25. } // end namespace
  26.  
  27. //////////////////
  28. // CCoolMenuManager implements "cool" menus with buttons in them. To use:
  29. //
  30. //  *    Instantiate in your CMainFrame.
  31. //     * Call Install to install it
  32. //  * Call LoadToolbars or LoadToolbar to load toolbars
  33. //
  34. //  Don't forget to link with CoolMenu.cpp, Subclass.cpp and DrawTool.cpp!
  35. //
  36.  
  37. class CLASS_EXPORT CCoolMenuManager : private CSubclassWnd
  38. {
  39.     DECLARE_DYNAMIC(CCoolMenuManager)
  40. public:
  41.     CCoolMenuManager();
  42.     ~CCoolMenuManager();
  43.  
  44.     // You can set these any time
  45.     BOOL m_bShowButtons;            // use to control whether buttons are shown
  46.     BOOL m_bAutoAccel;            // generate auto accelerators
  47.     BOOL m_bUseDrawState;        // use ::DrawState for disabled buttons
  48.     BOOL m_bDrawDisabledButtonsInColor; // draw disabled buttons in color
  49.                                         // (only if m_bUseDrawState = FALSE)
  50.     // public functions to use
  51.     void Install(CFrameWnd* pFrame);                    // connect to main frame
  52.     BOOL LoadToolbars(const UINT* arIDs, int n);    // load multiple toolbars
  53.     BOOL LoadToolbar(UINT nID);                        // load one toolbar
  54.     BOOL AddSingleBitmap(UINT nBitmapID, UINT n, UINT *nID);
  55.  
  56.     // should never need to call:
  57.     virtual void Destroy(); // destroys everything--to re-load new toolbars?
  58.     virtual void Refresh(); // called when system colors, etc change
  59.     static  HBITMAP GetMFCDotBitmap();    // get..
  60.     static  void    FixMFCDotBitmap();    // and fix MFC's dot bitmap
  61.     static BOOL bTRACE;    // Set TRUE to see extra diagnostics in DEBUG code
  62.  
  63. protected:
  64.     CFrameWnd*        m_pFrame;        // frame window I belong to
  65.     CUIntArray        m_arToolbarID;    // array of toolbar IDs loaded
  66.     CImageList        m_ilButtons;    // image list for all buttons
  67.     CMapWordToPtr    m_mapIDtoImage;// maps command ID -> image list index
  68.     CMapWordToPtr    m_mapIDtoAccel;// maps command ID -> ACCEL*
  69.     HACCEL            m_hAccel;        // current accelerators, if any
  70.     ACCEL*            m_pAccel;        // ..and table in memory
  71.     CPtrList            m_menuList;        // list of HMENU's initialized
  72.     CSize                m_szBitmap;        // size of button bitmap
  73.     CSize                m_szButton;        // size of button (including shadow)
  74.     CFont                m_fontMenu;        // menu font
  75.  
  76.     // helpers
  77.     void DestroyAccel();
  78.     void DrawMenuText(CDC& dc, CRect rc, CString text, COLORREF color);
  79.     BOOL Draw3DCheckmark(CDC& dc, const CRect& rc, BOOL bSelected,
  80.                 HBITMAP hbmCheck=NULL);
  81.     void ConvertMenu(CMenu* pMenu,UINT nIndex,BOOL bSysMenu,BOOL bShowButtons);
  82.     void LoadAccel(HACCEL hAccel);
  83.     BOOL AppendAccelName(CString& sItemName, UINT nID);
  84.     CFont* GetMenuFont();
  85.  
  86.     // Get button index for given command ID, or -1 if not found
  87.     int  GetButtonIndex(WORD nID) {
  88.         void* val;
  89.         return m_mapIDtoImage.Lookup(nID, val) ? (int)val : -1;
  90.     }
  91.  
  92.     // Get ACCEL structure associated with a given command ID
  93.     ACCEL* GetAccel(WORD nID) {
  94.         void* val;
  95.         return m_mapIDtoAccel.Lookup(nID, val) ? (ACCEL*)val : NULL;
  96.     }
  97.  
  98.     // window proc to hook frame using CSubclassWnd implementation
  99.     virtual LRESULT WindowProc(UINT msg, WPARAM wp, LPARAM lp);
  100.  
  101.     // CSubclassWnd message handlers 
  102.     virtual void OnInitMenuPopup(CMenu* pMenu, UINT nIndex, BOOL bSysMenu);
  103.     virtual BOOL OnMeasureItem(LPMEASUREITEMSTRUCT lpms);
  104.     virtual BOOL OnDrawItem(LPDRAWITEMSTRUCT lpds);
  105.     virtual LONG OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu);
  106.     virtual void OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu);
  107. };
  108.  
  109. //////////////////
  110. // Friendly version of MENUITEMINFO initializes itself
  111. //
  112. struct CMenuItemInfo : public MENUITEMINFO {
  113.     CMenuItemInfo()
  114.     { memset(this, 0, sizeof(MENUITEMINFO));
  115.       cbSize = sizeof(MENUITEMINFO);
  116.     }
  117. };
  118.  
  119. #endif