RTMenu.h
上传用户:qhonly
上传日期:2013-06-10
资源大小:487k
文件大小:6k
源码类别:

界面编程

开发平台:

Visual C++

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // MenuXP.h : header file
  4. //
  5. ///////////////////////////////////////////////////////////////////////////////
  6. #pragma once
  7. #include <afxtempl.h>
  8. ///////////////////////////////////////////////////////////////////////////////
  9. // Menu item image management class
  10. class CImgDesc
  11. {
  12. public:
  13.     HIMAGELIST m_hImgList;
  14.     int        m_nIndex;
  15.     CImgDesc (HIMAGELIST hImgList = NULL, int nIndex = 0)
  16.         : m_hImgList (hImgList), m_nIndex (nIndex)
  17.     {
  18.     }
  19. };
  20. ///////////////////////////////////////////////////////////////////////////////
  21. class CRTMenu
  22. {
  23. // Operations
  24. public:
  25.     static void InitializeHook ();
  26.     static void UninitializeHook ();
  27.     static void SetXPLookNFeel (CWnd* pWnd, BOOL bXPLook = TRUE);
  28.     static bool GetXPLookNFeel (const CWnd* pWnd);
  29.     static void UpdateMenuBar (CWnd* pWnd);
  30.     static void SetXPLookNFeel (CWnd* pWnd, HMENU hMenu, BOOL bXPLook = TRUE, BOOL bMenuBar = FALSE);
  31.     static bool IsOwnerDrawn (HMENU hMenu);
  32.     static void SetMRUMenuBarItem (RECT& rc);
  33.     static void SetMenuItemImage (UINT nID, HIMAGELIST hImgList, int nIndex);
  34.     static void OnMeasureItem (MEASUREITEMSTRUCT* pMeasureItemStruct);
  35.     static bool OnDrawItem (DRAWITEMSTRUCT* pDrawItemStruct, HWND hWnd);
  36.     static LRESULT OnMenuChar (HMENU hMenu, UINT nChar, UINT nFlags);
  37. static void SetMenuBarBitmap(CBitmap* MenuBarBitamp[],UINT DrawMode[]);
  38. static void SetMenuItemBitmap(CBitmap* MenuItemBitmap[],UINT DrawMode[]);
  39. static void EnableSkin(BOOL IsEnable = TRUE);
  40. // Attributes
  41. protected:
  42.     static CMap <int, int, CString, CString&> ms_sCaptions;
  43.     static CMap <HMENU, HMENU, CString, CString&> ms_sSubMenuCaptions;
  44.     static CMap <int, int, CImgDesc, CImgDesc&> ms_Images;
  45.     static CMap <HMENU, HMENU, CImgDesc, CImgDesc&> ms_SubMenuImages;
  46. public:
  47. static CBitmap* m_MenuBarBitmap[5];
  48. static UINT     m_MenuBarBitmapDrawMode[5];
  49. static CBitmap* m_MenuItemBitmap[5];
  50. static UINT     m_MenuItemBitmapDrawMode[5];
  51. static BOOL m_bEnableSkin;
  52. friend class CRTMenuItem;
  53. friend class CRTWndMenu;
  54. };
  55. ///////////////////////////////////////////////////////////////////////////////
  56. #define DECLARE_MENUXP()                                                             
  57.     protected:                                                                       
  58. afx_msg void OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu);     
  59. afx_msg void OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct); 
  60. afx_msg void OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct);          
  61. afx_msg LRESULT OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu);
  62. ///////////////////////////////////////////////////////////////////////////////
  63. #define ON_MENUXP_MESSAGES() 
  64. ON_WM_INITMENUPOPUP()    
  65. ON_WM_MEASUREITEM()      
  66. ON_WM_DRAWITEM()         
  67. ON_WM_MENUCHAR()
  68. ///////////////////////////////////////////////////////////////////////////////
  69. #define IMPLEMENT_MENUXP(theClass, baseClass)                                      
  70.     IMPLEMENT_MENUXP_(theClass, baseClass, CRTMenu::GetXPLookNFeel (this))
  71. ///////////////////////////////////////////////////////////////////////////////
  72. #define IMPLEMENT_MENUXP_(theClass, baseClass, bFlag)                              
  73.     void theClass::OnInitMenuPopup (CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu) 
  74.     {                                                                              
  75.     baseClass::OnInitMenuPopup (pPopupMenu, nIndex, bSysMenu);                 
  76.         CRTMenu::SetXPLookNFeel (this, pPopupMenu->m_hMenu,                        
  77.                                  bFlag/* && !bSysMenu*/);                          
  78.     }                                                                              
  79.     void theClass::OnMeasureItem (int, LPMEASUREITEMSTRUCT lpMeasureItemStruct)    
  80.     {                                                                              
  81.         CRTMenu::OnMeasureItem (lpMeasureItemStruct);                              
  82.     }                                                                              
  83.     void theClass::OnDrawItem (int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)      
  84.     {                                                                              
  85.         if ( !CRTMenu::OnDrawItem (lpDrawItemStruct, m_hWnd) )                     
  86.         {                                                                          
  87.             baseClass::OnDrawItem (nIDCtl, lpDrawItemStruct);                      
  88.         }                                                                          
  89.     }                                                                              
  90.     LRESULT theClass::OnMenuChar (UINT nChar, UINT nFlags, CMenu* pMenu)           
  91.     {                                                                              
  92.         if ( CRTMenu::IsOwnerDrawn (pMenu->m_hMenu) )                              
  93.         {                                                                          
  94.             return CRTMenu::OnMenuChar (pMenu->m_hMenu, nChar, nFlags);            
  95.         }                                                                          
  96.     return baseClass::OnMenuChar (nChar, nFlags, pMenu);                       
  97.     }
  98. ///////////////////////////////////////////////////////////////////////////////
  99. //{{AFX_INSERT_LOCATION}}
  100. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.