感谢在该贴http://community.csdn.net/Expert/topic/4444/4444759.xml?temp=.133938中的大虾的帮忙,已经可以在2000及以上的操作系统上实现了链接功能,但是该代码却不能在98下面使用,是不是需要再改一下代码还是98下面要用其它的方法来实现?谢谢

解决方案 »

  1.   

    可能一些系统api什么的不兼容
      

  2.   

    Richedit是动态创建的么
    CreateEx(0, _T("RichEdit20A"), NULL, WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_TABSTOP
    |ES_READONLY|ES_WANTRETURN|ES_MULTILINE,
    rect.left, rect.top, cx, cy,
    pParentWnd->m_hWnd, (HMENU)nID, NULL);
      

  3.   

    Richedit不是动态创建的,是dialog里面声明的一个控件
    类似RichEdit m_msg;
      

  4.   

    Richedit必须动态创建,dialog资源里的是richedit 1.0控件,用
    CreateEx(0, _T("RichEdit20A"), NULL, WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_TABSTOP
    |ES_READONLY|ES_WANTRETURN|ES_MULTILINE,
    rect.left, rect.top, cx, cy,
    pParentWnd->m_hWnd, (HMENU)nID, NULL);
      

  5.   

    我是新做了一个edit类,这个类继程了Richedit,在里面有create的函数
    return l_pWnd->Create( _T( "RichEdit20A" ), NULL,
            in_dwStyle, in_rcRect, in_pParentWnd, in_nID ) ;
    在这里面有创建了2.0
      

  6.   

    to goodboyws:你有没有现成的例子可以给我参考一下的?谢谢(VC6的例子)
      

  7.   

    class CMyEdit : public CRichEditCtrl
    {
    // Construction
    public:
    CMyEdit();// Attributes
    public:// Operations
    public:// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CMyEdit)
    //}}AFX_VIRTUAL// Implementation
    public:
    virtual ~CMyEdit(); // Generated message map functions
    protected:
    //{{AFX_MSG(CMyEdit)
    afx_msg void OnDestroy();
    //}}AFX_MSG
    afx_msg void OnURLClick(NMHDR *pNmhdr, LRESULT *pResult); DECLARE_MESSAGE_MAP()public:
    void SetLinkWord(LPCSTR strLink);//这个函数设置链接
    void SetLink();
    BOOL Create( DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID );protected:
    HINSTANCE m_hRichDllHandle;
    };
      

  8.   

    #include "stdafx.h"
    #include "MyApp.h"
    #include "MyEdit.h"
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endifCMyEdit::CMyEdit()
    {
    m_hRichDllHandle = LoadLibrary(_T("Riched20.dll"));
    }CMyEdit::~CMyEdit()
    {
    if(m_hRichDllHandle )
    {
    FreeLibrary(m_hRichDllHandle );
    }
    }
    BEGIN_MESSAGE_MAP(CMyEdit, CRichEditCtrl)
    //{{AFX_MSG_MAP(CMyEdit)
    //}}AFX_MSG_MAP
    ON_NOTIFY_REFLECT(EN_LINK,OnURLClick)
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CMyEdit message handlers
    BOOL   CMyEdit::Create(DWORD dwStyle, const RECT& rect, 
     CWnd* pParentWnd, UINT nID)
    {
    BOOL   Res;
    int    cx,cy;
    cx=rect.right - rect.left;
         cy=rect.bottom - rect.top;
    if(cx<0)
    {
    cx = -cx;
    }
    if(cy<0)
    {
    cy = -cy;
    }

    Res=CWnd::CreateEx(0, _T("RichEdit20A"), NULL, dwStyle,
              rect.left, rect.top, cx, cy,
      pParentWnd->m_hWnd, (HMENU)nID, NULL);

    if(Res)
    {
    SendMessage(EM_AUTOURLDETECT, (WPARAM)true, 0);
    SendMessage(EM_SETLANGOPTIONS, 0, 0);
    }
    return Res;
    }void CMyEdit::SetLinkWord(LPCSTR strLink)
    {
    SetSel(0, -1);
    CString strText = GetSelText();
    int nPos = strText.Find(strLink);
    if (-1 < nPos)
    {

    int nPosStart = MultiByteToWideChar(CP_ACP, 0, strText, nPos, NULL, 0);
    int nPosEnd = MultiByteToWideChar(CP_ACP, 0, strText, nPos + strlen(strLink), NULL, 0);
    SetSel(nPosStart,  nPosEnd);
    }
    SetLink();
    HideSelection(TRUE, FALSE);
    }
    }
    void CMyEdit::SetLink()
    {
    CHARFORMAT2 cf2;
    ZeroMemory(&cf2, sizeof(CHARFORMAT2));//
    cf2.cbSize = sizeof(CHARFORMAT2);
    cf2.dwMask = CFM_LINK;//
     
    SendMessage(EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf2);
    if (cf2.dwEffects & CFE_LINK)
    {
    cf2.dwEffects ^= CFE_LINK;
    }
    else
    {
    cf2.dwEffects |= CFE_LINK;
    }
    SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf2);
    }void CMyEdit::OnURLClick(NMHDR *pNmhdr, LRESULT *pResult)
    {
    TCHAR LinkChar[512];
    ENLINK *penLink = (ENLINK *)pNmhdr;
    if (penLink->msg == WM_LBUTTONUP)
    {
    SetSel(penLink->chrg);
    long Res = GetSelText((char *)LinkChar);
    LinkChar[Res] = 0;
    ShellExecute(NULL, "open", LinkChar[Res] , NULL, NULL, SW_SHOWNORMAL);
    }
    pResult = FALSE;
    }