MenuXP.h
上传用户:ckg1000
上传日期:2013-01-26
资源大小:630k
文件大小:5k
源码类别:

CAD

开发平台:

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 CMenuXP
  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. // Attributes
  38. protected:
  39.     static CMap <int, int, CString, CString&> ms_sCaptions;
  40.     static CMap <HMENU, HMENU, CString, CString&> ms_sSubMenuCaptions;
  41.     static CMap <int, int, CImgDesc, CImgDesc&> ms_Images;
  42.     static CMap <HMENU, HMENU, CImgDesc, CImgDesc&> ms_SubMenuImages;
  43. friend class CMenuItem;
  44. };
  45. ///////////////////////////////////////////////////////////////////////////////
  46. #define DECLARE_MENUXP()                                                             
  47.     protected:                                                                       
  48. afx_msg void OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu);     
  49. afx_msg void OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct); 
  50. afx_msg void OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct);          
  51. afx_msg LRESULT OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu);
  52. ///////////////////////////////////////////////////////////////////////////////
  53. #define ON_MENUXP_MESSAGES() 
  54. ON_WM_INITMENUPOPUP()    
  55. ON_WM_MEASUREITEM()      
  56. ON_WM_DRAWITEM()         
  57. ON_WM_MENUCHAR()
  58. ///////////////////////////////////////////////////////////////////////////////
  59. #define IMPLEMENT_MENUXP(theClass, baseClass)                                      
  60.     IMPLEMENT_MENUXP_(theClass, baseClass, CMenuXP::GetXPLookNFeel (this))
  61. ///////////////////////////////////////////////////////////////////////////////
  62. #define IMPLEMENT_MENUXP_(theClass, baseClass, bFlag)                              
  63.     void theClass::OnInitMenuPopup (CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu) 
  64.     {                                                                              
  65.     baseClass::OnInitMenuPopup (pPopupMenu, nIndex, bSysMenu);                 
  66.         CMenuXP::SetXPLookNFeel (this, pPopupMenu->m_hMenu,                        
  67.                                  bFlag/* && !bSysMenu*/);                          
  68.     }                                                                              
  69.     void theClass::OnMeasureItem (int, LPMEASUREITEMSTRUCT lpMeasureItemStruct)    
  70.     {                                                                              
  71.         CMenuXP::OnMeasureItem (lpMeasureItemStruct);                              
  72.     }                                                                              
  73.     void theClass::OnDrawItem (int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)      
  74.     {                                                                              
  75.         if ( !CMenuXP::OnDrawItem (lpDrawItemStruct, m_hWnd) )                     
  76.         {                                                                          
  77.             baseClass::OnDrawItem (nIDCtl, lpDrawItemStruct);                      
  78.         }                                                                          
  79.     }                                                                              
  80.     LRESULT theClass::OnMenuChar (UINT nChar, UINT nFlags, CMenu* pMenu)           
  81.     {                                                                              
  82.         if ( CMenuXP::IsOwnerDrawn (pMenu->m_hMenu) )                              
  83.         {                                                                          
  84.             return CMenuXP::OnMenuChar (pMenu->m_hMenu, nChar, nFlags);            
  85.         }                                                                          
  86.     return baseClass::OnMenuChar (nChar, nFlags, pMenu);                       
  87.     }
  88. ///////////////////////////////////////////////////////////////////////////////
  89. //{{AFX_INSERT_LOCATION}}
  90. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.