<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/ DTD/wml_1.1.xml">

<wml>
<head>
<meta http-equiv="cache-control" content="max-age=180,private" />
</head>
<card title="VC6.0實現超鏈接（附案例）">
<p>
作者:<a href="index.php?action=showuser&amp;userid=1&amp;hash=">way</a><br />时间:2008-12-21 15:50<br />分类:<a href="index.php?action=list&amp;cid=22&amp;hash=">Development</a><br />标签:<a href="index.php?action=tags&amp;item=wayce&amp;hash=">wayce</a>, <a href="index.php?action=tags&amp;item=vc%2B%2B&amp;hash=">vc++</a>, <a href="index.php?action=tags&amp;item=vc6.0&amp;hash=">vc6.0</a>, <a href="index.php?action=tags&amp;item=%E8%B6%85%E9%93%BE%E6%8E%A5&amp;hash=">超链接</a>, <a href="index.php?action=tags&amp;item=%E6%A1%88%E4%BE%8B&amp;hash=">案例</a><br />附件:<a href="index.php?action=downfile&amp;id=209&amp;hash=">hyperlink.jpg</a>, <a href="index.php?action=downfile&amp;id=210&amp;hash=">linktest.rar</a><br />内容:
這幾天做C++畢業設計需要用到超鏈接,


於是乎在網上刨了刨, 但發現那些教程忒多大理論, 代碼也不完善而且沒提供案例,


研究總結了一下, 我決定發這篇帖, 把VC6.0實現超鏈接盡可能的簡單說一下, 並附上案例。


1, 創建MFC(exe), 窗體中放入一對label, 一對button, 導入一個cur手型鼠標指針到工程中.


2, label1平行button1, label2平行button2, 所有控件ID值默認即可.


3, label1&amp;label2標題分別:&quot;Weblog&quot;,&quot;E-mail&quot;,


button1&amp;button2標題分別:&quot;http://www.wayce.net&quot;,&quot;mailto:mwcobain@gmail.com&quot;.


4, button樣式選擇浮動或客戶邊緣都行.


5, 分別創建兩個button的clicked事件,


button1事件代碼:


C++代码


    void CLinktestDlg::OnButton1()    

    {   

        // TODO: Add your control notification handler code here   

        ShellExecute(m_hWnd,NULL, &quot;http://www.wayce.net&quot;, NULL,NULL,SW_SHOWMAXIMIZED);   

    }  





 


button2事件代碼:


C++代码


    void CLinktestDlg::OnButton2()    

    {   

        // TODO: Add your control notification handler code here   

        ShellExecute(m_hWnd,NULL, &quot;mailto:mwcobain@gmail.com&quot;, NULL,NULL,SW_SHOWMAXIMIZED);   

    }  





 


6, 使用建立類嚮導為dialog增加WM_SETCURSOR消息處理函數, 函數代碼如下:


C++代码


    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-&gt;GetWindowRect (rcButton1);   

        pStatic2-&gt;GetWindowRect (rcButton2);   

        GetCursorPos(&amp;ptCursor);   

        if (rcButton1.PtInRect (ptCursor)||rcButton2.PtInRect (ptCursor))   

        {   

               

        CWinApp *pApp=AfxGetApp();   

        HICON hIconBang=pApp-&gt;LoadCursor (IDC_CURSOR1);   

        SetCursor(hIconBang);   

        return TRUE;   

        }   

        else  

        return CDialog::OnSetCursor   

        (pWnd, nHitTest, message);       

    }  





7, RUN..! 大功告成~


截圖：[attach=209]


案例：





下載(Download)
</p><p>
<a href="index.php?action=comments&amp;articleid=111&amp;hash=">查看评论</a><br />
<a href="index.php?action=login&amp;hash=">立即登陆发表评论</a><br />
</p>
<p><a href="index.php?action=list&amp;hash=">返回日志列表</a><br /><a href="index.php?action=index&amp;hash=">返回主页</a></p>
</card>
</wml>
