1、添加成员变量m_RectLink,用来保存文本框的坐标,添加两个静态文本控件,将默认ID改掉:
// Implementation
protected:
HICON m_hIcon;
//用于保存静态文本框的屏幕坐标
RECT m_pRectLink;
......
}
2、获取static控件的区域,在初始化函数里添加代码如下:
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
//将静态文本的屏幕坐标存放在m_pRectLink中
GetDlgItem(IDC_LINK) -> GetWindowRect(&m_pRectLink);
//将屏幕坐标转换为客户坐标
ScreenToClient(&m_pRectLink);
return TRUE; // return TRUE unless you set the focus to a control
}
3、添加Windows消息WM_MOUSEMOVE,代码如下:
if (point.x > m_pRectLink.left && point.x < m_pRectLink.right && point.y > m_pRectLink.top && point.y < m_pRectLink.bottom )
//此处添加判断坐标算法
{
HCURSOR hCursor;
hCursor = AfxGetApp() -> LoadCursor(IDC_HAND);
//将鼠标设为小手状
SetCursor(hCursor);
}
CDialog::OnMouseMove(nFlags, point);
}
4、添加Windows消息WM_LBUTTONDOWN,代码如下:
//也可以添加电子邮件的链接
ShellExecute(0, NULL, "mailto:koma0769@vip.qq.com", NULL,NULL, SW_NORMAL);
}
}
CDialog::OnLButtonDown(nFlags, point);
}
5、程序运行效果如下: