2012-02-10 21:14:24|?次阅读|上传:wustguangh【已有?条评论】发表评论
关键词:C/C++, MFC, 界面设计|来源:唯设编程网
三.聊天常用
a.LINK 链接功能
1. LoadLibrary(_T("Riched20.dll"));
2. 创建RichEdit2.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);
3. 设定选中的文字为链接显示
CHARFORMAT2 cf2; ZeroMemory(&cf2, sizeof(CHARFORMAT2));// cf2.cbSize = sizeof(CHARFORMAT2); cf2.dwMask = CFM_LINK; cf2.dwEffects |= CFE_LINK; m_cRichEdit.SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf2);
4.支持链接的点击响应
m_cRichEdit.SetEventMask(ENM_LINK);
5.响应链接的点击EN_LINK BEGIN_MESSAGE_MAP(CMyRichEdit, CRichEditCtrl)
ON_NOTIFY_REFLECT(EN_LINK,OnURL) END_MESSAGE_MAP() ...... void CMyRichEdit::OnURLClick(NMHDR *pNmhdr, LRESULT *pResult) { TCHAR LinkChar[512]; ENLINK *pLink = (ENLINK *)pNmhdr; if (pLink->msg == WM_LBUTTONUP) { SetSel(penLink->chrg);//这是链接的文字范围 long Res = GetSelText((char *)LinkChar);//这是链接文字 //后面是你的处理过程 ...... } }