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

📄 ceudpdlg.cpp

📁 Wince EVC 下的UDP通讯应用程序 自己写的UDP通讯类
💻 CPP
字号:
// CEUDPDlg.cpp : implementation file
//

#include "stdafx.h"
#include "CEUDP.h"
#include "CEUDPDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CCEUDPDlg dialog

CCEUDPDlg::CCEUDPDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCEUDPDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCEUDPDlg)
	m_RemoteHost = _T("192.168.253.178");
	m_RemotePort = 1234;
	m_LocalPort = 2345;
	m_int = 0;
	//}}AFX_DATA_INIT
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CCEUDPDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCEUDPDlg)
	DDX_Text(pDX, IDC_EDIT_REMOTEHOST, m_RemoteHost);
	DDX_Text(pDX, IDC_EDIT_REMOTEPORT, m_RemotePort);
	DDX_Text(pDX, IDC_EDIT_LOCALPORT, m_LocalPort);
	DDX_Text(pDX, IDC_EDIT4, m_int);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CCEUDPDlg, CDialog)
	//{{AFX_MSG_MAP(CCEUDPDlg)
	ON_BN_CLICKED(IDC_BTNOPEN, OnBtnopen)
	ON_BN_CLICKED(IDC_BTNCLOSE, OnBtnclose)
	ON_BN_CLICKED(IDC_BTNSEND, OnBtnsend)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCEUDPDlg message handlers

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

	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
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}



void CCEUDPDlg::OnBtnopen() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);

	DWORD nResult=m_CEUdp.Open(this,m_LocalPort,m_RemoteHost.GetBuffer(m_RemoteHost.GetLength()),m_RemotePort);
	if (nResult<=0)
	{
		AfxMessageBox(_T("打开端口失败"));

	}

	char hostName[255];
	ZeroMemory(hostName,255);
	gethostname(hostName,255);
}

void CCEUDPDlg::OnBtnclose() 
{
	// TODO: Add your control notification handler code here
	m_CEUdp.Close();
}

void CCEUDPDlg::OnBtnsend() 
{
	// TODO: Add your control notification handler code here
	char * sendBuf;
	sendBuf=new char [13];
    char Data[13]={0x88,0x00,0x23,0x12,0x12,0x23,0x34,0x23,0x34,0x23,0x34,0x56,0x78};

	CopyMemory(sendBuf,Data,13);

	m_CEUdp.SendData(sendBuf);
	delete[] sendBuf;
	sendBuf=NULL;	
}

void CCEUDPDlg::OnUdpCERecv(CWnd *pWnd, char *buf, int nLen, sockaddr *addr)
{

    CCEUDPDlg * pDLg;
	pDLg=(CCEUDPDlg*)pWnd;
	char * recvStr;

	recvStr=new char (nLen);
	//取得数据
//	CopyMemory(recvStr,buf,nLen);
    //显示数据
//	CEdit *pRecvStrEdit=(CEdit*)pDLg->GetDlgItem(IDC_EDIT_RECVSTR);
//	ASSERT(pRecvStrEdit!=NULL);
	CString strRecv=recvStr;
//	pRecvStrEdit->SetWindowText(strRecv);

    m_int=nLen;
	UpdateData(false);

	delete[] recvStr;
	recvStr=NULL;

}

void CCEUDPDlg::OnUdpCEError(CWnd *pWnd, int code)
{

}

void CCEUDPDlg::show(CWnd *pWnd,int len)
{
     CCEUDPDlg * pDLg;
	pDLg=(CCEUDPDlg*)pWnd;
    pDLg->SetDlgItemInt(IDC_EDIT4,len,true);

}

⌨️ 快捷键说明

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