home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / PVIEW95.PAK / TOOLBAR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  2.8 KB  |  108 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:   toolbar.c
  9. //
  10. //  PURPOSE:  Handles all toolbar manipulation.
  11. //
  12. //  FUNCTIONS:
  13. //    CreateAppToolbar -   Creates the toolbar control and adds buttons
  14. //    Toolbar_OnNeedText - Provides tooltip text for WM_NOTIFY/TTN_NEEDTEXT
  15. //       
  16. //  COMMENTS:
  17. //
  18. #include <windows.h>
  19. #include <commctrl.h>
  20. #include "globals.h"
  21. #include "resource.h"
  22.  
  23. #define NUM_BITMAPS 2
  24.  
  25. //
  26. //  FUNCTION: CreateAppToolbar(HWND, WORD)
  27. //
  28. //  PURPOSE:  Creates the toolbar control and adds buttoms
  29. //
  30. //  PARAMETERS:
  31. //    hwndParent - Handle of the parent window.
  32. //    wID           - Control identifier
  33. //
  34. //  RETURN VALUE:
  35. //    The window handle of the newly created toolbar control if successful, 
  36. //    or NULL if a new toolbar control could not be created.
  37. //
  38. //
  39.  
  40. HWND CreateAppToolbar(HWND hwndParent, WORD wID)
  41. {
  42.     HWND      hwndToolbar;    // window handle for the toolbar
  43.  
  44.     TBBUTTON tbButtons[] =     // array of buttons for the toolbar
  45.  
  46.     // the struct goes like this:
  47.     // bitmap index, WM_COMMAND id, state, style, reserved bytes, app data,
  48.     // string index
  49.     // Note that the reserved bytes exist only for Win32 targets
  50.     {
  51.         { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, {0, 0}, 0, 0 },
  52.         { 0, ID_PROCESS_REFRESH, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 },
  53.         { 1, ID_PROCESS_KILL, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0, 0}, 0, 0 }
  54.     };
  55.  
  56.     // Ensure that the common control DLL is loaded
  57.     InitCommonControls();
  58.  
  59.     // Create a toolbar that is customizable and has the tooltips enabled
  60.     hwndToolbar = CreateToolbarEx(hwndParent, WS_CHILD | TBSTYLE_TOOLTIPS,
  61.             wID, NUM_BITMAPS, hInst, IDB_TOOLBAR, tbButtons,
  62.             sizeof(tbButtons) / sizeof(TBBUTTON), 0, 16, 16, 15, 
  63.             sizeof(TBBUTTON));
  64.  
  65.     if (!hwndToolbar)
  66.         return NULL;
  67.  
  68.     ShowWindow(hwndToolbar, SW_SHOW);
  69.     return hwndToolbar;
  70. }
  71.  
  72.  
  73. //
  74. //  FUNCTION: Toolbar_OnNeedText(int, LPTOOLTIPTEXT)
  75. //
  76. //  PURPOSE:  Supplies the string table id for the tooltip.
  77. //
  78. //  PARAMETERS:
  79. //        
  80. //        idFrom - Identifies the control sending the notification
  81. //        lpttt  - Provides information about which button needs tooltip text
  82. //
  83. //  RETURN VALUE:
  84. //
  85. //    Always returns 0 - Message handled
  86. //
  87. //  COMMENTS:
  88. //
  89. //
  90.  
  91. #pragma argsused
  92. LRESULT Toolbar_OnNeedText(int idFrom, LPTOOLTIPTEXT lpttt)
  93. {
  94.     switch (lpttt->hdr.idFrom)    
  95.     {
  96.         // return the string table resource id for the appropriate string
  97.         case ID_PROCESS_REFRESH:
  98.             lpttt->lpszText = MAKEINTRESOURCE(IDS_TIP_REFRESH);
  99.             break;
  100.  
  101.         case ID_PROCESS_KILL:
  102.             lpttt->lpszText = MAKEINTRESOURCE(IDS_TIP_KILL);
  103.             break;
  104.     }
  105.  
  106.     return 0;
  107. }
  108.