home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / include / toolbarb.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-12  |  1.8 KB  |  54 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   : toolbarb.cpp                                                         //
  10. //  Description: Toolbar with bitmap switching                                       //
  11. //  Version    : 1.00.000, May 31, 2000                                              //
  12. //-----------------------------------------------------------------------------------//
  13.  
  14. #define STRICT
  15. #define WIN32_LEAN_AND_MEAN
  16.  
  17. #include <windows.h>
  18. #include <commctrl.h>
  19.  
  20. #include "toolbar.h"
  21. #include "toolbarb.h"
  22. #include "PalLoadBitmap.h"
  23.  
  24. BOOL KToolbarB::SetBitmap(HINSTANCE hInstance, int resourceID)
  25. {
  26.     HPALETTE hPal = CreateSystemPalette();
  27.     HBITMAP  hBmp = PaletteLoadBitmap(hInstance, MAKEINTRESOURCE(resourceID), hPal);
  28.     DeleteObject(hPal);
  29.  
  30.     if ( hBmp )
  31.     {
  32.         TBREPLACEBITMAP rp;
  33.  
  34.         rp.hInstOld = m_ResInstance;
  35.         rp.nIDOld   = m_ResId;
  36.         rp.hInstNew = NULL;
  37.         rp.nIDNew   = (UINT) hBmp;
  38.         rp.nButtons = 40;
  39.  
  40.         SendMessage(m_hWnd, TB_REPLACEBITMAP, 0, (LPARAM) & rp);
  41.  
  42.         if ( m_ResInstance==NULL )
  43.             DeleteObject( (HBITMAP) m_ResId);
  44.  
  45.         m_ResInstance = NULL;
  46.         m_ResId       = (UINT) hBmp;
  47.  
  48.         return TRUE;
  49.     }
  50.     else
  51.         return FALSE;
  52. }
  53.  
  54.