home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / include / Toolbar.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-11  |  2.6 KB  |  76 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   : toolbar.cpp                                                         //
  10. //  Description: Toolbar class                                                       //
  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.  
  22. void KToolbar::Create(HWND hParent, HINSTANCE hInst, UINT nControlID, const TBBUTTON * pButtons, int nCount)
  23. {
  24.     m_ControlID = nControlID;
  25.     m_hWnd      = CreateToolbarEx(hParent, WS_CHILD | WS_BORDER | WS_VISIBLE,
  26.                             nControlID,     40,
  27.                             (HINSTANCE) HINST_COMMCTRL,    IDB_VIEW_LARGE_COLOR,
  28.                             pButtons, nCount, 
  29.                             24, 24, 30, 30, sizeof(TBBUTTON) );
  30.  
  31. //    SendMessage(m_hWnd, TB_SETBITMAPSIZE, 0, MAKELONG(20, 20));
  32.  
  33.     m_hToolTip  = CreateWindowEx(0, TOOLTIPS_CLASS, NULL, TTS_ALWAYSTIP,
  34.                         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  35.                         hParent, NULL,
  36.                         hInst, NULL);
  37.  
  38.     m_ResInstance = (HINSTANCE) HINST_COMMCTRL;
  39.     m_ResId       = IDB_VIEW_LARGE_COLOR;
  40.  
  41.     TOOLINFO ti;
  42.  
  43.     ti.cbSize = sizeof(TOOLINFO);
  44.     ti.hwnd   = m_hWnd;
  45.     ti.hinst  = hInst;
  46.     ti.uFlags = TTF_SUBCLASS;
  47.  
  48.     for (int i=0; i<nCount; i++)
  49.         if (pButtons[i].fsStyle == TBSTYLE_BUTTON)
  50.         {
  51.             TCHAR Str[MAX_PATH];
  52.  
  53.             SendMessage(m_hWnd, TB_GETITEMRECT, i, (LPARAM) & ti.rect);
  54.  
  55.             LoadString(hInst, pButtons[i].dwData, Str, sizeof(Str));
  56.             
  57.             ti.uId      = pButtons[i].idCommand;
  58.             ti.lpszText = Str;
  59.  
  60.             SendMessage(m_hToolTip, TTM_ADDTOOL, 0, (LPARAM) & ti);
  61.         }
  62.  
  63.     // set the tooltip control as part of the toolbar
  64.     SendMessage(m_hWnd, TB_SETTOOLTIPS, (WPARAM) m_hToolTip, 0);
  65. }
  66.  
  67.  
  68. void KToolbar::Resize(HWND hParent, int width, int height)
  69. {
  70.     RECT Self;
  71.  
  72.     GetClientRect(m_hWnd, & Self);
  73.  
  74.     MoveWindow(m_hWnd, 0, 0, width, Self.bottom - Self.top, TRUE);    
  75. }
  76.