?? zhanglu15view.cpp
字號:
// zhanglu15View.cpp : implementation of the CZhanglu15View class
//
#include "stdafx.h"
#include "zhanglu15.h"
#include "zhanglu15Doc.h"
#include "zhanglu15View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CZhanglu15View
IMPLEMENT_DYNCREATE(CZhanglu15View, CView)
BEGIN_MESSAGE_MAP(CZhanglu15View, CView)
//{{AFX_MSG_MAP(CZhanglu15View)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_CREATE()
ON_WM_CHAR()
ON_WM_TIMER()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CZhanglu15View construction/destruction
CZhanglu15View::CZhanglu15View()
{
// TODO: add construction code here
m_strLine="";
m_ptOrigin=0;
m_bDragging=false; // 初始化拖拽標記
// 獲得十字光標句柄
m_hCross=AfxGetApp()->
LoadStandardCursor(IDC_CROSS);
}
CZhanglu15View::~CZhanglu15View()
{
}
BOOL CZhanglu15View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CZhanglu15View drawing
void CZhanglu15View::OnDraw(CDC* pDC)
{
CZhanglu15Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int nIndex=pDoc->GetNumLines(); // 取得線段的數量
// 循環畫出每一段線段
while(nIndex--) // 數組下標從0到nIndex-1
{
pDoc->GetLine(nIndex)->DrawLine(pDC);
// 類CLine的成員函數
}
}
/////////////////////////////////////////////////////////////////////////////
// CZhanglu15View printing
BOOL CZhanglu15View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CZhanglu15View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CZhanglu15View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CZhanglu15View diagnostics
#ifdef _DEBUG
void CZhanglu15View::AssertValid() const
{
CView::AssertValid();
}
void CZhanglu15View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CZhanglu15Doc* CZhanglu15View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CZhanglu15Doc)));
return (CZhanglu15Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CZhanglu15View message handlers
void CZhanglu15View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
SetCaretPos(point);
m_strLine.Empty();
m_ptOrigin=point;
SetCapture(); // 捕捉鼠標
::SetCursor(m_hCross); // 設置十字光標
m_ptOrigin=point;
m_bDragging=TRUE; // 設置拖拽標記
CView::OnLButtonDown(nFlags, point);
}
void CZhanglu15View::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_bDragging)
{
m_bDragging=false; // 清拖拽標記
ReleaseCapture(); // 釋放鼠標,還原鼠標形狀
}
// CView::OnLButtonUp(nFlags, point);
}
void CZhanglu15View::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_bDragging)
{ CZhanglu15Doc *pDoc=GetDocument(); //獲得文檔對象指針
ASSERT_VALID(pDoc); //測試文檔對象是否運行有效
pDoc->AddLine(m_ptOrigin, point); //加入線段到指針數組
CClientDC dc(this);
dc.MoveTo(m_ptOrigin);
dc.LineTo(point); // 繪制線段
m_ptOrigin=point; // 新的起始點
}
CStatusBar*pFrame=(CStatusBar*)AfxGetMainWnd();
CStatusBar*pStatusBar=(CStatusBar*)pFrame->GetDescendantWindow(AFX_IDW_STATUS_BAR);
CString strMousePoint;
strMousePoint.Format("%3d,%3d",point.x,point.y);
pStatusBar->SetPaneText(pStatusBar->CommandToIndex(IDS_INDICATOR_MOUSE),strMousePoint);
CView::OnMouseMove(nFlags, point);
}
int CZhanglu15View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
CClientDC dc(this);//創建設備描述表
TEXTMETRIC tm;//定義文本信息結構體變量
dc.GetTextMetrics(&tm);//獲得設備描述表中文本信息
CreateSolidCaret(tm.tmAveCharWidth/8,tm.tmHeight);
//根據字體大小,創建合適的插入符
ShowCaret();//顯示顯示符
return 0;
}
void CZhanglu15View::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
TEXTMETRIC tm;
dc.GetTextMetrics(&tm);
if(0x0d==nChar)
{
m_strLine.Empty();
m_ptOrigin.y+=tm.tmHeight;
}
else if(0x08==nChar)
{
COLORREF clr=dc.SetTextColor(dc.GetBkColor());
dc.TextOut(m_ptOrigin.x,m_ptOrigin.y,m_strLine);
m_strLine=m_strLine.Left(m_strLine.GetLength()-1);
dc.SetTextColor(clr);
}
else
{
m_strLine+=nChar;
}
CSize sz=dc.GetTextExtent(m_strLine);
CPoint pt;
pt.x=m_ptOrigin.x+sz.cx;
pt.y=m_ptOrigin.y;
SetCaretPos(pt);
dc.TextOut(m_ptOrigin.x,m_ptOrigin.y,m_strLine);
CView::OnChar(nChar, nRepCnt, nFlags);
}
//DEL void CZhanglu15View::OnIdcColor()
//DEL {
//DEL // TODO: Add your command handler code here
//DEL pDC->SetTextColor(RGB(255,0,0));//字體顏色
//DEL
//DEL }
void CZhanglu15View::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CView::OnTimer(nIDEvent);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -