?? sdocdemoview.cpp
字號:
// SDocDemoView.cpp : implementation of the CSDocDemoView class
//
#include "stdafx.h"
#include "SDocDemo.h"
#include "SDocDemoDoc.h"
#include "SDocDemoView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSDocDemoView
IMPLEMENT_DYNCREATE(CSDocDemoView, CScrollView)
BEGIN_MESSAGE_MAP(CSDocDemoView, CScrollView)
//{{AFX_MSG_MAP(CSDocDemoView)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSDocDemoView construction/destruction
CSDocDemoView::CSDocDemoView()
{
// TODO: add construction code here
m_bDraw=false;
m_Hcursor=AfxGetApp()->LoadStandardCursor(IDC_CROSS);//載入十字光標
}
CSDocDemoView::~CSDocDemoView()
{
}
BOOL CSDocDemoView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.lpszClass=AfxRegisterWndClass( CS_VREDRAW | CS_HREDRAW,
::LoadCursor(NULL, IDC_ARROW),(HBRUSH)::GetStockObject(LTGRAY_BRUSH),0);//設置窗口背景為淺灰色
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CSDocDemoView drawing
void CSDocDemoView::OnDraw(CDC* pDC)
{
CSDocDemoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int index;
index=pDoc->GetTotalLine();//獲取線條數目
while(index--)
{
pDoc->GetLine(index)->DrawLine(pDC);//繪制線條
}
}
/////////////////////////////////////////////////////////////////////////////
// CSDocDemoView printing
BOOL CSDocDemoView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CSDocDemoView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CSDocDemoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CSDocDemoView diagnostics
#ifdef _DEBUG
void CSDocDemoView::AssertValid() const
{
CScrollView::AssertValid();
}
void CSDocDemoView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CSDocDemoDoc* CSDocDemoView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSDocDemoDoc)));
return (CSDocDemoDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSDocDemoView message handlers
void CSDocDemoView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
OnPrepareDC(&dc);
dc.DPtoLP(&point);//屏幕坐標轉換為邏輯坐標
SetCursor(m_Hcursor); //使用新光標
m_bDraw=true;//進入繪圖狀態
m_pOld=point;
SetCapture();//捕捉鼠標
CRect rect;
GetClientRect(&rect);//獲取客戶窗口矩形區域
ClientToScreen(&rect);//轉換為屏幕坐標
ClipCursor(rect);//限定鼠標不能移出客戶窗口
CScrollView::OnLButtonDown(nFlags, point);
}
void CSDocDemoView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
OnPrepareDC(&dc);
dc.DPtoLP(&point);//屏幕坐標轉換為邏輯坐標
m_bDraw=false;//取消繪圖狀態
ReleaseCapture();//釋放鼠標捕捉
ClipCursor(NULL);//取消鼠標區域的限制
CScrollView::OnLButtonUp(nFlags, point);
}
void CSDocDemoView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_bDraw)
{
CClientDC dc(this);
OnPrepareDC(&dc);
dc.DPtoLP(&point);//屏幕坐標轉換為邏輯坐標
CSDocDemoDoc *pDoc=GetDocument();//獲取文檔指針
dc.MoveTo(m_pOld);
dc.LineTo(point);
pDoc->AddLine(m_pOld.x,m_pOld.y,point.x,point.y);//存儲線條
m_pOld=point;
}
CScrollView::OnMouseMove(nFlags, point);
}
void CSDocDemoView::OnInitialUpdate()
{
SIZE size={2800,1600};
SetScrollSizes(MM_TEXT,size);//滾動窗口的最大區域
CScrollView::OnInitialUpdate();
}
void CSDocDemoView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
// TODO: Add your specialized code here and/or call the base class
CScrollView::OnPrepareDC(pDC, pInfo);
//設置映射模式
pDC->SetMapMode(MM_ANISOTROPIC);
CSize winSize = CSize(800,600);
pDC->SetWindowExt(winSize); //設定窗口大小
//得到實際設備每邏輯英寸的象素數量
int xLogPixPerInch,yLogPixPerInch;
xLogPixPerInch=pDC->GetDeviceCaps(LOGPIXELSX);
yLogPixPerInch=pDC->GetDeviceCaps(LOGPIXELSY);
//得到設備坐標和邏輯坐標的比例
int xExt,yExt;
xExt=winSize.cx*xLogPixPerInch/96;
yExt=winSize.cy*yLogPixPerInch/96;
//設定視口大小
pDC->SetViewportExt(xExt,yExt);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -