这么简单,我看你应该还是有点水平吗,你的名字都带接口IMarksman,
还问这么简单的问题。

解决方案 »

  1.   

    //HyperLink.h
    #include "stdafx.h"
    #include "HyperLink.h"
    #include <afxconv.h>           // For LPTSTR -> LPSTR macros
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif#define TOOLTIP_ID 1/////////////////////////////////////////////////////////////////////////////
    // CHyperLinkCHyperLink::CHyperLink()
    {
        m_hLinkCursor       = NULL;                 // No cursor as yet
        m_bOverControl      = FALSE;                // Cursor not yet over control  
        m_strURL.Empty();
    }CHyperLink::~CHyperLink()
    {
        m_Font.DeleteObject();
    }BEGIN_MESSAGE_MAP(CHyperLink, CStatic)
        //{{AFX_MSG_MAP(CHyperLink)
        ON_CONTROL_REFLECT(STN_CLICKED, OnClicked)
        ON_WM_CTLCOLOR_REFLECT()
        ON_WM_SETCURSOR()    ON_WM_MOUSEMOVE()
        //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CHyperLink message handlersvoid CHyperLink::OnClicked()
    {
        m_bOverControl = FALSE;
    GotoURL(m_strURL, SW_SHOW);
    }HBRUSH CHyperLink::CtlColor(CDC* pDC, UINT nCtlColor) 
    {
        ASSERT(nCtlColor == CTLCOLOR_STATIC);
        UNUSED(nCtlColor);    if (m_bOverControl)
            pDC->SetTextColor(0xFF0080);
        else
            pDC->SetTextColor(0xFF0000);    // transparent text.
        pDC->SetBkMode(TRANSPARENT);
        return (HBRUSH)GetStockObject(NULL_BRUSH);
    }
    BOOL CHyperLink::OnSetCursor(CWnd* /*pWnd*/, UINT /*nHitTest*/, UINT /*message*/) 
    {
        if (m_hLinkCursor)
        {
            ::SetCursor(m_hLinkCursor);
            return TRUE;
        }
        return FALSE;
    }void CHyperLink::OnMouseMove(UINT nFlags, CPoint point) 
    {
        CStatic::OnMouseMove(nFlags, point);    if (m_bOverControl)        // Cursor is currently over control
        {
            CRect rect;
            GetClientRect(rect);        if (!rect.PtInRect(point))
            {
                m_bOverControl = FALSE;
                ReleaseCapture();
                RedrawWindow();
                return;
            }
        }
        else                      // Cursor has just moved over control
        {
            m_bOverControl = TRUE;
            RedrawWindow();
            SetCapture();
        }
    }void CHyperLink::PreSubclassWindow() 
    {
        // We want to get mouse clicks via STN_CLICKED
        DWORD dwStyle = GetStyle();
        ::SetWindowLong(GetSafeHwnd(), GWL_STYLE, dwStyle | SS_NOTIFY);
        
        // Set the URL as the window text
        if (m_strURL.IsEmpty())
            GetWindowText(m_strURL);    // Check that the window text isn't empty. If it is, set it as the URL.
        CString strWndText;
        GetWindowText(strWndText);
        if (strWndText.IsEmpty()) {
            ASSERT(!m_strURL.IsEmpty());    // Window and URL both NULL. DUH!
            SetWindowText(m_strURL);
        }    // Create the font
        LOGFONT lf;
        GetFont()->GetLogFont(&lf);
        lf.lfUnderline = (BYTE) TRUE;
        m_Font.CreateFontIndirect(&lf);
        SetFont(&m_Font);
        // Create the tooltip
        CRect rect; 
        GetClientRect(rect);    CStatic::PreSubclassWindow();
    }LONG CHyperLink::GetRegKey(HKEY key, LPCTSTR subkey, LPTSTR retdata)
    {
        HKEY hkey;
        LONG retval = RegOpenKeyEx(key, subkey, 0, KEY_QUERY_VALUE, &hkey);    if (retval == ERROR_SUCCESS) {
            long datasize = MAX_PATH;
            TCHAR data[MAX_PATH];
            RegQueryValue(hkey, NULL, data, &datasize);
            lstrcpy(retdata,data);
            RegCloseKey(hkey);
        }    return retval;
    }HINSTANCE CHyperLink::GotoURL(LPCTSTR url, int showcmd)
    {
        TCHAR key[MAX_PATH + MAX_PATH];    // First try ShellExecute()
        HINSTANCE result = ShellExecute(NULL, _T("open"), url, NULL,NULL, showcmd);    // If it failed, get the .htm regkey and lookup the program
        if ((UINT)result <= HINSTANCE_ERROR) {        if (GetRegKey(HKEY_CLASSES_ROOT, _T(".htm"), key) == ERROR_SUCCESS) {
                lstrcat(key, _T("\\shell\\open\\command"));            if (GetRegKey(HKEY_CLASSES_ROOT,key,key) == ERROR_SUCCESS) {
                    TCHAR *pos;
                    pos = _tcsstr(key, _T("\"%1\""));
                    if (pos == NULL) {                     // No quotes found
                        pos = _tcsstr(key, _T("%1"));       // Check for %1, without quotes 
                        if (pos == NULL)                   // No parameter at all...
                            pos = key+lstrlen(key)-1;
                        else
                            *pos = '\0';                   // Remove the parameter
                    }
                    else
                        *pos = '\0';                       // Remove the parameter                lstrcat(pos, _T(" "));
                    lstrcat(pos, url);#ifdef _UNICODE
                    USES_CONVERSION;
                    result = (HINSTANCE) WinExec(T2A(key),showcmd);
    #else
                    result = (HINSTANCE) WinExec(key,showcmd);
    #endif
                }
            }
        }    return result;
    }void CHyperLink::InitHyperLink(CString strLink, HCURSOR hCursor)
    {
        m_strURL = strLink;
        m_hLinkCursor = hCursor;
    }
      

  2.   

    考,上边的是CPP,
    H在这里:
      #if !defined(AFX_HYPERLINK_H__D1625061_574B_11D1_ABBA_00A0243D1382__INCLUDED_)
    #define AFX_HYPERLINK_H__D1625061_574B_11D1_ABBA_00A0243D1382__INCLUDED_#if _MSC_VER >= 1000
    #pragma once
    #endif // _MSC_VER >= 1000
    class CHyperLink : public CStatic
    {
    // Construction/destruction
    public:
        CHyperLink();
        virtual ~CHyperLink();// Attributes
    public:// Operations
    public:
    void InitHyperLink(CString strLink,HCURSOR hCursor);// Overrides
        // ClassWizard generated virtual function overrides
        //{{AFX_VIRTUAL(CHyperLink)
        public:
        protected:
        virtual void PreSubclassWindow();
        //}}AFX_VIRTUAL// Implementation
    protected:
        HINSTANCE GotoURL(LPCTSTR url, int showcmd);
        LONG GetRegKey(HKEY key, LPCTSTR subkey, LPTSTR retdata);// Protected attributes
    protected:
        HCURSOR m_hLinkCursor;
        BOOL     m_bOverControl;                        // cursor over control?
        CString  m_strURL;                              // hyperlink URL
        CFont    m_Font;                                // Underline font if necessary        // Generated message map functions
    protected:
        //{{AFX_MSG(CHyperLink)
        afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
        afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);    afx_msg void OnMouseMove(UINT nFlags, CPoint point);
        //}}AFX_MSG
        afx_msg void OnClicked();
        DECLARE_MESSAGE_MAP()
    };///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
    // Microsoft Developer Studio will insert additional declarations immediately before the previous line.#endif // !defined(AFX_HYPERLINK_H__D1625061_574B_11D1_ABBA_00A0243D1382__INCLUDED_)
      

  3.   

    我手上有个这样的代码控件。网上也有下载,注意是点击的时候,调用ShellExecute函数打开浏览器。具体的www.vchelp.net上有下载的。叫Hyperlink控件
      

  4.   

    to iProgram
    我这里还有一个问题?请大哥一并给解答了吧!好不好?
    http://www.csdn.net/expert/topic/136/136562.shtm
    那一个分更多!
      

  5.   

    Usage:
    m_url.InitHyperLink(_T("http://www.csdn.net"),AfxGetApp()->LoadCursor(IDC_CURSOR_HAND));
    m_url是对话框上CStatic控件,用ClassWizard做成CHyperLink m_url
      

  6.   

    to IMarksman:
    你的名字好酷
      

  7.   

    CSplid什么Wnd的那个偶没用过,所以不会