[6a7162]: CoolMenu.h  Maximize  Restore  History

Download this file

123 lines (102 with data), 4.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* Copyright (c) 2003-2008 Rony Shapiro <ronys@users.sourceforge.net>.
* All rights reserved. Use of the code is allowed under the
* Artistic License 2.0 terms, as specified in the LICENSE file
* distributed with this code, or available from
* http://www.opensource.org/licenses/artistic-license-2.0.php
*/
#pragma once
////////////////////////////////////////////////////////////////
// 1997 Microsoft Systems Journal.
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
// Modified for PWS toolbar
// Remove automatic accelerators
// Updated for VS2005 + UNICODE
// Change from MS classes to STL eqivalents where possible
// Understand that RUE menu also uses MENUITEMINFO dwItemData field for icons
#include "SubClass.h"
#include "PWToolbar.h"
#include <vector>
#include <map>
#include <algorithm>
//////////////////
// CCoolMenuManager implements "cool" menus with buttons in them. To use:
//
// * Instantiate in your CMainFrame.
// * Call Install to install it
//
// identifies owner-draw data as mine
const long COOLMENUITEMID = MAKELONG(MAKEWORD('C', 'M'),MAKEWORD('I', 'D'));
// private struct: one of these for each owner-draw menu item
struct CMenuItemData {
long magicNum; // magic number identifying me
CString text; // item text
UINT fType; // original item type flags
int iButton; // index of button image in image list
CMenuItemData() { magicNum = COOLMENUITEMID; }
BOOL IsCMID() { return magicNum == COOLMENUITEMID; }
};
typedef std::vector<HMENU> MenuVector;
typedef MenuVector::iterator MenuVectorIter;
typedef std::vector<CMenuItemData *> PMDVector;
typedef PMDVector::iterator PMDVectorIter;
class CCoolMenuManager : private CSubclassWnd
{
public:
DECLARE_DYNAMIC(CCoolMenuManager)
CCoolMenuManager();
~CCoolMenuManager();
void CleanUp();
// You can set these any time
BOOL m_bShowButtons; // use to control whether buttons are shown
// public functions to use
void Install(CWnd* pWnd) { HookWindow(pWnd); }
void SetImageList(CPWToolBar *pwtoolbar);
void SetMapping(CPWToolBar *pwtoolbar)
{pwtoolbar->MapControlIDtoImage(m_IDtoImages);}
// should never need to call:
static HBITMAP GetMFCDotBitmap(); // get..
static void FixMFCDotBitmap(); // and fix MFC's dot bitmap
protected:
CImageList m_ImageList; // image list for all buttons
CImageList m_DisabledImageList; // disabled image list for all buttons
MenuVector m_menuList; // list of HMENU's initialized
PMDVector m_pmdList; // Vector of ptrs to CMenuItemData
CSize m_szBitmap; // size of button bitmap
CSize m_szButton; // size of button (including shadow)
CFont m_fontMenu; // menu font
ID2ImageMap m_IDtoImages; // To obtain image ID from Control ID
bool m_bNoDIL; // "true" if No Disabled Image List i.e. Classic toolbar
// helpers
void DrawMenuText(CDC& dc, CRect rc, CString text, COLORREF color);
BOOL Draw3DCheckmark(CDC& dc, const CRect& rc, BOOL bSelected,
HBITMAP hbmCheck = NULL);
void ConvertMenu(CMenu* pMenu,UINT nIndex,BOOL bSysMenu,BOOL bShowButtons);
CFont* GetMenuFont();
void FillRect(CDC& dc, const CRect& rc, COLORREF color);
void DrawEmbossed(CDC& dc, CImageList &il, int iBtn, CPoint p);
// Get button index for given command ID, or -1 if not found
int GetButtonIndex(UINT nID) {
ID2ImageMapIter iter = m_IDtoImages.find(nID);
return iter != m_IDtoImages.end() ? iter->second : -1;
}
// window proc to hook frame using CSubclassWnd implementation
virtual LRESULT WindowProc(UINT msg, WPARAM wp, LPARAM lp);
// CSubclassWnd message handlers
virtual void OnInitMenuPopup(CMenu* pMenu, UINT nIndex, BOOL bSysMenu);
virtual BOOL OnMeasureItem(LPMEASUREITEMSTRUCT lpms);
virtual BOOL OnDrawItem(LPDRAWITEMSTRUCT lpds);
virtual LONG OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu);
virtual void OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu);
};
//////////////////
// Friendly version of MENUITEMINFO initializes itself
//
struct CMenuItemInfo : public MENUITEMINFO {
CMenuItemInfo()
{ memset(this, 0, sizeof(MENUITEMINFO));
cbSize = sizeof(MENUITEMINFO);
}
};

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks