设为首页 加入收藏

TOP

1.3.3 小试牛刀--编程实现写邮件超级链接(2)
2013-10-07 15:53:01 来源: 作者: 【 】 浏览:89
Tags:1.3.3 小试牛刀 编程 实现 邮件 超级 链接

1.3.3  小试牛刀--编程(www.cppentry.com)实现写邮件超级链接(2)

(2) 在文件HyperLink.cpp中定义类成员函数的具体实现,接下来开始讲解此文件的具体实现过程。

① 定义函数OnMouseMove和OnSetCursor实现鼠标移动事件,具体代码如下:

  1. //鼠标移动事件  
  2. void CHyperLink::OnMouseMove(UINT nFlags, CPoint point)   
  3. {  
  4. CStatic::OnMouseMove(nFlags, point);  
  5. //判断鼠标是否在控件上方  
  6. if (m_bOverControl)          
  7. {  
  8. CRect rect;  
  9. GetClientRect(rect);  
  10.  
  11. if (!rect.PtInRect(point))  
  12. {  
  13. m_bOverControl = FALSE;  
  14. ReleaseCapture();  
  15. RedrawWindow();  
  16. return;  
  17. }  
  18. }  
  19. else                      // 鼠标移过控件  
  20. {  
  21. m_bOverControl = TRUE;  
  22. RedrawWindow();  
  23. SetCapture();  
  24. }  
  25. }  
  26. BOOL CHyperLink::OnSetCursor(  
  27. CWnd* /*pWnd*/,   
  28. UINT /*nHitTest*/,   
  29. UINT /*message*/)   
  30. {  
  31. if (m_hLinkCursor)  
  32. {  
  33. ::SetCursor(m_hLinkCursor);  
  34. return TRUE;  
  35. }  
  36. return FALSE;  
  37. }  

② 定义函数PreSubclassWindow()实现鼠标移动事件,具体代码如下:
  1. void CHyperLink::PreSubclassWindow()   
  2. {  
  3. // 获得鼠标单击事件  
  4. DWORD dwStyle = GetStyle();  
  5. ::SetWindowLong(GetSafeHwnd(), GWL_STYLE, dwStyle | SS_NOTIFY);  
  6.  
  7. // 如果URL为空,设定为窗体名称  
  8. if (m_strURL.IsEmpty())  
  9. GetWindowText(m_strURL);  
  10.  
  11. // 同时检查窗体标题是否为空,如果为空则设定为URL  
  12. CString strWndText;  
  13. GetWindowText(strWndText);  
  14. if (strWndText.IsEmpty()) {  
  15. ASSERT(!m_strURL.IsEmpty());      
  16. SetWindowText(m_strURL);  
  17. }  
  18.  
  19. // 创建字体  
  20. LOGFONT lf;  
  21. GetFont()->GetLogFont(&lf);  
  22. lf.lfUnderline = m_bUnderline;  
  23. m_Font.CreateFontIndirect(&lf);  
  24. SetFont(&m_Font);  
  25.  
  26. PositionWindow();               // 调整窗体大小  
  27. SetDefaultCursor();             // 设定默认鼠标形状  
  28.  
  29. //创建提示信息  
  30. CRect rect;   
  31. GetClientRect(rect);  
  32. m_ToolTip.Create(this);  
  33. m_ToolTip.AddTool(this, m_strURL, rect, TOOLTIP_ID);  
  34.  
  35. CStatic::PreSubclassWindow();  
  36. }  

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇1.3.3 小试牛刀--编程实现写邮件.. 下一篇1.3.3 小试牛刀--编程实现写邮件..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·C++中智能指针的性能 (2025-12-25 03:49:29)
·如何用智能指针实现c (2025-12-25 03:49:27)
·如何在 C 语言中管理 (2025-12-25 03:20:14)
·C语言和内存管理有什 (2025-12-25 03:20:11)
·为什么C语言从不被淘 (2025-12-25 03:20:08)