⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ipc_msgclientdlg.cpp

📁 EVC编写的WINCE下进程通讯程序客户端
💻 CPP
字号:
// IPC_MSGClientDlg.cpp : implementation file
//

#include "stdafx.h"
#include "IPC_MSGClient.h"
#include "IPC_MSGClientDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CIPC_MSGClientDlg dialog

CIPC_MSGClientDlg::CIPC_MSGClientDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CIPC_MSGClientDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CIPC_MSGClientDlg)
	m_SessionName = _T("");
	m_SendData = _T("");
	m_RecvData = _T("");
	m_Status = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CIPC_MSGClientDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CIPC_MSGClientDlg)
	DDX_Text(pDX, IDC_EDTSESSIONNAME, m_SessionName);
	DDX_Text(pDX, IDC_EDTSEND, m_SendData);
	DDX_Text(pDX, IDC_EDTRECV, m_RecvData);
	DDX_Text(pDX, IDC_STATICSTATUS, m_Status);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CIPC_MSGClientDlg, CDialog)
	//{{AFX_MSG_MAP(CIPC_MSGClientDlg)
	ON_BN_CLICKED(IDC_BTNCONNECT, OnBtnconnect)
	ON_BN_CLICKED(IDC_BTNDISCONNECT, OnBtndisconnect)
	ON_BN_CLICKED(IDC_BTNSENDDATA, OnBtnsenddata)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CIPC_MSGClientDlg message handlers

BOOL CIPC_MSGClientDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	CenterWindow(GetDesktopWindow());	// center to the hpc screen

	// TODO: Add extra initialization here

	if (!m_IPCClient.CreateEx(WS_EX_CLIENTEDGE, _T("STATIC"),
		_T("Hi"), WS_POPUP, 5, 5, 30, 30, m_hWnd, NULL));
	{
		AfxMessageBox(_T("创建进程通讯客户端失败"));
	}

	m_IPCClient.m_ClientConnected = OnClientConnected;
	m_IPCClient.m_ClientDisConnected = OnClientDisConnected;
	m_IPCClient.m_ClientDataArrive = OnClientDataArrive;
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

/*
*函数介绍:客户端连接建立事件处理函数
*入口参数:paretnWnd: 创建通讯类的窗体指针
		   hWnd: 服务器端窗口句柄
*出口参数:无
*返回值:  无
*/
void CALLBACK CIPC_MSGClientDlg::OnClientConnected(CWnd *parentWnd, HWND hWnd)
{
	CIPC_MSGClientDlg * pDlg;
	pDlg = (CIPC_MSGClientDlg *)parentWnd;

	pDlg->m_Status = _T("连接状态:连接成功");
	pDlg->UpdateData(FALSE);
}

/*
*函数介绍:客户端连接断开处理函数
*入口参数:parentWnd: 创建通讯类的窗体指针
		   hWnd: 服务器端窗口句柄
*出口参数:无
*返回值:  无
*/
void CALLBACK CIPC_MSGClientDlg::OnClientDisConnected(CWnd *parentWnd, HWND hWnd)
{
	CIPC_MSGClientDlg * pDlg;
	pDlg = (CIPC_MSGClientDlg *)parentWnd;

	pDlg->m_Status = _T("连接状态:连接不成功");
	pDlg->UpdateData(FALSE);
}


/*
*函数介绍:客户端接收数据事件处理函数
*入口参数:parentWnd: 创建通讯类的窗体指针
		   pData: 接收数据指针
		   bufLen: 接收数据长度
		   hWnd: 服务器端窗口句柄
*出口参数:无
*返回值:  无
*/
void CALLBACK CIPC_MSGClientDlg::OnClientDataArrive(CWnd *parentWnd, LPVOID pData, DWORD bufLen)
{
	CIPC_MSGClientDlg * pDlg;
	pDlg = (CIPC_MSGClientDlg *)parentWnd;

	pDlg->m_RecvData = LPCTSTR(pData);
	pDlg->UpdateData(FALSE);
}


/*
*函数介绍:“建立连接”按钮单击事件
*入口参数:无
*出口参数:无
*返回值:  无
*/
void CIPC_MSGClientDlg::OnBtnconnect() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_IPCClient.m_SessionName = m_SessionName;
	m_IPCClient.Open(this);
}

/*
*函数介绍:“断开连接”按钮单击事件
*入口参数:无
*出口参数:无
*返回值:无
*/
void CIPC_MSGClientDlg::OnBtndisconnect() 
{
	// TODO: Add your control notification handler code here
	m_IPCClient.Close();
}

/*
*函数介绍:“发送数据”按钮单击事件
*入口参数:无
*出口参数:无
*返回值:无
*/
void CIPC_MSGClientDlg::OnBtnsenddata() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_IPCClient.SendMsg(m_SendData.GetBuffer(m_SendData.GetLength()),
						m_SendData.GetLength()*2);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -