1 #ifndef _ODMENU_CLW 2 #define _ODMENU_CLW 3 4 #include <windows.h> 5 #include <map> 6 #include <string> 7 8 using namespace std; 9 10 enum bitmapType {eNormal, eDisabled, eShadow, eFaded}; 11 12 typedef struct tagODMENUITEM 13 { 14 UINT dwType; 15 UINT wID; 16 string rawText; 17 string displayText; 18 string rawDisplayText; 19 string shortcutText; 20 HBITMAP hBitmap; 21 bool topMost; 22 23 } ODMENUITEM; 24 25 typedef map<UINT, ODMENUITEM> ODMENUITEMS; 26 27 class ODMenu 28 { 29 //Aesthetic parameters 30 COLORREF m_clrIconBar; 31 COLORREF m_clrTranparent; 32 COLORREF m_clrItemText; 33 COLORREF m_clrItemBackground; 34 COLORREF m_clrHighlightItemText; 35 COLORREF m_clrHighlightItemBackground; 36 COLORREF m_clrHighlightItemOutline; 37 COLORREF m_clrSeparator; 38 COLORREF m_clrIconShadow; 39 COLORREF m_clrCheckMark; 40 COLORREF m_clrCheckMarkBackground; 41 COLORREF m_clrCheckMarkBackgroundHighlight; 42 UINT m_iconBarMargin; 43 UINT m_iconWidth; 44 UINT m_iconHeight; 45 UINT m_textLeftMargin; 46 UINT m_textRightMargin; 47 UINT m_verticalSpacing; 48 49 //GDI object handles 50 HBRUSH m_hIconBarBrush; 51 HBRUSH m_hIconShadowBrush; 52 HBRUSH m_hCheckMarkBackgroundBrush; 53 HBRUSH m_hCheckMarkBackgroundHighlightBrush; 54 HBRUSH m_hItemBackground; 55 HBRUSH m_hHighlightItemBackgroundBrush; 56 HPEN m_hSelectionOutlinePen; 57 HPEN m_hSeparatorPen; 58 HPEN m_hCheckMarkPen; 59 HFONT m_hFont; 60 61 UINT m_seqNumber; 62 HMENU m_hRootMenu; 63 TCHAR m_szItemText[256]; 64 ODMENUITEMS m_menuItems; 65 66 int m_alpDx[256]; 67 68 void EnumMenuItems(HMENU hMenu); 69 void DeleteSubMenu(HMENU hMenu); 70 void SetMenuItemOwnerDrawn(HMENU hMenu, UINT item, UINT type); 71 void GenerateDisplayText(ODMENUITEM& item); 72 void DrawItemText(DRAWITEMSTRUCT* lpdis, ODMENUITEM& item); 73 void DrawIconBar(DRAWITEMSTRUCT* lpdis, ODMENUITEM& item); 74 void ComputeMenuTextPos(DRAWITEMSTRUCT* lpdis, ODMENUITEM& item, int& x, int& y, SIZE& size); 75 void DrawTransparentBitmap(HDC hDC, HBITMAP hBitmap, short xStart, short yStart, 76 COLORREF cTransparentColor, bitmapType eType=eNormal); 77 void DrawCheckMark(HDC hDC, short x, short y, bool bNarrow=true); 78 COLORREF LightenColor(COLORREF col, double factor); 79 COLORREF DarkenColor(COLORREF col, double factor); 80 COLORREF AverageColor(COLORREF col1, COLORREF col2, double weight1=0.5); 81 double GetColorIntensity(COLORREF col); 82 83 public: 84 ODMenu(); 85 ~ODMenu(); 86 87 bool Init(HWND hOwnerWnd, HMENU hMenu); 88 void MeasureItem(HWND hWnd, LPARAM lParam); 89 void DrawItem(HWND hWnd, LPARAM lParam); 90 void OnDestroy(); 91 bool GetItem(UINT id, ODMENUITEM** ppItem); 92 void SetItemImage(HINSTANCE hInst, UINT wID, UINT idBitmap); 93 void AddItem(HMENU hMenu, int index, MENUITEMINFO* pItemInfo=NULL); 94 void DeleteItem(HMENU hMenu, int index); 95 }; 96 97 #endif