1.3.3 小试牛刀--编程(www.cppentry.com)实现写邮件超级链接(1)
实例功能 编程(www.cppentry.com)实现写邮件超级链接
源码路径 光盘\yuanma\1\Link
本实例的目的是,使用Visual C++(www.cppentry.com) 6.0开发一个实现写邮件超级链接的应用程序。
1. 设计MFC窗体
使用Visual C++(www.cppentry.com) 6.0创建一个MFC项目后,根据本实例的需要设计一个窗体,命名为IDD_ HLSAMPLE_DIALOG,如图1-16所示。
|
| 图1-16 创建的窗体 |
2. 具体编码
设计好窗体之后,接下来开始讲解具体的编码过程。
(1) 在文件HyperLink.h中定义继承于类CStatic的类CHyperLink,并设置与超链接相关的样式变量,例如鼠标形状、是否访问过等。具体代码如下:
- class CHyperLink : public CStatic
- {
- public:
- CHyperLink();
- virtual ~CHyperLink();
- // 属性
- public:
-
- public:
- //设定URL
- void SetURL(CString strURL);
- CString GetURL() const;
- //设定颜色
- void SetColours(COLORREF crLinkColour, COLORREF crVisitedColour,
- COLORREF crHoverColour=-1);
- //获得连接颜色
- COLORREF GetLinkColour() const;
- //获得被访问后的颜色
- COLORREF GetVisitedColour() const;
- //获得鼠标移动上以后的颜色
- COLORREF GetHoverColour() const;
-
- //设定是否被访问过
- void SetVisited(BOOL bVisited=TRUE);
- //获得是否被访问过
- BOOL GetVisited() const;
-
- //设定鼠标形状
- void SetLinkCursor(HCURSOR hCursor);
- //获得鼠标形状
- HCURSOR GetLinkCursor() const;
- //设定是否有下划线
- void SetUnderline(BOOL bUnderline=TRUE);
- //获得是否有下划线
- BOOL GetUnderline() const;
- //设定是否是自动改变大小
- void SetAutoSize(BOOL bAutoSize=TRUE);
- BOOL GetAutoSize() const;
-
- public:
- virtual BOOL PreTranslateMessage(MSG *pMsg);
- protected:
- virtual void PreSubclassWindow();
- //}}AFX_VIRTUAL
-
- protected:
- //连接到URL
- HINSTANCE GotoURL(LPCTSTR url, int showcmd);
- //打印错误
- void ReportError(int nError);
- //获得注册表信息
- LONG GetRegKey(HKEY key, LPCTSTR subkey, LPTSTR retdata);
- //调整位置
- void PositionWindow();
- //设定默认的鼠标形状
- void SetDefaultCursor();
-
- // 变量
- protected:
- COLORREF m_crLinkColour, m_crVisitedColour; // 超级链接颜色
- COLORREF m_crHoverColour; // 鼠标停留颜色
- BOOL m_bOverControl; // 是否鼠标移到控件上
- BOOL m_bVisited; // 是否被访问
- BOOL m_bUnderline; // 是否有下划线
- BOOL m_bAdjustToFit; // 是否自动调整控件大小
- CString m_strURL; // URL
- CFont m_Font; // 设定字体
- HCURSOR m_hLinkCursor; // 光标
- CToolTipCtrl m_ToolTip; // 提示文字
- protected:
- afx_msg HBRUSH CtlColor(CDC *pDC, UINT nCtlColor);
- afx_msg BOOL OnSetCursor(CWnd *pWnd, UINT nHitTest, UINT message);
- afx_msg void OnMouseMove(UINT nFlags, CPoint point);
- //}}AFX_MSG
- afx_msg void OnClicked();
- DECLARE_MESSAGE_MAP()
- };