Exemplo n.º 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();
}
Exemplo n.º 2
0
void ChatDialog::Notify(TNotifyUI& msg)
{
	if (_tcsicmp(msg.sType, _T("windowinit")) == 0)
	{
		OnPrepare(msg);
	}
	else if (_tcsicmp(msg.sType, _T("killfocus")) == 0)
	{
	}
	else if (_tcsicmp(msg.sType, _T("click")) == 0)
	{
		if (_tcsicmp(msg.pSender->GetName(), kCloseButtonControlName) == 0)
		{
			OnExit(msg);
		}
		else if (_tcsicmp(msg.pSender->GetName(), kMinButtonControlName) == 0)
		{

			SendMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0);

		}
		else if (_tcsicmp(msg.pSender->GetName(), kMaxButtonControlName) == 0)
		{

			SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0);

		}
		else if (_tcsicmp(msg.pSender->GetName(), kRestoreButtonControlName) == 0)
		{

			SendMessage(WM_SYSCOMMAND, SC_RESTORE, 0);

		}
		else if (_tcsicmp(msg.pSender->GetName(), kFontButtonControlName) == 0)
		{
			CContainerUI* pFontbar = static_cast<CContainerUI*>(paint_manager_.FindControl(kFontbarControlName));
			if (pFontbar != NULL)
				pFontbar->SetVisible(!pFontbar->IsVisible());
		}
		else if (_tcsicmp(msg.pSender->GetName(), kEmotionButtonControlName) == 0)
		{
			POINT pt = {0};
			CDuiRect rcEmotionBtn = msg.pSender->GetPos();
			CDuiRect rcWindow;
			GetWindowRect(m_hWnd, &rcWindow);

			pt.y = rcWindow.top + rcEmotionBtn.top;
			pt.x = rcWindow.left + rcEmotionBtn.left;
			//emotion_list_window_.SelectEmotion(pt);
			new CEmotion(this,pt);
		}
		else if (_tcsicmp(msg.pSender->GetName(), kSendButtonControlName) == 0)
        {
			CRichEditUI* pRichEdit = static_cast<CRichEditUI*>(paint_manager_.FindControl(kInputRichEditControlName));
			CRichEditUI* pViewEdit = static_cast<CRichEditUI*>(paint_manager_.FindControl(kViewRichEditControlName));
			if( pRichEdit == NULL ) return;
			pRichEdit->SetFocus();
			CDuiString sText = pRichEdit->GetTextRange(0, pRichEdit->GetTextLength());
			//CDuiString sText=pRichEdit->GetEditGifStr();
		    if( sText.IsEmpty() ) 
				return;

			int textlen = sText.GetLength();

			if (textlen > 512)
			{  
				pViewEdit->SetTextColor(RGB(255,0,0));
				pViewEdit->SetText(_T("错误!发送数据的长度不能超过512字节。")); 
			}
			else
			{
				int imNum = friend_.id;
				TCHAR sendmesg[513] = {0};


				_stprintf_s(sendmesg,512,_T("%s"),sText.GetData());
				int len = strlen(sendmesg);

				if (len !=textlen)
				{
					pViewEdit->SetTextColor(RGB(255,0,0));
					pViewEdit->SetText(_T("警告!发送数据的长度和计算的不同。")); 
				}
				frame_wnd_->m_pTcpCommunication->SendMsg(MSG_TYPE_FRIEND,imNum,sendmesg,textlen);
				//显示在
				SendMsg(g_myself_info.nick_name,sText);
				pRichEdit->SetText(_T(""));
                //test
				//CDuiString strbmp;
				//strbmp.Format("c:\\1.gif");
				//pRichEdit->InsertGif(strbmp);
			}

		}
	}
    else if( _tcsicmp(msg.sType, _T("return")) == 0 ) 
    {
        if (_tcsicmp(msg.pSender->GetName(), kInputRichEditControlName) == 0)
        {
			CRichEditUI* pRichEdit = static_cast<CRichEditUI*>(paint_manager_.FindControl(kInputRichEditControlName));
			CRichEditUI* pViewEdit = static_cast<CRichEditUI*>(paint_manager_.FindControl(kViewRichEditControlName));
			if( pRichEdit == NULL ) return;
			pRichEdit->SetFocus();
			CDuiString sText = pRichEdit->GetTextRange(0, pRichEdit->GetTextLength());
			if( sText.IsEmpty() ) 
				return;

			int textlen = sText.GetLength();

			if (textlen > 512)
			{  
				pViewEdit->SetTextColor(RGB(255,0,0));
				pViewEdit->SetText(_T("错误!发送数据的长度不能超过512字节。")); 
			}
			else
			{
				int imNum = friend_.id;
				TCHAR sendmesg[513] = {0};
                 
				
				_stprintf_s(sendmesg,512,_T("%s"),sText.GetData());
                int len = strlen(sendmesg);

				if (len !=textlen)
				{
					pViewEdit->SetTextColor(RGB(255,0,0));
					pViewEdit->SetText(_T("警告!发送数据的长度和计算的不同。")); 
				}
				frame_wnd_->m_pTcpCommunication->SendMsg(MSG_TYPE_FRIEND,imNum,sendmesg,textlen);
				//显示在
				SendMsg(g_myself_info.nick_name,sText);
				pRichEdit->SetText(_T(""));
			}
        }
    }
	else if (_tcsicmp(msg.sType, _T("timer")) == 0)
	{
		return OnTimer(msg);
	}
	else if (_tcsicmp(msg.sType, _T("selectchanged")) == 0)
	{
		if (_tcsicmp(msg.pSender->GetName(), kColorButtonControlName) == 0)
		{
			CContainerUI* pFontbar = static_cast<CContainerUI*>(paint_manager_.FindControl(kFontbarControlName));
			if (pFontbar != NULL)
			{
				POINT pt = {0};
				CDuiRect rcFontbar = pFontbar->GetPos();
				CDuiRect rcColorBtn = msg.pSender->GetPos();
				CDuiRect rcWindow;
				GetWindowRect(m_hWnd, &rcWindow);

				pt.y = rcWindow.top + rcFontbar.top;
				pt.x = rcWindow.left + rcColorBtn.left + static_cast<LONG>(rcColorBtn.right - rcColorBtn.left / 2);
				
			     new CColorPicker((ChatDialog*)this, pt);
			
			}
		}
		else if (_tcsicmp(msg.pSender->GetName(), kBoldButtonControlName) == 0)
		{
			COptionUI* bold_button = static_cast<COptionUI*>(msg.pSender);
			if (bold_button != NULL)
			{
				bold_ = bold_button->IsSelected();
				FontStyleChanged();
			}
		}
		else if (_tcsicmp(msg.pSender->GetName(), kItalicButtonControlName) == 0)
		{
			COptionUI* italic_button = static_cast<COptionUI*>(msg.pSender);
			if (italic_button != NULL)
			{
				italic_ = italic_button->IsSelected();
				FontStyleChanged();
			}
		}
		else if (_tcsicmp(msg.pSender->GetName(), KUnderlineButtonControlName) == 0)
		{
			COptionUI* underline_button = static_cast<COptionUI*>(msg.pSender);
			if (underline_button != NULL)
			{
				underline_ = underline_button->IsSelected();
				FontStyleChanged();
			}
		}
	}
	else if (_tcsicmp(msg.sType, _T("itemselect")) == 0)
	{
		if (_tcsicmp(msg.pSender->GetName(), kFontTypeControlName) == 0)
		{
			CComboUI* font_type = static_cast<CComboUI*>(msg.pSender);
			if (font_type != NULL)
			{
				font_face_name_ = font_type->GetText();
				FontStyleChanged();
			}
		}
		else if (_tcsicmp(msg.pSender->GetName(), kFontSizeControlName) == 0)
		{
			CComboUI* font_size = static_cast<CComboUI*>(msg.pSender);
			if (font_size != NULL)
			{
				font_size_ = _ttoi(font_size->GetText());
				FontStyleChanged();
			}
		}
	}
}