您的位置:首页 > 其它

使用静态文本控件制作超链接

2011-02-28 11:54 302 查看
1、创建一个基于对话框的工程,拖放一个静态文本控件,更改相关属性名称,并添加一个手型的光标资源;

2、建立一个新类,命名为CLinkStatic,以CStatic为基类。

3、在主对话框中,为静态文本控件关联一个CLinkStatic的成员变量;

4、在CLinkStatic中响应OnMouseMove函数:

void CLinkStatic::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default

HCURSOR hCursor;
hCursor=AfxGetApp()->LoadCursor(IDC_HAND);
//将鼠标设为小手状
::SetCursor(hCursor);

CStatic::OnMouseMove(nFlags, point);

}


5、在CLinkStatic中响应OnLButtonDown函数:

void CLinkStatic::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
ShellExecute(0, NULL, "http://www.163.com", NULL,NULL, SW_NORMAL);

CStatic::OnLButtonDown(nFlags, point);
}


6、在CLinkStatic中响应OnPaint() 函数:

void CLinkStatic::OnPaint()
{
CPaintDC dc(this); // device context for painting

// TODO: Add your message handler code here

CPen pen(PS_SOLID,0,RGB(0,0,255));
dc.SelectObject(&pen);

CRect rect;
GetWindowRect(&rect);
ScreenToClient(&rect);

dc.SetBkMode(TRANSPARENT);
dc.SetTextColor(RGB(0,0,255));
dc.TextOut(rect.left,rect.top+5,www.163.com);
dc.SetTextAlign(TA_UPDATECP | TA_TOP);

dc.MoveTo(rect.left,rect.top+rect.Height()/2+12);
dc.LineTo(rect.left+205,rect.top+rect.Height()/2+12);
// Do not call CStatic::OnPaint() for painting messages
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: