/***********************************************************************/ /* Copyright (C) 2002 Definitive Solutions, Inc. All Rights Reserved. */ /* THIS COMPUTER PROGRAM IS PROPRIETARY AND CONFIDENTIAL TO DEFINITIVE */ /* SOLUTIONS, INC. AND ITS LICENSORS AND CONTAINS TRADE SECRETS OF */ /* DEFINITIVE SOLUTIONS, INC. THAT ARE PROVIDED PURSUANT TO A WRITTEN */ /* AGREEMENT CONTAINING RESTRICTIONS ON USE AND DISCLOSURE. ANY USE, */ /* REPRODUCTION, OR TRANSFER EXCEPT AS PROVIDED IN SUCH AGREEMENT */ /* IS STRICTLY PROHIBITED. */ /***********************************************************************/ ///////////////////////////////////////////////////////////////////////////// // How to add this class to your application. // // Add MyMenu.cpp and MyMenu.h to your project in the usual folders. // // Be sure this line appears in your stdafx.h file (for CToolBar): // // #include // MFC extensions // // There is much more - need to add later ?? // ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // MyMenu.h : header file // Version : 2.2 // Date : May 10, 1998 // Author : Brent Corkum // // Portions of code supplied by: // Ben Ashley,Girish Bharadwaj,Jean-Edouard Lachand-Robert, // Robert Edward Caldecott,Kenny Goers,Leonardo Zide, // Stefan Kuhr // // Bug Fixes: // Stefan Kuhr,Martin Vladic,Kim Yoo Chul,Larry Leonard // // You are free to use/modify this code but leave this header intact. ///////////////////////////////////////////////////////////////////////////// #ifndef MYMENUH_0F8C0B22_2ADE_11d6_8ACA_00B0D0529ED2_INCLUDED_ #define MYMENUH_0F8C0B22_2ADE_11d6_8ACA_00B0D0529ED2_INCLUDED_ #pragma once #include ///////////////////////////////////////////////////////////////////////////// // Unicode support. #ifndef UNICODE #define AppendMyMenu AppendMyMenuA #define ModifyMyMenu ModifyMyMenuA #else #define AppendMyMenu AppendMyMenuW #define ModifyMyMenu ModifyMyMenuW #endif ///////////////////////////////////////////////////////////////////////////// // MyMenuData. Fill this class structure to define a single menu item. // Declare the class depending on this file is in an EXE project or a DLL one. class #ifdef _WINDLL AFX_EXT_CLASS #endif MyMenuData : public CObject { friend class MyMenu; // Construction. public: MyMenuData(); virtual ~MyMenuData(); // Declared but not defined. private: MyMenuData(const MyMenuData& rhs); MyMenuData& operator=(const MyMenuData& rhs); // Interface. public: void SetAnsiString(LPCSTR szAnsiString); CString GetString() const; // Data. private: // The maximum allowed menu item seems to be 256 (in the RC file). But the // maximum file length savable is MAX_PATH (260), so we go with that, and // add one for the NULL at the end. wchar_t m_szMenuText[MAX_PATH + 1]; int m_nXOffset; int m_nMenuIconNormal; UINT m_uiFlags; UINT m_uiID; UINT m_uiSyncFlag; CImageList* m_pilistBitmap; }; ///////////////////////////////////////////////////////////////////////////// // MyMenu class MyMenu : public CMenu { // Construction. public: MyMenu(); virtual ~MyMenu(); // Declared but not defined. private: MyMenu(const MyMenu& rhs); MyMenu& operator=(const MyMenu& rhs); // Operations public: //{{AFX_VIRTUAL(CCustomMenu) //}}AFX_VIRTUAL // Static interface. public: static LRESULT FindKeyboardShortcut(UINT uiChar,UINT uiFlags, CMenu* pMenu); static void UpdateMenu(CMenu* pMenu); // Public data. public: static CPINFO m_CPInfo; // Interface. public: virtual void DrawItem(LPDRAWITEMSTRUCT lpdi); virtual void MeasureItem(LPMEASUREITEMSTRUCT lpdi); // These two "hide" their non-virtual calls in CMenu. This means you can't // use this class to call LoadMenu polymorphically. BOOL LoadMenu(LPCTSTR lpszResourceName); BOOL LoadMenu(UINT uiResourceID); BOOL LoadToolbar(UINT uiToolBar); BOOL LoadToolbars(const UINT* puiIdArray, int nCount); bool IsMenu(const CMenu* pSubMenu) const; BOOL ModifyMyMenuA(const char* pszText, UINT uiID = 0U, int nIconNormal = -1); BOOL ModifyMyMenuA(const char* pszText, const char* pszOptionText, int nIconNormal); BOOL ModifyMyMenuW(wchar_t* pszText, UINT uiID = 0U, int nIconNormal = -1); BOOL ModifyMyMenuW(wchar_t* pszText, wchar_t* pszOptionText, int nIconNormal); void DestroyMenu(); // Implementation. private: enum Win32Type { ShellUnknown = -1, Win32s, Win95, WinNT3, WinNT4orHigher }; static Win32Type GetShell(); bool AddBitmapToImageList(CImageList* pList, UINT uiResourceID); bool LoadFromToolBar(UINT uiID, UINT uiToolBar,int& nXOffset); void InsertSpaces(); void DrawCheckMark(CDC* pDC, int x, int y, COLORREF cr); void DrawRadioDot(CDC* pDC, int x, int y, COLORREF cr); MyMenu* FindMenuOption(UINT uiId, int& nLoc); MyMenuData* FindMenuOption(wchar_t* pszText) const; void LoadCheckmarkBitmap(UINT uiUnselectID, UINT uiSelectID); bool GetMenuText(UINT uiID, CString& s) const; void DitherBlt(CDC* pdcDraw, int nXDest, int nYDest, int nWidth, int nHeight, CBitmap &bmp, int nXSrc, int nYSrc); HBITMAP LoadSysColorBitmap(int nResourceId); BOOL AppendMyMenuA(LPCSTR pszText,UINT uiFlags = MF_OWNERDRAW, UINT uiID = 0U, int nIconNormal = -1); BOOL AppendMyMenuW(wchar_t* pszText, UINT uiFlags = MF_OWNERDRAW, UINT uiID = 0U, int nIconNormal = -1); MyMenuData* NewMyMenu(UINT uiPos, UINT uiFlags, UINT uiID, const CString& sText); void SynchronizeMenu(); void InitializeMenuList(int nValue); void DeleteMenuList(); MyMenuData* FindMenuList(UINT uiID); //void AddFromToolBar(CToolBar* pToolBar, int nResourceID); Currently unused by me. bool Draw3DCheckmark(CDC* pdc, const CRect& rc, BOOL bChecked, HBITMAP hbmCheck); // Data. private: static const int m_nGap; static Win32Type m_Shell; // Stores list of menu items. When loading an owner-drawn menu using a // Resource, MyMenu must keep track of the popup menu's that it creates. // Warning, this list *MUST* be destroyed last item first. CTypedPtrArray m_arMenuData; // Stores list of sub-menus. CTypedPtrArray m_arSubMenus; CImageList* m_pilistCheckMaps; bool m_bCheckMapsShare; UINT m_uiSelectCheckID; UINT m_uiUnselectCheckID; int m_nIconX; int m_nIconY; COLORREF m_crBitmapBackground; }; #endif // MYMENUH_0F8C0B22_2ADE_11d6_8ACA_00B0D0529ED2_INCLUDED_