root / trunk / win / Bmpmenu.h

Revision 496, 5.2 kB (checked in by leo, 3 years ago)

Better menu title class.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1// BMPMenu.h : header file
2// Version : 2.3
3
4#include <afxtempl.h>
5
6#ifndef _BMPMENU_H_
7#define _BMPMENU_H_
8
9// CBMPMenuData class. Fill this class structure to define a single menu item:
10
11class CBMPMenuData
12{
13wchar_t *m_szMenuText;
14public:
15CBMPMenuData () {menuIconNormal=-1;xoffset=-1;bitmap=NULL;
16               nFlags=0;nID=0;syncflag=0;m_szMenuText=NULL;};
17void SetAnsiString(LPCSTR szAnsiString);
18void SetWideString(const wchar_t *szWideString);
19const wchar_t *GetWideString(void) {return m_szMenuText;};
20~CBMPMenuData ();
21CString GetString(void);//returns the menu text in ANSI or UNICODE
22int xoffset;
23int menuIconNormal;
24UINT nFlags,nID,syncflag;
25CImageList *bitmap;
26};
27
28//struct CMenuItemInfo : public MENUITEMINFO {
29struct CMenuItemInfo : public
30//MENUITEMINFO
31#ifndef UNICODE   //SK: this fixes warning C4097: typedef-name 'MENUITEMINFO' used as synonym for class-name 'tagMENUITEMINFOA'
32tagMENUITEMINFOA
33#else
34tagMENUITEMINFOW
35#endif
36    {
37    CMenuItemInfo()
38    { memset(this, 0, sizeof(MENUITEMINFO));
39      cbSize = sizeof(MENUITEMINFO);
40    }
41};
42
43
44
45
46typedef enum {Normal,TextOnly} HIGHLIGHTSTYLE;
47
48#ifndef UNICODE
49#define AppendODMenu AppendODMenuA
50#define ModifyODMenu ModifyODMenuA
51#else
52#define AppendODMenu AppendODMenuW
53#define ModifyODMenu ModifyODMenuW
54#endif
55
56
57
58class CBMPMenu : public CMenu  // Derived from CMenu
59{
60    // Construction
61public:
62    CBMPMenu();
63    // Attributes
64protected:
65    CTypedPtrArray<CPtrArray, CBMPMenuData*> m_MenuList;  // Stores list of menu items
66    // When loading an owner-drawn menu using a Resource, CBMPMenu must keep track of
67    // the popup menu's that it creates. Warning, this list *MUST* be destroyed
68    // last item first :)
69    CImageList m_List;
70   
71    CTypedPtrArray<CPtrArray, CBMPMenu*>  m_SubMenus;  // Stores list of sub-menus
72    // Operations
73public:
74    // Overrides
75    // ClassWizard generated virtual function overrides
76    //{{AFX_VIRTUAL(CCustomMenu)
77    //}}AFX_VIRTUAL
78    // Implementation
79public:
80    static BOOL IsNewShell(void);
81    void SetBitmapBackground(COLORREF color);
82    void SetDisableOldStyle(void);
83    void UnSetDisableOldStyle(void);
84    BOOL GetDisableOldStyle(void);
85    void UnSetBitmapBackground(void);
86    int AddBitmapToImageList(CImageList *list,UINT nResourceID);
87    BOOL LoadFromToolBar(UINT nID,UINT nToolBar,int& xoffset);
88    void InsertSpaces(void);
89    static LRESULT FindKeyboardShortcut(UINT nChar,UINT nFlags,CMenu *pMenu);
90    static void UpdateMenu(CMenu *pmenu);
91    BOOL IsMenu(CMenu *submenu);
92    void DrawCheckMark(CDC *pDC,int x,int y,COLORREF color);
93    void DrawRadioDot(CDC *pDC,int x,int y,COLORREF color);
94    CBMPMenu *FindMenuOption(int nId,int& nLoc);
95    CBMPMenuData *FindMenuOption(wchar_t *lpstrText);
96    BOOL GetMenuText(UINT id,CString &string);
97    CImageList *checkmaps;
98    BOOL checkmapsshare;
99    int m_selectcheck;
100    int m_unselectcheck;
101    void LoadCheckmarkBitmap(int unselect,int select);
102    void DitherBlt(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HBITMAP hbm, int nXSrc, int nYSrc);
103    void DitherBlt2(CDC *drawdc, int nXDest, int nYDest, int nWidth, int nHeight, CBitmap &bmp, int nXSrc, int nYSrc);
104    HBITMAP LoadSysColorBitmap(int nResourceId);
105   
106    virtual ~CBMPMenu();  // Virtual Destructor
107    // Drawing:
108    virtual void DrawItem( LPDRAWITEMSTRUCT);  // Draw an item
109    virtual void MeasureItem( LPMEASUREITEMSTRUCT );  // Measure an item
110   
111    // Customizing:
112   
113    void SetIconSize (int, int);  // Set icon size
114   
115    BOOL AppendODMenuA(LPCSTR lpstrText, UINT nFlags = MF_OWNERDRAW, UINT nID = 0, int nIconNormal = -1); // Owner-Drawn Append
116    BOOL AppendODMenuW(wchar_t *lpstrText, UINT nFlags = MF_OWNERDRAW, UINT nID = 0, int nIconNormal = -1); // Owner-Drawn Append
117   
118    BOOL ChangeMenuItemShortcut(const char *Shortcut, UINT nID);
119    BOOL DeleteMenu(UINT nPosition, UINT nFlags);
120    BOOL ModifyODMenuA(const char *lpstrText,UINT nID=0,int nIconNormal=-1);
121    BOOL ModifyODMenuA(const char *lpstrText,const char *OptionText,int nIconNormal);
122    BOOL ModifyODMenuW(wchar_t *lpstrText,UINT nID=0,int nIconNormal=-1);
123    BOOL ModifyODMenuW(wchar_t *lpstrText,wchar_t *OptionText,int nIconNormal);
124    CBMPMenuData *NewODMenu(UINT pos,UINT nFlags,UINT nID,CString string);
125    void SynchronizeMenu(void);
126    void CBMPMenu::InitializeMenuList(int value);
127    void CBMPMenu::DeleteMenuList(void);
128    CBMPMenuData *CBMPMenu::FindMenuList(UINT nID);
129    virtual BOOL LoadMenu(LPCTSTR lpszResourceName);  // Load a menu
130    virtual BOOL LoadMenu(int nResource);  // ...
131    void AddFromToolBar(CToolBar* pToolBar, int nResourceID);
132    BOOL Draw3DCheckmark(CDC *dc, const CRect& rc,BOOL bSelected, HBITMAP hbmCheck);
133    BOOL LoadToolbar(UINT nToolBar);
134    BOOL LoadToolbars(const UINT *arID,int n);
135   
136    // Destoying:
137   
138    virtual BOOL DestroyMenu();
139   
140    // Generated message map functions
141protected:
142    int m_iconX,m_iconY;
143    COLORREF m_bitmapBackground;
144    BOOL m_bitmapBackgroundFlag;
145    BOOL disable_old_style;
146};
147
148// ============================================================================
149
150class CTitleMenu : public CMenu
151{
152public:
153    CTitleMenu();
154    virtual ~CTitleMenu();
155
156// Operations
157public:
158    void SetMenuTitle(UINT ID, const char* Title);
159
160// Implementation
161public:
162    virtual void MeasureItem(LPMEASUREITEMSTRUCT lpMIS);
163    virtual void DrawItem(LPDRAWITEMSTRUCT lpDIS);
164
165protected:
166    CFont m_Font;
167    HFONT CreateTitleFont();
168    CMap<int, int, const char*, const char*> m_TitleStrings;
169};
170
171#endif
Note: See TracBrowser for help on using the browser.