?? lxdrawview.cpp
字號(hào):
// 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();//捕獲鼠標(biāo)
m_ptPrevP=point;//記錄當(dāng)前鼠標(biāo)為繪圖始點(diǎn)
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();//釋放鼠標(biāo)
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;
//開(kāi)始添加
char* pBuf=new char[sizeof(CLxLine)];//pBuf用于存放需要傳輸?shù)淖止?jié)流
memcpy(pBuf,(char*)pLine,sizeof(CLxLine));//強(qiáng)制把線條類轉(zhuǎn)換為字符串格式,以便于傳輸
GetDocument()->m_sConnectSocket.Send((LPCTSTR)(pBuf),sizeof(CLxLine)); //利用文檔類的Socket進(jìn)行傳輸,Socket的Send函數(shù)有兩個(gè)參數(shù),第一個(gè)是所要傳輸?shù)淖址娣诺刂?,第二個(gè)是要傳輸?shù)淖止?jié)數(shù)。
//結(jié)束添加
}
}
CView::OnMouseMove(nFlags, point);
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -