void ChatDialog::SendMsg() { CRichEditUI* pRichEdit = static_cast<CRichEditUI*>(m_PaintManager.FindControl(kInputRichEditControlName)); if( pRichEdit == NULL ) return; pRichEdit->SetFocus(); CDuiString sText = pRichEdit->GetTextRange(0, pRichEdit->GetTextLength()); if( sText.IsEmpty() ) return; pRichEdit->SetText(_T("")); pRichEdit = static_cast<CRichEditUI*>(m_PaintManager.FindControl(kViewRichEditControlName)); if( pRichEdit == NULL ) return; long lSelBegin = 0, lSelEnd = 0; CHARFORMAT2 cf; ZeroMemory(&cf, sizeof(CHARFORMAT2)); cf.cbSize = sizeof(cf); cf.dwReserved = 0; cf.dwMask = CFM_COLOR | CFM_LINK | CFM_UNDERLINE | CFM_UNDERLINETYPE; cf.dwEffects = CFE_LINK; cf.bUnderlineType = CFU_UNDERLINE; cf.crTextColor = RGB(220, 0, 0); lSelEnd = lSelBegin = pRichEdit->GetTextLength(); pRichEdit->SetSel(lSelEnd, lSelEnd); pRichEdit->ReplaceSel(_T("某人"), false); lSelEnd = pRichEdit->GetTextLength(); pRichEdit->SetSel(lSelBegin, lSelEnd); pRichEdit->SetSelectionCharFormat(cf); lSelEnd = lSelBegin = pRichEdit->GetTextLength(); pRichEdit->SetSel(lSelEnd, lSelEnd); pRichEdit->ReplaceSel(_T("说:\t2011-07-30 08:30:12\n"), false); cf.dwMask = CFM_COLOR; cf.crTextColor = RGB(0, 0, 0); cf.dwEffects = 0; lSelEnd = pRichEdit->GetTextLength(); pRichEdit->SetSel(lSelBegin, lSelEnd); pRichEdit->SetSelectionCharFormat(cf); PARAFORMAT2 pf; ZeroMemory(&pf, sizeof(PARAFORMAT2)); pf.cbSize = sizeof(pf); pf.dwMask = PFM_STARTINDENT; pf.dxStartIndent = 0; pRichEdit->SetParaFormat(pf); lSelEnd = lSelBegin = pRichEdit->GetTextLength(); pRichEdit->SetSel(-1, -1); pRichEdit->ReplaceSel(sText.GetData(), false); pRichEdit->SetSel(-1, -1); pRichEdit->ReplaceSel(_T("\n"), false); cf.crTextColor = RGB(0, 0, 0); lSelEnd = pRichEdit->GetTextLength(); pRichEdit->SetSel(lSelBegin, lSelEnd); pRichEdit->SetSelectionCharFormat(cf); ZeroMemory(&pf, sizeof(PARAFORMAT2)); pf.cbSize = sizeof(pf); pf.dwMask = PFM_STARTINDENT; pf.dxStartIndent = 220; pRichEdit->SetParaFormat(pf); pRichEdit->EndDown(); }
//name 显示的名字,sText内容 int ChatDialog::SendMsg(CDuiString name,CDuiString sText) { CRichEditUI* pRichEdit = static_cast<CRichEditUI*>(paint_manager_.FindControl(kViewRichEditControlName)); if( pRichEdit == NULL ) { DbgPrint("can not find kViewRichEditControlName\n"); return -1; } CDuiString strFolder=CPaintManagerUI::GetInstancePath(); long lSelBegin = 0, lSelEnd = 0; CHARFORMAT2 cf; ZeroMemory(&cf, sizeof(CHARFORMAT2)); cf.cbSize = sizeof(cf); cf.dwReserved = 0; cf.dwMask = CFM_COLOR | CFM_LINK | CFM_UNDERLINE | CFM_UNDERLINETYPE; cf.dwEffects = CFE_LINK; cf.bUnderlineType = CFU_UNDERLINE; cf.crTextColor = RGB(220, 0, 0); lSelEnd = lSelBegin = pRichEdit->GetTextLength(); pRichEdit->SetSel(lSelEnd, lSelEnd); pRichEdit->ReplaceSel((LPCTSTR)name, false); lSelEnd = pRichEdit->GetTextLength(); pRichEdit->SetSel(lSelBegin, lSelEnd); pRichEdit->SetSelectionCharFormat(cf); lSelEnd = lSelBegin = pRichEdit->GetTextLength(); pRichEdit->SetSel(lSelEnd, lSelEnd); CTime time = CTime::GetCurrentTime(); CDuiString sendTime = time.Format(_T("%H:%M:%S")); CDuiString sendtimestr; sendtimestr.Format(_T("说:\t%s\n"),sendTime); pRichEdit->ReplaceSel(sendtimestr, false); //pRichEdit->ReplaceSel(_T("说:\t2011-07-30 08:30:12\n"), false); cf.dwMask = CFM_COLOR; cf.crTextColor = RGB(0, 0, 0); cf.dwEffects = 0; lSelEnd = pRichEdit->GetTextLength(); pRichEdit->SetSel(lSelBegin, lSelEnd); pRichEdit->SetSelectionCharFormat(cf); PARAFORMAT2 pf; ZeroMemory(&pf, sizeof(PARAFORMAT2)); pf.cbSize = sizeof(pf); pf.dwMask = PFM_STARTINDENT; pf.dxStartIndent = 0; pRichEdit->SetParaFormat(pf); lSelEnd = lSelBegin = pRichEdit->GetTextLength(); //插入字符串,需转移表情 //pRichEdit->SetSel(-1, -1); //pRichEdit->ReplaceSel(sText.GetData(), false); pRichEdit->SetSel(-1,-1); int m,begin; begin=0; CDuiString temp; char buff[2]; while(1) { m=sText.Find(_T("#"),begin); if(-1!=m) { temp=sText.Mid(begin,m-begin); pRichEdit->ReplaceSel(temp.GetData(),false); int n=sText.Find(_T(".gif"),m); //find .gif if (n!=-1) { temp = sText.Mid(m+1,n-m+3); if (frame_wnd_) { CDuiString strfacefolder,strface; strfacefolder.Format(_T("%s\\skin\\Faces\\"),strFolder.GetData()); strface.Format(_T("%s\\skin\\Faces\\%s"),strFolder.GetData(),temp.GetData()); if (0==frame_wnd_->find_gif_in_folder(temp,strfacefolder)) { // pRichEdit->InsertGif(strface); } begin=n+4; m=n+4; } else { return 0; } } else { pRichEdit->ReplaceSel(temp,false); begin=n+1; } } else { temp=sText.Mid(begin); pRichEdit->SetSel(-1, -1); pRichEdit->ReplaceSel(temp,false); //pRichEdit->PostMessage(WM_VSCROLL, SB_BOTTOM, 0);//滚动条自动到最后一行 break; } } pRichEdit->SetSel(-1, -1); pRichEdit->ReplaceSel(_T("\n"), false); cf.crTextColor = RGB(0, 0, 0); lSelEnd = pRichEdit->GetTextLength(); // pRichEdit->SetSel(lSelBegin, lSelEnd); pRichEdit->SetSelectionCharFormat(cf); ZeroMemory(&pf, sizeof(PARAFORMAT2)); pf.cbSize = sizeof(pf); pf.dwMask = PFM_STARTINDENT; pf.dxStartIndent = 220; pRichEdit->SetParaFormat(pf); pRichEdit->EndDown(); return 0; }