用MFC实现超链接

1)创建MFC(exe),窗体中放入一对静态文本框(Static Text)、一对button,导入一个cur手型鼠标指针到工程中;

2)Text1平行于button1,Text2平行于button2,所有控件的ID值默认即可;

3)Text1 & Text2 的标题分别为:“Weblog”,"E-mail",

     button1 & button2的标题分别为:"http://www.wayce.net","mailto:mwcobain@gmail.com".

4)创建两个button的clicked事件。

button1事件代码:

void CLinktestDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	ShellExecute(m_hWnd,NULL, "http://www.wayce.net", NULL,NULL,SW_SHOWMAXIMIZED);   

}


button2事件代码:

void CLinktestDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
	ShellExecute(m_hWnd,NULL, "mailto:mwcobain@gmail.com", NULL,NULL,SW_SHOWMAXIMIZED);   

}

5)使用类向导为dialog增加WM_SETCURSOR消息处理函数,函数代码如下:

BOOL CLinktestDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
{
	// TODO: Add your message handler code here and/or call default
	
	//return CDialog::OnSetCursor(pWnd, nHitTest, message);
	CRect rcButton1,rcButton2;   
	CPoint ptCursor;   
	CWnd *pStatic1=GetDlgItem(IDC_BUTTON1);   
    CWnd *pStatic2=GetDlgItem(IDC_BUTTON2);   
    pStatic1->GetWindowRect (rcButton1);   
    pStatic2->GetWindowRect (rcButton2);   
    GetCursorPos(&ptCursor);   
    if (rcButton1.PtInRect (ptCursor)||rcButton2.PtInRect (ptCursor))   
    {   
		
		CWinApp *pApp=AfxGetApp();   
		HICON hIconBang=pApp->LoadCursor (IDC_CURSOR1);   
		SetCursor(hIconBang);   
		return TRUE;   
    }   
    else  
		return CDialog::OnSetCursor   
    (pWnd, nHitTest, message);    

}


效果如下:

 

    图(1)用MFC实现超链接

代码下载:http://download.csdn.net/detail/sanqima/7660953

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sanqima

一键三连,多多益善

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值