home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows 95 / Programming Windows 95.iso / code / CHAP12 / TOOLTIP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-01  |  3.2 KB  |  115 lines

  1. /*---------------------------------------
  2.    TOOLTIP.C -- Tooltip helper functions
  3.                 (c) Paul Yao, 1996
  4.   ---------------------------------------*/
  5. #include <windows.h>
  6. #include <commctrl.h>
  7. #include "comcthlp.h"
  8. #include "notifdef.h"
  9. #include "gadgets.h"
  10.  
  11. extern BOOL bComboBox;
  12. extern char szTbStrings[];
  13. extern HINSTANCE hInst;
  14. extern HWND hwndEdit;
  15. extern HWND hwndCombo;
  16. extern HWND hwndEdit;
  17. static HWND hwndTT;
  18.  
  19. // Map toolbar button command to string index. 
  20. int CommandToString[] = 
  21.      { IDM_FILE_NEW, IDM_FILE_OPEN, IDM_FILE_SAVE, IDM_FILE_PRINT,
  22.        IDM_FILE_PREVIEW, IDM_EDIT_CUT, IDM_EDIT_COPY, IDM_EDIT_PASTE,
  23.        IDM_EDIT_UNDO, IDM_EDIT_PROP, IDM_TB_HELP, IDM_TB_DELETE, -1   
  24.      } ;
  25.  
  26. //-------------------------------------------------------------------
  27. BOOL InitToolTip (HWND hwndToolBar, HWND hwndComboBox)
  28.      {
  29.      BOOL bSuccess ;
  30.      TOOLINFO ti ;
  31.  
  32.      // Fetch handle to tooltip control
  33.      hwndTT = ToolBar_GetToolTips (hwndToolBar) ;
  34.      if (hwndTT == NULL) 
  35.           return FALSE ;
  36.  
  37.      // Add tooltip for main combo box
  38.      ZeroMemory (&ti, sizeof (TOOLINFO)) ;
  39.      ti.cbSize = sizeof (TOOLINFO) ;
  40.      ti.uFlags = TTF_IDISHWND | TTF_CENTERTIP | TTF_SUBCLASS ;
  41.      ti.hwnd   = hwndToolBar ;
  42.      ti.uId    = (UINT) (HWND) hwndComboBox ;
  43.      ti.lpszText = LPSTR_TEXTCALLBACK ;
  44.      bSuccess = ToolTip_AddTool (hwndTT, &ti) ;
  45.      if (!bSuccess)
  46.           return FALSE ;
  47.  
  48.      // Add tooltip for combo box's edit control
  49.      hwndEdit = GetWindow (hwndComboBox, GW_CHILD) ;
  50.      ti.uId    = (UINT) (HWND) hwndEdit ;
  51.      bSuccess = ToolTip_AddTool (hwndTT, &ti) ;
  52.  
  53.      return bSuccess ;
  54.      }
  55.  
  56. //-------------------------------------------------------------------
  57. void CopyToolTipText (LPTOOLTIPTEXT lpttt)
  58.      {
  59.      int i ;
  60.      int iButton = lpttt->hdr.idFrom ;
  61.      int cb ;
  62.      int cMax ;
  63.      LPSTR pString ;
  64.      LPSTR pDest = lpttt->lpszText ;
  65.  
  66.      // Check for combo box window handles
  67.      if (lpttt->uFlags & TTF_IDISHWND)
  68.           {
  69.           if ((iButton == (int) hwndCombo) ||
  70.               (iButton == (int) hwndEdit))
  71.                {
  72.                lstrcpy (pDest, "1-2-3 ComboBox") ;
  73.                return ;
  74.                }
  75.           }
  76.  
  77.      // Map command ID to string index
  78.      for (i = 0 ; CommandToString[i] != -1 ; i++)
  79.           {
  80.           if (CommandToString[i] == iButton)
  81.                {
  82.                iButton = i ;
  83.                break ;
  84.                }
  85.           }
  86.  
  87.      // To be safe, count number of strings in text
  88.      pString = szTbStrings ;
  89.      cMax = 0 ;
  90.      while (*pString != '\0')
  91.           {
  92.           cMax++ ;
  93.           cb = lstrlen (pString) ;
  94.           pString += (cb + 1) ;
  95.           }
  96.  
  97.      // Check for valid parameter
  98.      if (iButton > cMax)
  99.           {
  100.           pString = "Invalid Button Index" ;
  101.           }
  102.      else
  103.           {
  104.           // Cycle through to requested string
  105.           pString = szTbStrings ;
  106.           for (i = 0 ; i < iButton ; i++)
  107.                {
  108.                cb = lstrlen (pString) ;
  109.                pString += (cb + 1) ;
  110.                }
  111.           }
  112.  
  113.      lstrcpy (pDest, pString) ;
  114.      }
  115.