📄 udpview.cpp
字号:
// UDPView.cpp : implementation of the CUDPView class
//
#include "stdafx.h"
#include "UDP.h"
#include "UDPDoc.h"
#include "UDPView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CUDPView
IMPLEMENT_DYNCREATE(CUDPView, CView)
BEGIN_MESSAGE_MAP(CUDPView, CView)
//{{AFX_MSG_MAP(CUDPView)
ON_COMMAND(ID_CLEARSCREEN, OnClearscreen)
ON_COMMAND(ID_ShowIPDialog, OnShowIPDialog)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CUDPView construction/destruction
CUDPView::CUDPView()
{
// TODO: add construction code here
IsClearnScreen=false;
IsDrawing=false;
}
CUDPView::~CUDPView()
{
}
BOOL CUDPView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
//创建本地套接口
m_sockRecv.Create(5000,SOCK_DGRAM);
/////////////////////////////////////////////////////////////////
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CUDPView drawing
void CUDPView::OnDraw(CDC* pDC)
{
CUDPDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//定义坐标系
pDC->SetMapMode(MM_ANISOTROPIC);
pDC->SetWindowOrg(0,0);
pDC->SetWindowExt(320,240);
pDC->SetViewportOrg(125,75);
pDC->SetViewportExt(480,360);
//画边框
/*pDC->MoveTo(0,0);
pDC->LineTo(320,0);
pDC->LineTo(320,240);
pDC->LineTo(0,240);
pDC->LineTo(0,0);*/
//根据输入进行绘线
for(int i=0;i<m_sockRecv.myarray.GetSize();i++)
{
if(m_sockRecv.myarray[i].x<0){
IsDrawing=false;
}
else{
if(IsDrawing){
pDC->LineTo(m_sockRecv.myarray[i].x,m_sockRecv.myarray[i].y);
}
else{
pDC->MoveTo(m_sockRecv.myarray[i].x,m_sockRecv.myarray[i].y);
}
IsDrawing=true;
}
}
////////////////////////////////////////////////////////////////
}
/////////////////////////////////////////////////////////////////////////////
// CUDPView printing
BOOL CUDPView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CUDPView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CUDPView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CUDPView diagnostics
#ifdef _DEBUG
void CUDPView::AssertValid() const
{
CView::AssertValid();
}
void CUDPView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CUDPDoc* CUDPView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CUDPDoc)));
return (CUDPDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CUDPView message handlers
void CUDPView::OnClearscreen()
{
// TODO: Add your command handler code here
IsClearnScreen=true;
//发送清屏命令
//ARM端用于接收的端口比用于发送的端口小一
int iSend=m_sockRecv.SendTo((int*)&IsClearnScreen,sizeof(int),m_sockRecv.uPort-1,m_sockRecv.szIP,0);
m_sockRecv.myarray.RemoveAll();//删除数组中所有点
Invalidate();
IsClearnScreen=false;
/////////////////////////////////////////////////////////////////
}
void CUDPView::OnShowIPDialog()
{
// TODO: Add your command handler code here
SetIPDialog.DoModal();
int test=1;
int iSend=m_sockRecv.SendTo((int*)&test,sizeof(int),4998,SetIPDialog.m_IP,0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -