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

📄 lxdrawview.cpp

📁 实现网络图象传输
💻 CPP
字号:
// lxdrawView.cpp : implementation of the CLxdrawView class
//

#include "stdafx.h"
#include "lxdraw.h"

#include "lxdrawDoc.h"
#include "lxdrawView.h"
#include "LxLine.h"

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

/////////////////////////////////////////////////////////////////////////////
// CLxdrawView

IMPLEMENT_DYNCREATE(CLxdrawView, CView)

BEGIN_MESSAGE_MAP(CLxdrawView, CView)
	//{{AFX_MSG_MAP(CLxdrawView)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_MOUSEMOVE()
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CLxdrawView construction/destruction

CLxdrawView::CLxdrawView()
{
	// TODO: add construction code here

}

CLxdrawView::~CLxdrawView()
{
}

BOOL CLxdrawView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CLxdrawView drawing

void CLxdrawView::OnDraw(CDC* pDC)
{
	CLxdrawDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	int liCount=pDoc->GetLineCount();
	if(liCount)
	{
		int liPos;
		CLxLine *lptLine;
		for(liPos=0;liPos<liCount;liPos++)
		{
			lptLine=pDoc->GetLine(liPos);
			lptLine->Draw(pDC);
		}
	}

}

/////////////////////////////////////////////////////////////////////////////
// CLxdrawView printing

BOOL CLxdrawView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CLxdrawView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CLxdrawView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CLxdrawView diagnostics

#ifdef _DEBUG
void CLxdrawView::AssertValid() const
{
	CView::AssertValid();
}

void CLxdrawView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CLxdrawDoc* CLxdrawView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CLxdrawDoc)));
	return (CLxdrawDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CLxdrawView message handlers

void CLxdrawView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	SetCapture();//捕获鼠标
	m_ptPrevP=point;//记录当前鼠标为绘图始点

	CView::OnLButtonDown(nFlags, point);
}

void CLxdrawView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(GetCapture()==this)
		ReleaseCapture();//释放鼠标

	CView::OnLButtonUp(nFlags, point);
}

void CLxdrawView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
if((nFlags & MK_LBUTTON)==MK_LBUTTON)
	{
		if(GetCapture()==this)
		{
			CClientDC dc(this);
			CLxLine* pLine=GetDocument()->AddLine(m_ptPrevP,point);
			pLine->Draw(&dc);
			m_ptPrevP=point;

			//开始添加
			char* pBuf=new char[sizeof(CLxLine)];//pBuf用于存放需要传输的字节流
			memcpy(pBuf,(char*)pLine,sizeof(CLxLine));//强制把线条类转换为字符串格式,以便于传输
	  GetDocument()->m_sConnectSocket.Send((LPCTSTR)(pBuf),sizeof(CLxLine));		//利用文档类的Socket进行传输,Socket的Send函数有两个参数,第一个是所要传输的字符串存放地址,第二个是要传输的字节数。
			//结束添加

		}
	}
	CView::OnMouseMove(nFlags, point);

}

⌨️ 快捷键说明

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