Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
3.2 KiB

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