MFC 文本超链接

第一步,在Dlg类中定义一个protect成员变量HCURSOR  m_hCursor,

在构造函数里(或者在OnInitDialog()里)调用语句

m_hCursor=AfxGetApp()->LoadCursor(IDI_CURLINK);加载鼠标;(IDI_CURLINK为鼠标的icon)

第二步,在Dlg类中定义一个protect成员变量RECT  m_StaticRect,表示静态文本的坐标,在成员函数OnInitDialog()里调用语句

GetDlgItem(IDC_STATIC)->GetWindowRect(&m_StaticRect);

ScreenToClient(&m_StaticRect);


第三步,加载鼠标移动消息,在OnMouseMove()里调用语句

if( point.x > m_StaticRect.left && point.x < m_StaticRect.right &&
    point.y > m_StaticRect.top  && point.y < m_StaticRect.bottom ) 
    { 
       SetCursor(m_hCursor); 
    } 


第四步,加载鼠标单击消息,在OnLButtonDown()里添加语句

if( point.x > m_StaticRect.left && point.x < m_StaticRect.right &&point.y > m_StaticRect.top  && point.y < m_StaticRect.bottom )
{
SetCursor(m_hCursor);
ShellExecute(NULL,"open",TEXT(http://www.baidu.com),NULL,NULL, SW_SHOWNORMAL);//调用ShellExecute
} 


 

若是邮箱,则改为ShellExecute(NULL, "open",_T(“wjn1206@yeah.net”), NULL, NULL, SW_SHOWNORMAL),这个你们懂的;

设置静态文本的字体与颜色

第一步,字体的设置:在Dlg类中定义一个protect成员变量CFont m_Font表示字体,在类的成员函数OnInitDialog()里调用m_Font.CreateFont(……),设置字体样式颜色等具体参考MSDN。接着编写两行代码:

OnInitDialog()

{

..............

CStatic *m_static=(CStatic *)GetDlgItem(IDC_STATIC);

m_static->SetFont(&m_Font,false);

return TRUE;

}

第二步,颜色的设置:在Dlg中加载WM_CTLCOLOR消息,在此消息的响应函数OnCtlColor(……)里添加如下代码:

HBRUSH CScreenShotsDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
    if (pWnd->GetDlgCtrlID() == IDC_STATIC)
     {
       pDC->SetTextColor(RGB(255, 0, 0));
     }
    return hbr;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值