Exemple #1
0
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();
}
Exemple #2
0
void main_frame::Notify( TNotifyUI& msg )
{
	if( msg.sType == _T("windowinit") ) 
		OnPrepare(msg);
	else if (_tcsicmp(msg.sType,_T("click")) == 0)
	{
		if (_tcsicmp(msg.pSender->GetName(),_T("closebtn")) == 0 )
		{	
			Close();
		}
		else if (_tcsicmp(msg.pSender->GetName(),_T("minbtn")) == 0)
		{
			SendMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0);
		}
		else if (_tcsicmp(msg.pSender->GetName(),_T("maxbtn")) == 0)
		{
			SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0);
		}
		else if (_tcsicmp(msg.pSender->GetName(),_T("tagBtn")) == 0)
		{
			CRichEditUI *pRichEdit = static_cast<CRichEditUI*>(m_PaintManager.FindControl(_T("weiboContent")));
			if (pRichEdit)
			{
				CDuiString strText = _T("#²åÈëÄãµÄ»°Ìâ#");
				pRichEdit->SetText(strText);
				pRichEdit->SetSel(1,7);
				pRichEdit->SetFocus();
				
				CLabelUI *plabel = static_cast<CLabelUI*>(m_PaintManager.FindControl(_T("defaultShowText")));
				if (plabel)
				{
					plabel->SetVisible(false);
				}
				
			}
		}
		else if (_tcsicmp(msg.pSender->GetName(),_T("sendWeiboBtn")) == 0)
		{
			CRichEditUI *pRichEdit = static_cast<CRichEditUI*>(m_PaintManager.FindControl(_T("weiboContent")));
			if (pRichEdit)
			{
				CDuiString strWeibo = pRichEdit->GetText();
				if (strWeibo.GetLength() > 0)
				{
					DWORD dwNum = WideCharToMultiByte(CP_UTF8,NULL,strWeibo,-1,NULL,0,NULL,FALSE);
					char *psText;
					psText = new char[dwNum];
					if(!psText)
					{
						delete []psText;
					}
					WideCharToMultiByte (CP_UTF8,NULL,strWeibo,-1,psText,dwNum,NULL,FALSE);
					m_weiboManage.PostNewWeibo(psText);

					delete []psText;

					pRichEdit->SetText(_T(""));
				}
			}
		}
		else if (_tcsicmp(msg.pSender->GetName(),_T("refreshBtn")) == 0)
		{
			m_weiboManage.RefreshTimeline();
		}
	}
	
}
Exemple #3
0
//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;
}