📄 csdemoclientmodule.cpp
字号:
// CsDemoClientModule.cpp : implementation file
//
#include "stdafx.h"
#include "CsDemoClient.h"
#include "CsDemoClientModule.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCsDemoClientModule
IMPLEMENT_DYNCREATE(CCsDemoClientModule, CCmdTarget)
DELEGATE_DUAL_INTERFACE(CCsDemoClientModule, RTXCModule)
CCsDemoClientModule::CCsDemoClientModule()
{
EnableAutomation();
// To keep the application running as long as an OLE automation
// object is active, the constructor calls AfxOleLockApp.
AfxOleLockApp();
}
CCsDemoClientModule::~CCsDemoClientModule()
{
// To terminate the application when all objects created with
// with OLE automation, the destructor calls AfxOleUnlockApp.
AfxOleUnlockApp();
}
void CCsDemoClientModule::OnFinalRelease()
{
// When the last reference for an automation object is released
// OnFinalRelease is called. The base class will automatically
// deletes the object. Add additional cleanup required for your
// object before calling the base class.
CCmdTarget::OnFinalRelease();
}
BEGIN_MESSAGE_MAP(CCsDemoClientModule, CCmdTarget)
//{{AFX_MSG_MAP(CCsDemoClientModule)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BEGIN_DISPATCH_MAP(CCsDemoClientModule, CCmdTarget)
//{{AFX_DISPATCH_MAP(CCsDemoClientModule)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()
BEGIN_INTERFACE_MAP(CCsDemoClientModule, CCmdTarget)
INTERFACE_PART(CCsDemoClientModule, IID_IRTXCModule, RTXCModule)
INTERFACE_PART(CCsDemoClientModule, IID_IRTXCPlugin, RTXCModule)
END_INTERFACE_MAP()
// {7B1B9AF1-272D-4CEC-B885-4EA65237502A}
IMPLEMENT_OLECREATE(CCsDemoClientModule, "RTXC.CsDemoClientModule",
0x7b1b9af1, 0x272d, 0x4cec, 0xb8, 0x85, 0x4e, 0xa6, 0x52, 0x37, 0x50, 0x2a)
/////////////////////////////////////////////////////////////////////////////
// CCsDemoClientModule message handlers
HRESULT CCsDemoClientModule::get_Identifier(BSTR* pVal)
{
RTX_CHECK_INVALIDARG_NULL(pVal);
*pVal = CString(RTX_MODULE_IDENTIFIER_CSDEMOCLIENT).AllocSysString();
return S_OK;
}
HRESULT CCsDemoClientModule::get_Name(BSTR* pVal)
{
RTX_CHECK_INVALIDARG_NULL(pVal);
*pVal = CString(RTX_MODULE_NAME_CSDEMOCLIENT).AllocSysString();
return S_OK;
}
HRESULT CCsDemoClientModule::get_ModuleSite(IDispatch* *pVal)
{
RTX_CHECK_INVALIDARG_NULL(pVal);
*pVal = (IDispatch*)m_ptrModuleSite;
if (*pVal != NULL)
{
(*pVal)->AddRef();
return S_OK;
}
return E_FAIL;
}
HRESULT CCsDemoClientModule::OnLoad(IDispatch* RTXCModuleSite)
{
RTX_CHECK_INVALIDARG_NULL(RTXCModuleSite);
RTX_TRY
{
m_ptrModuleSite = RTXCModuleSite;
m_ptrRoot = m_ptrModuleSite->RTXCRoot;
m_RootEventSink.HookEvent(evt_OnLoginResult, this, &CCsDemoClientModule::OnLoginResult);
VERIFY(m_RootEventSink.Advise(m_ptrRoot));
m_ModuleSiteEventSink.HookEvent(evt_OnDataReceived, this, &CCsDemoClientModule::OnDataReceived);
m_ModuleSiteEventSink.HookEvent(evt_OnViewData, this, &CCsDemoClientModule::OnViewData);
m_ModuleSiteEventSink.HookEvent(evt_OnSendDataResult, this, &CCsDemoClientModule::OnSendDataResult);
VERIFY(m_ModuleSiteEventSink.Advise(m_ptrModuleSite));
return S_OK;
}
RTX_CATCH_ALL(return E_FAIL)
}
HRESULT CCsDemoClientModule::OnAccountChange()
{
return S_OK;
}
HRESULT CCsDemoClientModule::OnInvoke(VARIANT Receiver,
VARIANT Parameter, VARIANT Extra, VARIANT* Result)
{
return S_OK;
}
HRESULT CCsDemoClientModule::OnUnload(enum RTXC_MODULE_UNLOAD_REASON Reason)
{
VERIFY(m_RootEventSink.Unadvise());
m_RootEventSink.UnhookEvent(evt_OnLoginResult, this, &CCsDemoClientModule::OnLoginResult);
VERIFY(m_ModuleSiteEventSink.Unadvise());
m_ModuleSiteEventSink.UnhookEvent(evt_OnDataReceived, this, &CCsDemoClientModule::OnDataReceived);
m_ModuleSiteEventSink.UnhookEvent(evt_OnViewData, this, &CCsDemoClientModule::OnViewData);
m_ModuleSiteEventSink.UnhookEvent(evt_OnSendDataResult, this, &CCsDemoClientModule::OnSendDataResult);
return S_OK;
}
HRESULT CCsDemoClientModule::get_Info(enum RTXC_PLUGIN_INFO_FIELD Field, BSTR *pVal)
{
RTX_CHECK_INVALIDARG_NULL(pVal);
*pVal = NULL;
if (Field == RTXC_PLUGIN_INFO_FIELD_DESCRIPTION)
{
*pVal = CString(RTX_MODULE_DESCRIPTION_CSDEMOCLIENT).AllocSysString();
}
return S_OK;
}
void CCsDemoClientModule::OnLoginResult(RTXC_LOGIN_RESULT Result)
{
if( Result == RTXC_LOGIN_RESULT_OK) //客户端登录成功时显示该窗口
{
CCsDemoClientDlg* m_pDlg = new CCsDemoClientDlg;
m_pDlg->Init(m_ptrModuleSite); //把RTX的m_ptrModuleSite指针传给窗口
m_pDlg->DoModal(); //显示窗口
delete m_pDlg;
m_pDlg = NULL;
}
}
void CCsDemoClientModule::OnDataReceived(LPCTSTR Key)
{
IRTXCDataPtr& ptrData = m_ptrModuleSite->GetData(_bstr_t(Key), VARIANT_TRUE); //获取服务器应用传过来的数据,获取出来为一个RTXCData对象
CComBSTR bstrSender = (BSTR)ptrData->GetString(_bstr_t("Sender")); //获取发送者
CComBSTR bstrMsg = (BSTR)ptrData->GetString(_bstr_t("Content")); //获取消息内容
AfxMessageBox("发送者:" + bstrSender + " 消息内容:" + bstrMsg,MB_OK,NULL);
}
void CCsDemoClientModule::OnViewData(LPCTSTR Key)
{
}
void CCsDemoClientModule::OnSendDataResult(RTXC_MODULE_SEND_DATA_RESULT Result, const VARIANT* Extra)
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -