




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、用VC實(shí)現(xiàn)超鏈接技術(shù) 在網(wǎng)絡(luò)日益普及的今天,我們使用形形色色的軟件過(guò)程中,總能發(fā)現(xiàn)在這些軟件中都增加了一種實(shí)用功能超鏈接。使用超鏈接我們可以方便的在應(yīng)用程序中提供網(wǎng)址與電子郵件地址,方便用戶快捷升級(jí),登錄網(wǎng)址瀏覽最新信息,發(fā)送郵件提供合理建議等等。這里所說(shuō)的超鏈接是指用給定的地址從應(yīng)用程序中啟動(dòng)瀏覽器或電子郵件軟件的功能,本文將在對(duì)話框中插入超鏈接,闡述超鏈接的實(shí)現(xiàn)方法。實(shí)現(xiàn)超鏈接,有些程序員們要說(shuō)這簡(jiǎn)單,只要使用API函數(shù)ShellExecute調(diào)用瀏覽器軟件或相應(yīng)的電子郵件軟件就可以實(shí)現(xiàn)。但這并不是一個(gè)好的實(shí)現(xiàn)方法,首先,每一個(gè)操作系統(tǒng)的瀏覽器不盡相同,簡(jiǎn)單的調(diào)用方法不能很好的解決這一問(wèn)題
2、;其次,不能實(shí)現(xiàn)良好的界面。一、實(shí)現(xiàn)良好的界面一個(gè)界面良好的超鏈接,在對(duì)話框中實(shí)現(xiàn)時(shí)可以實(shí)現(xiàn)顏色的變換,即正常時(shí)為一種顏色,光標(biāo)移到超鏈接控件上時(shí)顯示另一種顏色,訪問(wèn)過(guò)的超鏈接又顯示一種顏色。響應(yīng)WM_CTLCOLOR_REFLECT消息,修改響應(yīng)函數(shù)如下可以實(shí)現(xiàn)顏色的變換。HBRUSH CHLink:CtlColor(CDC* pDC, UINT nCtlColor)/ TODO: Change any attributes of the DC hereif(m_bPointing)/m_bPointing為BOOL變量,光標(biāo)指向超鏈接控件為TRUE。pDC->SetTextColor
3、(m_cPointingColor);/m_cPointingColor為COLORREF變量,光標(biāo)指向超鏈接控件時(shí)的控件的顏色。elseif(m_bVisited)/m_bVisited為BOOL變量,超鏈接被訪問(wèn)過(guò)為TRUE。pDC->SetTextColor(m_cVisitedColor);/m_cVisitedColor為COLORREF變量,超鏈接被訪問(wèn)后的控件的顏色。 elseif(m_bNormal)/m_bNormal為BOOL變量,超鏈接正常狀態(tài)為TRUE。pDC->SetTextColor(m_cNormalColor);/m_cNormalColor為COL
4、ORREF變量,超鏈接正常狀態(tài)的顏色。 / TODO: Return a different brush if the default is not desiredpDC->SetBkMode(TRANSPARENT);return (HBRUSH)GetStockObject(NULL_BRUSH);/ HLink.h : header file/ CHLink windowclass CHLink : public CStatic/ Constructionpublic:void SetUnderline(BOOL Underline);void SetTipTitle(CStrin
5、g tipStr);void SetWindowTitle(CString tStr);LONG GetRegKey(HKEY key, LPCTSTR subkey, LPTSTR retdata);HINSTANCE GotoURL(LPCTSTR url, int showcmd);void SetLinkCur();void SetPointingColor(COLORREF PointingColor);void SetVisitedColor(COLORREF VisitedColor);void SetNormalColor(COLORREF NormalColor);void
6、SetURL(CString strURL);CHLink();private:void AutoSizeWindow();CString m_strURL;COLORREF m_cPointingColor;COLORREF m_cVisitedColor;COLORREF m_cNormalColor;BOOL m_bVisited;BOOL m_bPointing;BOOL m_bNormal;BOOL m_bUnderLine;BOOL m_bAdjustFit;BOOL m_Title;BOOL m_tip;CFont m_Font;CToolTipCtrl m_ToolTip;HC
7、URSOR m_cursor;/ Attributespublic:/ Operationspublic:/ Overrides/ ClassWizard generated virtual function overrides/AFX_VIRTUAL(CHLink)public:virtual BOOL PreTranslateMessage(MSG* pMsg);protected:virtual void PreSubclassWindow();/AFX_VIRTUAL/ Implementationpublic:virtual CHLink();/ Generated message
8、map functionsprotected:/AFX_MSG(CHLink)afx_msg void OnMouseMove(UINT nFlags, CPoint point);afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);afx_msg void OnLButtonDown(UINT nFlags, CPoint point);afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);/AFX_MSGDECLARE_MESSAGE_MAP();/ HLink.c
9、pp : implementation file/#include "stdafx.h"#include "llll.h"#include "HLink.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endif/ CHLinkCHLink:CHLink()m_cNormalColor=RGB(0,0,255);m_cPointingColor=RGB(0,125,155);m_cVisitedColor=RGB(8
10、5,26,139);m_bNormal=TRUE;m_bVisited=FALSE;m_bPointing=FALSE;m_Title=FALSE;m_tip=FALSE;m_bUnderLine=TRUE;m_bAdjustFit=TRUE;CHLink:CHLink()m_Font.DeleteObject();BEGIN_MESSAGE_MAP(CHLink, CStatic)/AFX_MSG_MAP(CHLink)ON_WM_MOUSEMOVE()ON_WM_CTLCOLOR_REFLECT()ON_WM_LBUTTONDOWN()ON_WM_SETCURSOR()/AFX_MSG_M
11、APEND_MESSAGE_MAP()/ CHLink message handlersvoid CHLink:SetURL(CString strURL)m_strURL=strURL;if(!m_Title)SetWindowText(m_strURL);AutoSizeWindow();if(!m_tip)m_ToolTip.UpdateTipText(strURL, this, 1);Invalidate();void CHLink:PreSubclassWindow()/ TODO: Add your specialized code here and/or call the bas
12、e classDWORD dwStyle = GetStyle();:SetWindowLong(GetSafeHwnd(), GWL_STYLE, dwStyle | SS_NOTIFY);m_cursor=AfxGetApp()->LoadStandardCursor(IDC_ARROW);LOGFONT lf;GetFont()->GetLogFont(&lf);lf.lfUnderline = m_bUnderLine;m_Font.CreateFontIndirect(&lf);SetFont(&m_Font);CRect rect;GetClie
13、ntRect(rect);m_ToolTip.Create(this);m_ToolTip.AddTool(this, m_strURL, rect, 1);SetLinkCur();CStatic:PreSubclassWindow();HBRUSH CHLink:CtlColor(CDC* pDC, UINT nCtlColor)/ TODO: Change any attributes of the DC hereif(m_bPointing)pDC->SetTextColor(m_cPointingColor);elseif(m_bVisited)pDC->SetTextC
14、olor(m_cVisitedColor);elseif(m_bNormal)pDC->SetTextColor(m_cNormalColor);/ TODO: Return a different brush if the default is not desiredpDC->SetBkMode(TRANSPARENT);return (HBRUSH)GetStockObject(NULL_BRUSH);void CHLink:SetPointingColor(COLORREF PointingColor)m_cPointingColor=PointingColor;void C
15、HLink:SetVisitedColor(COLORREF VisitedColor)m_cVisitedColor=VisitedColor;void CHLink:SetNormalColor(COLORREF NormalColor)m_cNormalColor=NormalColor;void CHLink:OnMouseMove(UINT nFlags, CPoint point)/ TODO: Add your message handler code here and/or call defaultCStatic:OnMouseMove(nFlags, point);CRect
16、 rect;GetClientRect(rect);if (!rect.PtInRect(point)m_bPointing = FALSE;ReleaseCapture();else / Cursor has just moved over controlm_bPointing = TRUE;SetLinkCur();SetCapture();Invalidate();void CHLink:AutoSizeWindow()if(m_bAdjustFit)CRect rect;GetWindowRect(rect);CWnd *pParent=GetParent();if(pParent)p
17、Parent->ScreenToClient(rect);CString strText;GetWindowText(strText);CDC* pDC=GetDC();CFont* oldFont=pDC->SelectObject(&m_Font);CSize strExtent=pDC->GetTextExtent(strText);pDC->SelectObject(oldFont);ReleaseDC(pDC);DWORD dwStyle = GetStyle();if (dwStyle & SS_CENTERIMAGE)rect.Deflat
18、eRect(0, (rect.Height() - strExtent.cy)/2);elserect.bottom = rect.top + strExtent.cy;if (dwStyle & SS_CENTER)rect.DeflateRect(rect.Width() - strExtent.cx)/2, 0);elseif (dwStyle & SS_RIGHT)rect.left = rect.right - strExtent.cx;elserect.right = rect.left + strExtent.cx;SetWindowPos(NULL, rect.
19、left, rect.top, rect.Width(), rect.Height(), SWP_NOZORDER);void CHLink:OnLButtonDown(UINT nFlags, CPoint point)/ TODO: Add your message handler code here and/or call defaultint result = (int)GotoURL(m_strURL, SW_SHOW);m_bVisited = (result > HINSTANCE_ERROR);Invalidate();CStatic:OnLButtonDown(nFla
20、gs, point);BOOL CHLink:PreTranslateMessage(MSG* pMsg)/ TODO: Add your specialized code here and/or call the base classm_ToolTip.RelayEvent(pMsg);return CStatic:PreTranslateMessage(pMsg);void CHLink:SetLinkCur()m_cursor=AfxGetApp()->LoadCursor(IDC_CURSOR);BOOL CHLink:OnSetCursor(CWnd* pWnd, UINT n
21、HitTest, UINT message)/ TODO: Add your message handler code here and/or call default:SetCursor(m_cursor);return TRUE;/return CStatic:OnSetCursor(pWnd, nHitTest, message);HINSTANCE CHLink:GotoURL(LPCTSTR url, int showcmd)TCHAR keyMAX_PATH + MAX_PATH;HINSTANCE result = ShellExecute(NULL, _T("open
22、"), url, NULL,NULL, showcmd);if (UINT)result <= HINSTANCE_ERROR) if (GetRegKey(HKEY_CLASSES_ROOT, _T(".htm"), key) = ERROR_SUCCESS) lstrcat(key, _T("shellopencommand");if (GetRegKey(HKEY_CLASSES_ROOT,key,key) = ERROR_SUCCESS)TCHAR *pos;pos = _tcsstr(key, _T(""%1"");if (pos = NULL)pos = strstr(key, _T("%1");if (pos = NULL)pos = key+lstrlen(key)-1;else*pos = '0'else*pos = '0' / Remove the parameterlstrcat(pos, _T(" ");lstrcat(pos, url);result = (HINSTANCE) WinExec(key,showcmd);return result;
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 冰柜采購(gòu)合同范本
- 促進(jìn)健康教育活動(dòng)的實(shí)施計(jì)劃
- 基于風(fēng)險(xiǎn)評(píng)估的保安管理計(jì)劃
- 社區(qū)鄰里親情關(guān)懷計(jì)劃
- 《貴州豐聯(lián)礦業(yè)有限公司畢節(jié)市陰底鄉(xiāng)瑞興煤礦(變更)礦產(chǎn)資源綠色開發(fā)利用方案(三合一)》專家組評(píng)審意見(jiàn)
- 2025年云南貨運(yùn)上崗資格證模擬考試
- 亞洲的人文環(huán)境課件-+2024-2025學(xué)年人教版七年級(jí)地理下冊(cè)
- 2025年莆田道路運(yùn)輸貨運(yùn)考試題庫(kù)
- 2025年鐵嶺貨運(yùn)運(yùn)輸駕駛員從業(yè)資格證考試試題
- 第12課+水陸交通的變遷高二歷史統(tǒng)編版(2019)選擇性必修2
- 醫(yī)療器械委托生產(chǎn)控制程序
- 法院電子卷宗制度
- 光伏發(fā)電施工勞務(wù)分包合同模板
- CRRT治療原理、模式選擇
- 成都市2024屆高中畢業(yè)班第二次診斷性監(jiān)測(cè)-2024年全國(guó)各地高考語(yǔ)文模擬卷作文導(dǎo)寫講練
- 醫(yī)保統(tǒng)計(jì)信息管理制度
- 達(dá)格列凈治療心衰機(jī)制
- 2024年保育員(初級(jí))證考試題庫(kù)及答案
- 40篇英語(yǔ)短文搞定3500個(gè)單詞 正文
- 2024年度《冠心病》全套課件(完整版)
- 正面吊安全操作規(guī)程培訓(xùn)
評(píng)論
0/150
提交評(píng)論