StatLink.cpp
上传用户:shilei2004
上传日期:2020-07-18
资源大小:83k
文件大小:2k
源码类别:

RichEdit

开发平台:

Visual C++

  1. #include "StdAfx.h"
  2. #include "StatLink.h"
  3. #ifdef _DEBUG
  4. #define new DEBUG_NEW
  5. #undef THIS_FILE
  6. static char THIS_FILE[] = __FILE__;
  7. #endif
  8. COLORREF CStaticLink::g_colorUnvisited = RGB(0,0,255);
  9. COLORREF CStaticLink::g_colorVisited   = RGB(128,0,128);
  10. HCURSOR CStaticLink::g_hCursorLink = NULL;
  11. IMPLEMENT_DYNAMIC(CStaticLink, CStatic)
  12. BEGIN_MESSAGE_MAP(CStaticLink, CStatic)
  13. ON_WM_NCHITTEST()
  14. ON_WM_CTLCOLOR_REFLECT()
  15. ON_WM_LBUTTONDOWN()
  16. ON_WM_SETCURSOR()
  17. END_MESSAGE_MAP()
  18. CStaticLink::CStaticLink(LPCTSTR lpText, BOOL bDeleteOnDestroy)
  19. {
  20. m_link = lpText;
  21. m_color = g_colorUnvisited;
  22. m_bDeleteOnDestroy = bDeleteOnDestroy;
  23. }
  24. UINT CStaticLink::OnNcHitTest(CPoint point)
  25. {
  26. return HTCLIENT;
  27. }
  28. HBRUSH CStaticLink::CtlColor(CDC* pDC, UINT nCtlColor)
  29. {
  30. ASSERT(nCtlColor == CTLCOLOR_STATIC);
  31. DWORD dwStyle = GetStyle();
  32. HBRUSH hbr = NULL;
  33. if ((dwStyle & 0xFF) <= SS_RIGHT) {
  34. if (!(HFONT)m_font) {
  35. LOGFONT lf;
  36. GetFont()->GetObject(sizeof(lf), &lf);
  37. lf.lfUnderline = TRUE;
  38. m_font.CreateFontIndirect(&lf);
  39. }
  40. pDC->SelectObject(&m_font);
  41. pDC->SetTextColor(m_color);
  42. pDC->SetBkMode(TRANSPARENT);
  43. hbr = (HBRUSH)::GetStockObject(HOLLOW_BRUSH);
  44. }
  45. return hbr;
  46. }
  47. void CStaticLink::OnLButtonDown(UINT nFlags, CPoint point)
  48. {
  49. if (m_link.IsEmpty()) {
  50. GetWindowText(m_link);
  51. if (m_link.IsEmpty())
  52. return;
  53. }
  54. HINSTANCE h = m_link.Navigate();
  55. if ((UINT)h > 32) {
  56. m_color = g_colorVisited;
  57. Invalidate();
  58. } else {
  59. MessageBeep(0);
  60. TRACE(_T("*** WARNING: CStaticLink: unable to navigate link %sn"),
  61. (LPCTSTR)m_link);
  62. }
  63. }
  64. BOOL CStaticLink::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
  65. {
  66. if (g_hCursorLink == NULL) {
  67. static bTriedOnce = FALSE;
  68. if (!bTriedOnce) {
  69.          CString windir;
  70.          GetWindowsDirectory(windir.GetBuffer(MAX_PATH), MAX_PATH);
  71.          windir.ReleaseBuffer();
  72.          windir += _T("\winhlp32.exe");
  73.          HMODULE hModule = LoadLibrary(windir);
  74. if (hModule) {
  75. g_hCursorLink =
  76. CopyCursor(::LoadCursor(hModule, MAKEINTRESOURCE(106)));
  77. }
  78. FreeLibrary(hModule);
  79. bTriedOnce = TRUE;
  80. }
  81. }
  82. if (g_hCursorLink) {
  83. ::SetCursor(g_hCursorLink);
  84. return TRUE;
  85. }
  86. return FALSE;
  87. }
  88. void CStaticLink::PostNcDestroy()
  89. {
  90. if (m_bDeleteOnDestroy)
  91. delete this;
  92. }