這幾天做C++畢業設計需要用到超鏈接,
於是乎在網上刨了刨, 但發現那些教程忒多大理論, 代碼也不完善而且沒提供案例,
研究總結了一下, 我決定發這篇帖, 把VC6.0實現超鏈接盡可能的簡單說一下, 並附上案例。
1, 創建MFC(exe), 窗體中放入一對label, 一對button, 導入一個cur手型鼠標指針到工程中.
2, label1平行button1, label2平行button2, 所有控件ID值默認即可.
3, label1&label2標題分別:"Weblog","E-mail",
button1&button2標題分別:"http://www.wayce.net","mailto:mwcobain@gmail.com".
4, button樣式選擇浮動或客戶邊緣都行.
5, 分別創建兩個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);
- }
6, 使用建立類嚮導為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);
- }
7, RUN..! 大功告成~
案例: