URLLinkButton.h
上传用户:yxb0227
上传日期:2022-06-16
资源大小:19k
文件大小:4k
源码类别:

按钮控件

开发平台:

Visual C++

  1. #if !defined(AFX_URLLINKBUTTON_H__19A95AD8_340E_4CE0_9971_138A765EF60A__INCLUDED_)
  2. #define AFX_URLLINKBUTTON_H__19A95AD8_340E_4CE0_9971_138A765EF60A__INCLUDED_
  3. /////////////////////////////////////////////////////////////////////////////
  4. // File: URLLinkButton.h
  5. // By: Nguyen Duc Thanh, Vegasoft, JSC.
  6. // Copyright 2004, Nguyen Duc Thanh.
  7. // Email: thanhnd@vegasoft.ws
  8. // Website: http:\www.vegasoft.ws
  9. // Date: July 15, 2004
  10. /////////////////////////////////////////////////////////////////////////////
  11. //
  12. // The CURLLinkButton class extends the functionality of CButton 
  13. // by providing support for URL links
  14. // It displays the URL link and invokes the shell when clicked.
  15. // Tooltip supported, full color customization
  16. //
  17. /////////////////////////////////////////////////////////////////////////////
  18. //
  19. // This code is free for non-commercial use, providing this notice remains 
  20. // intact in the source files and all eventual changes are clearly marked 
  21. // with comments. Do not misrepresent the origin of this code.
  22. //
  23. // No warrantee of any kind, express or implied, is included with this
  24. // software; use at your own risk
  25. // 
  26. // If you find this code useful, credits would be nice!
  27. //
  28. /////////////////////////////////////////////////////////////////////////////
  29. #if _MSC_VER > 1000
  30. #pragma once
  31. #endif // _MSC_VER > 1000
  32. // URLLinkButton.h : header file
  33. //
  34. const UINT WM_LINK_CLICKED = ::RegisterWindowMessage (_T ("WM_LINK_CLICKED"));
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CURLLinkButton window
  37. class CURLLinkButton : public CButton
  38. {
  39. // Construction
  40. public:
  41. CURLLinkButton();
  42. // Attributes
  43. public:
  44. static HCURSOR m_hCursorHand;
  45. protected:
  46. COLORREF m_clrRegular;
  47. COLORREF m_clrHover;
  48. COLORREF m_clrVisited;
  49. COLORREF m_clrDisabled;
  50. BOOL m_bHover; // indicates if mouse is over the button
  51. BOOL m_bTracking;
  52. BOOL m_bVisited;
  53. CString m_sURL;
  54. CString m_sPrefix;
  55. CFont* m_pVisitedFont;
  56. private:
  57. CToolTipCtrl m_ToolTip;
  58. //This is used to fix fix infinite loop problem when we invoke the return key on the link to show a dialogbox
  59. BOOL  m_bKeyDown;
  60. // Operations
  61. public:
  62. // Overrides
  63. // ClassWizard generated virtual function overrides
  64. //{{AFX_VIRTUAL(CURLLinkButton)
  65. public:
  66. virtual BOOL PreTranslateMessage(MSG* pMsg);
  67. virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
  68. protected:
  69. virtual void PreSubclassWindow();
  70. //}}AFX_VIRTUAL
  71. // Implementation
  72. public:
  73. //Resize a URL link button to the size of the button's caption
  74. void SizeToContent();
  75. //Customize the colors of Hyperlink 
  76. void SetLinkColor(COLORREF clrRegular, COLORREF clrHover, COLORREF clrVisited);
  77. //Customize the colors of the Tooltip 
  78. void SetToolTipColor(COLORREF clrTextColor, COLORREF clrBkColor);
  79. //Customize the tooltip text
  80. void SetToolTipText(CString sTip=_T(""));
  81. // Set URL. By default, window text will be used
  82. void SetURL (LPCTSTR lpszURL);
  83. //Set URL prefix. For example "mailto:"
  84. void SetURLPrefix (LPCTSTR lpszPrefix);
  85. //Set window text and resize to content
  86. void SetDisplayText (LPCTSTR lpszDisplayText);
  87. void SetToolTipBkColor(COLORREF clrBkgrdColor);
  88. void SetToolTipTextColor(COLORREF clrTextColor);
  89. void SetVisitedColor(COLORREF clrVisited);
  90. void SetHoverColor(COLORREF clrHover);
  91. void SetRegularColor(COLORREF clrRegular);
  92. CString GetDefaultTipText();
  93. virtual ~CURLLinkButton();
  94. // Generated message map functions
  95. protected:
  96. //{{AFX_MSG(CURLLinkButton)
  97. afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  98. afx_msg LRESULT OnMouseLeave(WPARAM wparam, LPARAM lparam);
  99. afx_msg void OnMouseHover(WPARAM wparam, LPARAM lparam) ;
  100. afx_msg void OnClicked();
  101. afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
  102. afx_msg void OnKillFocus(CWnd* pNewWnd);
  103. //}}AFX_MSG
  104. DECLARE_MESSAGE_MAP()
  105. };
  106. /////////////////////////////////////////////////////////////////////////////
  107. //{{AFX_INSERT_LOCATION}}
  108. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  109. #endif // !defined(AFX_URLLINKBUTTON_H__19A95AD8_340E_4CE0_9971_138A765EF60A__INCLUDED_)