www.pudn.com > IP.rar > MessageDlg.cpp, change:2009-04-07,size:3852b


//Download by http://www.codefans.net 
#include "stdafx.h" 
#include "rtccore.h" 
#include "AVDConf.h" 
#include "MessageDlg.h" 
#include "defines.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CMessageDlg dialog 
 
 
CMessageDlg::CMessageDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CMessageDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CMessageDlg) 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
} 
 
 
void CMessageDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CMessageDlg) 
	DDX_Control(pDX, IDC_MESSAGE, m_cMessage); 
	DDX_Control(pDX, IDC_TEXT, m_cText); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CMessageDlg, CDialog) 
	//{{AFX_MSG_MAP(CMessageDlg) 
	ON_BN_CLICKED(IDC_SENDTEXT, OnSendtext) 
	ON_BN_CLICKED(IDC_CLEAR, OnClear) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
 
HRESULT CMessageDlg::DeliverMessage(IRTCParticipant *pParticipant, BSTR bstrContentType,  
									BSTR bstrMessage) 
{ 
    HRESULT hr; 
    BSTR bstrURI = NULL; 
 
    hr = pParticipant->get_UserURI(&bstrURI); 
 
    if (FAILED(hr)) 
    { 
         
        return hr; 
    } 
 
     
	char szBuf[256], szText[265]; 
	wcstombs ( szBuf, bstrURI, 256); 
	SendDlgItemMessage (IDC_MESSAGE, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)szBuf); 
	 
	wcstombs ( szBuf, bstrMessage, 256 ); 
	sprintf ( szText, "     %s", szBuf ); 
	SendDlgItemMessage (IDC_MESSAGE, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)szText); 
 
    if (FAILED(hr)) 
    { 
        
        return hr; 
    } 
 
    if (FAILED(hr)) 
    { 
         
        return hr; 
    } 
 
    return S_OK; 
} 
 
 
HRESULT CMessageDlg::DeliverUserStatus(IRTCParticipant *pParticipant, RTC_MESSAGING_USER_STATUS enStatus) 
{ 
    HRESULT hr; 
    BSTR bstrURI = NULL; 
 
     
    hr = pParticipant->get_UserURI(&bstrURI); 
 
    if (FAILED(hr)) 
    { 
         
        return hr; 
    } 
 
     
	if (enStatus) 
	{ 
		char szTyping[256], szBuf[256]; 
 
		wcstombs ( szBuf, bstrURI, 256 ); 
        wsprintf(szTyping, "%s is typing.", szBuf); 
 
        SetDlgItemText ( IDC_STATUSTEXT, szTyping ); 
 	} 
 
    if (FAILED(hr)) 
    { 
        
        return hr; 
    } 
 
    return S_OK; 
} 
 
 
void CMessageDlg::OnSendtext()  
{ 
	LONG	lLength; 
	BSTR	bstrMessage; 
	WCHAR	szBuf[256]; 
 
	GetDlgItemTextW (m_hWnd, IDC_TEXT, szBuf, 256); 
	if ((lLength = lstrlenW(szBuf)) > 0) 
	{ 
		bstrMessage = SysAllocString ( szBuf ); 
 
		if (bstrMessage == NULL) 
		{ 
			 
			return; 
		} 
 
		DoDisplayMessage(); 
 
		m_pParentSession->SendMessage ( NULL, bstrMessage, 0 ); 
 
		SAFE_FREE_STRING (bstrMessage); 
	} 
 
} 
 
 
void CMessageDlg::OnClear()  
{ 
	m_cMessage.ResetContent (); 
} 
 
 
BOOL CMessageDlg::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	 
	m_cText.LimitText ( 256 ); 
 
	return TRUE;   
} 
 
 
void CMessageDlg::SetParentClient(IRTCClient *pClient) 
{ 
	m_pParentClient = pClient; 
} 
 
 
void CMessageDlg::SetSession(IRTCSession *pSession) 
{ 
	m_pParentSession = pSession; 
} 
 
 
void CMessageDlg::OnOK()  
{ 
	HRESULT hr = m_pParentSession->Terminate(RTCTR_NORMAL); 
 
	SAFE_RELEASE (m_pParentSession); 
 
	DestroyWindow(); 
} 
 
 
void CMessageDlg::DoDisplayMessage() 
{ 
	BSTR bstrURI = NULL; 
	char szBuf[256], LBBuf[265]; 
 
	HRESULT hr = m_pParentClient->get_LocalUserURI (&bstrURI); 
 
	wcstombs(szBuf, bstrURI, 256); 
	SendDlgItemMessage (IDC_MESSAGE, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)szBuf ); 
 
	GetDlgItemText (IDC_TEXT, szBuf, 256); 
	wsprintf ( LBBuf, "       %s", szBuf ); 
	SendDlgItemMessage (IDC_MESSAGE, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)LBBuf); 
 
	m_cText.SetSel (0, -1); 
	m_cText.ReplaceSel (""); 
} 
 
 
void CMessageDlg::OnCancel()  
{ 
	return;	 
}