XHyperLink.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. // XHyperLink.h Version 1.0
  2. //
  3. // XHyperLink static control. Will open the default browser with the
  4. // given URL when the user clicks on the link.
  5. //
  6. // Copyright Chris Maunder, 1997-1999 (cmaunder@mail.com)
  7. // Feel free to use and distribute. May not be sold for profit.
  8. //
  9. // 2/29/00 -- P. Shaffer standard font mod.
  10. //
  11. ///////////////////////////////////////////////////////////////////////////////
  12. //
  13. // Modified by: Hans Dietrich
  14. // hdietrich2@hotmail.com
  15. //
  16. ///////////////////////////////////////////////////////////////////////////////
  17. #ifndef XHYPERLINK_H
  18. #define XHYPERLINK_H
  19. extern UINT WM_XHYPERLINK_CLICKED;
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CXHyperLink window
  22. class CXHyperLink : public CStatic
  23. {
  24. // Construction/destruction
  25. public:
  26. CXHyperLink();
  27. virtual ~CXHyperLink();
  28. public:
  29. enum UnderLineOptions { ulHover = -1, ulNone = 0, ulAlways = 1};
  30. // Attributes
  31. public:
  32. void SetURL(CString strURL);
  33. CString GetURL() const
  34. {
  35. return m_strURL;
  36. }
  37. void EnableURL(BOOL bFlag) { m_bIsURLEnabled = bFlag; }
  38. BOOL IsURLEnabled() const { return m_bIsURLEnabled; }
  39. void SetColours(COLORREF crLinkColour,
  40. COLORREF crVisitedColour,
  41. COLORREF crHoverColour = -1);
  42. COLORREF GetLinkColour() const
  43. {
  44. return m_crLinkColour;
  45. }
  46. COLORREF GetVisitedColour() const
  47. {
  48. return m_crVisitedColour;
  49. }
  50. COLORREF GetHoverColour() const
  51. {
  52. return m_crHoverColour;
  53. }
  54. void SetBackgroundColour(COLORREF crBackground);
  55. COLORREF GetBackgroundColour() const
  56. {
  57. return m_crBackground;
  58. }
  59. void SetVisited(BOOL bVisited = TRUE);
  60. BOOL GetVisited() const
  61. {
  62. return m_bVisited;
  63. }
  64. void SetLinkCursor(HCURSOR hCursor);
  65. HCURSOR CXHyperLink::GetLinkCursor() const
  66. {
  67. return m_hLinkCursor;
  68. }
  69. void SetUnderline(int nUnderline = ulHover);
  70. int GetUnderline() const
  71. {
  72. return m_nUnderline;
  73. }
  74. void SetAutoSize(BOOL bAutoSize = TRUE);
  75. BOOL GetAutoSize() const
  76. {
  77. return m_bAdjustToFit;
  78. }
  79. void SetNotifyParent(BOOL bFlag) { m_bNotifyParent = bFlag; }
  80. BOOL GetNotifyParent() const { return m_bNotifyParent; }
  81. void EnableTooltip(BOOL bFlag)
  82. {
  83. m_bToolTip = bFlag;
  84. m_ToolTip.Activate(m_bToolTip);
  85. }
  86. BOOL IsTooltipEmabled() const
  87. {
  88. return m_bToolTip;
  89. }
  90. void SetAlwaysOpenNew(BOOL bFlag)
  91. {
  92. m_bAlwaysOpenNew = bFlag;
  93. }
  94. BOOL GetAlwaysOpenNew() const
  95. {
  96. return m_bAlwaysOpenNew;
  97. }
  98. void SetWindowText(LPCTSTR lpszString);
  99. // Operations
  100. public:
  101. static HINSTANCE GotoURL(LPCTSTR url, int showcmd, BOOL bAlwaysOpenNew = FALSE);
  102. // Overrides
  103. // ClassWizard generated virtual function overrides
  104. //{{AFX_VIRTUAL(CXHyperLink)
  105. public:
  106. virtual BOOL PreTranslateMessage(MSG* pMsg);
  107. virtual BOOL DestroyWindow();
  108. protected:
  109. virtual void PreSubclassWindow();
  110. //}}AFX_VIRTUAL
  111. // Implementation
  112. protected:
  113. static LONG GetRegKey(HKEY key, LPCTSTR subkey, LPTSTR retdata);
  114. void NotifyParent();
  115. void PositionWindow();
  116. void ReportError(int nError);
  117. void SetDefaultCursor();
  118. // Protected attributes
  119. protected:
  120. COLORREF m_crLinkColour; // Hyperlink colours
  121. COLORREF m_crVisitedColour;
  122. COLORREF m_crHoverColour; // Hover colour
  123. COLORREF m_crBackground; // background color
  124. CBrush m_Brush; // background brush
  125. BOOL m_bOverControl; // cursor over control?
  126. BOOL m_bVisited; // Has it been visited?
  127. int m_nUnderline; // underline hyperlink?
  128. BOOL m_bAdjustToFit; // Adjust window size to fit text?
  129. CString m_strURL; // hyperlink URL
  130. CFont m_UnderlineFont; // Font for underline display
  131. CFont m_StdFont; // Standard font
  132. HCURSOR m_hLinkCursor; // Cursor for hyperlink
  133. CToolTipCtrl m_ToolTip; // The tooltip
  134. UINT m_nTimerID;
  135. BOOL m_bIsURLEnabled; // TRUE = navigate to url
  136. BOOL m_bNotifyParent; // TRUE = notify parent
  137. BOOL m_bToolTip; // TRUE = display tooltip
  138. BOOL m_bAlwaysOpenNew; // TRUE = always open new browser window
  139. // Generated message map functions
  140. protected:
  141. //{{AFX_MSG(CXHyperLink)
  142. afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
  143. afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
  144. afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  145. afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  146. //}}AFX_MSG
  147. afx_msg void OnTimer(UINT nIDEvent);
  148. afx_msg void OnClicked();
  149. DECLARE_MESSAGE_MAP()
  150. };
  151. /////////////////////////////////////////////////////////////////////////////
  152. //{{AFX_INSERT_LOCATION}}
  153. // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
  154. #endif //XHYPERLINK_H