home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / DirectInput / DIConfig / flextooltip.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-08  |  3.3 KB  |  111 lines

  1. //-----------------------------------------------------------------------------
  2. // File: flextooltip.h
  3. //
  4. // Desc: Implements a tooltip class that displays a text string as a tooltip.
  5. //       CFlexTooltip (derived from CFlexWnd) is used throughout the UI when
  6. //       a control needs to have a tooltip.
  7. //
  8. // Copyright (C) 1999-2001 Microsoft Corporation. All Rights Reserved.
  9. //-----------------------------------------------------------------------------
  10.  
  11. #ifndef __FLEXTOOLTIP_H__
  12. #define __FLEXTOOLTIP_H__
  13.  
  14. struct TOOLTIPINIT
  15. {
  16.     HWND hWndParent;
  17.     int iSBWidth;
  18.     DWORD dwID;
  19.     HWND hWndNotify;
  20.     TCHAR tszCaption[MAX_PATH];
  21. };
  22.  
  23. struct TOOLTIPINITPARAM
  24. {
  25.     HWND hWndParent;
  26.     int iSBWidth;
  27.     DWORD dwID;
  28.     HWND hWndNotify;
  29.     LPCTSTR tszCaption;
  30. };
  31.  
  32. class CFlexToolTip : public CFlexWnd
  33. {
  34.     LPTSTR m_tszText;
  35.     COLORREF m_rgbText, m_rgbBk, m_rgbSelText, m_rgbSelBk, m_rgbFill, m_rgbLine;
  36.     HWND m_hNotifyWnd;
  37.     DWORD m_dwID;  // Used to store offset when owned by a control
  38.     int m_iSBWidth;  // Width of the owner window's scroll bar.  We cannot obscure the scroll bar.
  39.     BOOL m_bEnabled;  // Whether this is enabled.  If not, we hide the underlying window.
  40.  
  41.     void InternalPaint(HDC hDC);
  42.  
  43. public:
  44.     CFlexToolTip();
  45.     virtual ~CFlexToolTip();
  46.  
  47.     // Statics for show control
  48.     static UINT_PTR s_uiTimerID;
  49.     static DWORD s_dwLastTimeStamp;  // Last time stamp for mouse move
  50.     static TOOLTIPINIT s_TTParam;  // Parameters to initialize the tooltip
  51.     static void SetToolTipParent(HWND hWnd) { s_TTParam.hWndParent = hWnd; }
  52.     static void UpdateToolTipParam(TOOLTIPINITPARAM &TTParam)
  53.     {
  54.         s_TTParam.hWndParent = TTParam.hWndParent;
  55.         s_TTParam.iSBWidth = TTParam.iSBWidth;
  56.         s_TTParam.dwID = TTParam.dwID;
  57.         s_TTParam.hWndNotify = TTParam.hWndNotify;
  58.         if (TTParam.tszCaption)
  59.             lstrcpy((LPTSTR)s_TTParam.tszCaption, TTParam.tszCaption);
  60.         else
  61.             s_TTParam.tszCaption[0] = _T('\0');
  62.     }
  63.     static TOOLTIPINIT &GetTTParam() { return s_TTParam; }
  64.     static void CALLBACK TimerFunc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime);
  65.  
  66.     HWND Create(HWND hParent, const RECT &rect, BOOL bVisible, int iSBWidth = 0);
  67.  
  68.     HWND GetParent() { return ::GetParent(m_hWnd); }
  69.  
  70.     virtual LRESULT OnCreate(LPCREATESTRUCT lpCreateStruct);
  71.     virtual void OnDestroy();
  72.  
  73. private:
  74.     void SetNotifyWindow(HWND hWnd) { m_hNotifyWnd = hWnd; }
  75.     void SetColors(COLORREF text, COLORREF bk, COLORREF seltext, COLORREF selbk, COLORREF fill, COLORREF line);
  76.     void SetText(LPCTSTR tszText, POINT *textpos = NULL);
  77.     void SetID(DWORD dwID) { m_dwID = dwID; }
  78.     void SetPosition(POINT pt, BOOL bOffsetForMouseCursor = TRUE);
  79.     void SetSBWidth(int iSBWidth) { m_iSBWidth = iSBWidth; }
  80.  
  81. public:
  82.     DWORD GetID() { return m_dwID; }
  83.     void SetEnable(BOOL bEnable)
  84.     {
  85.         if (m_hWnd)
  86.         {
  87.             if (bEnable && !m_bEnabled)
  88.             {
  89.                 ShowWindow(m_hWnd, SW_SHOW);
  90.                 Invalidate();
  91.             }
  92.             else if (!bEnable && m_bEnabled)
  93.             {
  94.                 ShowWindow(m_hWnd, SW_HIDE);
  95.                 Invalidate();
  96.             }
  97.         }
  98.         m_bEnabled = bEnable;
  99.     }
  100.     BOOL IsEnabled() { return m_bEnabled; }
  101.  
  102.     virtual void OnClick(POINT point, WPARAM fwKeys, BOOL bLeft);
  103.     virtual void OnDoubleClick(POINT point, WPARAM fwKeys, BOOL bLeft);
  104.  
  105. protected:
  106.     virtual void OnPaint(HDC hDC);
  107.     virtual LRESULT WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  108. };
  109.  
  110. #endif
  111.