home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / include / BitmapMenu.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  2.1 KB  |  62 lines

  1. //-----------------------------------------------------------------------------------//
  2. //              Windows Graphics Programming: Win32 GDI and DirectDraw               //
  3. //                             ISBN  0-13-086985-6                                   //
  4. //                                                                                   //
  5. //  Written            by  Yuan, Feng                             www.fengyuan.com   //
  6. //  Copyright (c) 2000 by  Hewlett-Packard Company                www.hp.com         //
  7. //  Published          by  Prentice Hall PTR, Prentice-Hall, Inc. www.phptr.com      //
  8. //                                                                                   //
  9. //  FileName   : bitmapmenu.cpp                                                         //
  10. //  Description: Adding DDB to menu                                                  //
  11. //  Version    : 1.00.000, May 31, 2000                                              //
  12. //-----------------------------------------------------------------------------------//
  13.  
  14. #define STRICT
  15. #define _WIN32_WINNT 0x0500
  16. #define NOCRYPT
  17.  
  18. #include <windows.h>
  19. #include <assert.h>
  20. #include <tchar.h>
  21.  
  22.  
  23. #include "BitmapMenu.h"
  24.  
  25. // process command: 0: not processed, 1: no change, 2: changed
  26. int KBitmapMenu::OnCommand(int nCmdId)
  27. {
  28.     int n = nCmdId - m_nFirstCommand;
  29.  
  30.     if ( (n<0) || (n>=m_nBitmap) )
  31.         return 0;
  32.  
  33.     if ( n==m_nChecked )
  34.         return 1;
  35.  
  36.     CheckMenuItem(m_hMenu, m_nFirstCommand + m_nChecked, MF_BYCOMMAND | MF_UNCHECKED);
  37.     m_nChecked = n;
  38.     CheckMenuItem(m_hMenu, m_nFirstCommand + m_nChecked, MF_BYCOMMAND | MF_CHECKED);
  39.  
  40.     return 2;
  41. }
  42.  
  43.  
  44. void KBitmapMenu::AddToMenu(HMENU hMenu, int nCount, HMODULE hModule, const int nID[], int nFirstCommand)
  45. {
  46.     m_hMenu    = hMenu;
  47.     m_nBitmap  = nCount;
  48.     m_nChecked = 0;
  49.     m_nFirstCommand = nFirstCommand;
  50.  
  51.     for (int i=0; i<nCount; i++)
  52.     {
  53.         m_hBitmap[i] = LoadBitmap(hModule, MAKEINTRESOURCE(nID[i]));
  54.  
  55.         if ( m_hBitmap[i] )
  56.             AppendMenu(hMenu, MF_BITMAP, nFirstCommand + i, (LPCTSTR) m_hBitmap[i]);
  57.     }
  58.     
  59.     CheckMenuItem(m_hMenu, m_nChecked + nFirstCommand, MF_BYCOMMAND | MF_CHECKED);
  60. }
  61.  
  62.