home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / samples / c05 / owndraw / bmapmenu.cpp next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  1.1 KB  |  61 lines

  1. // BMapMenu.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "OwnDraw.h"
  6. #include "BMapMenu.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CBitmapMenu
  16. CBitmapMenu::CBitmapMenu()
  17. {
  18.     m_pBitmaps = new CBitmap[4];
  19.     VERIFY(CreateMenu());
  20. }
  21.  
  22. CBitmapMenu::~CBitmapMenu()
  23. {
  24.     delete m_pBitmaps;
  25.     Detach();
  26.     ASSERT(m_hMenu == NULL);
  27. }
  28.  
  29. void CBitmapMenu::AppendBitmapMenuItem(UINT nID)
  30. {
  31.     UINT bitmapID;
  32.     int index;
  33.     
  34.     // Determine which bitmap to load.
  35.     switch (nID)
  36.     {
  37.         case IDR_COLOR_RED:
  38.             index = 0;
  39.             bitmapID = IDB_RED;
  40.             break;
  41.         case IDR_COLOR_GREEN:
  42.             index = 1;
  43.             bitmapID = IDB_GREEN;
  44.             break;
  45.         case IDR_COLOR_BLUE:
  46.             index = 2;
  47.             bitmapID = IDB_BLUE;
  48.             break;
  49.         default:
  50.             index = 3;
  51.             bitmapID = IDB_BLACK;
  52.     }
  53.     
  54.     // Load it into one of the CBitmap objects.
  55.     m_pBitmaps[index].LoadBitmap(bitmapID);
  56.     
  57.     // Append it to the menu. Note that the bitmap MUST
  58.     // be persistent.
  59.     AppendMenu(MF_ENABLED, nID, &m_pBitmaps[index]);
  60. }
  61.