📄 mysocket.cpp
字号:
// MySocket.cpp : implementation file
//
#include "stdafx.h"
#include "UDP.h"
#include "MySocket.h"
#include "MainFrm.h"
#include "UDPView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// MySocket
MySocket::MySocket()
{
//第一个数据用于建立连接,所以接收不到,在此赋值
scrpoint.x=-1;
scrpoint.y=0;
myarray.Add(scrpoint);
}
MySocket::~MySocket()
{
}
// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(MySocket, CAsyncSocket)
//{{AFX_MSG_MAP(MySocket)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif // 0
/////////////////////////////////////////////////////////////////////////////
// MySocket member functions
void MySocket::OnReceive(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
//接收UDP数据
int iRecv=ReceiveFrom((struct mpoint*)&scrpoint,10,szIP,uPort,0);
myarray.Add(scrpoint);//将点保存到数组中
CString mystatus="xxxxxx yyyyyy";
mystatus.Format("x=%d y=%d",scrpoint.x,scrpoint.y);//转换成字符串
CMainFrame* pFrame=(CMainFrame*)AfxGetMainWnd();//得到主窗口指针
if(scrpoint.x!=-1){
pFrame->m_wndStatusBar.SetPaneText(0,mystatus);//在状态栏上显示
}
CUDPView* pView=( CUDPView*) pFrame->GetActiveView();//得到活动视类指针
pView->Invalidate();//更新屏幕
/////////////////////////////////////////////////////////////////
CAsyncSocket::OnReceive(nErrorCode);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -