?? axatlconview.cpp
字號(hào):
// AxAtlConView.cpp : implementation of the CAxAtlConView class
//
#include "stdafx.h"
#include "AxAtlCon.h"
#include "AxAtlConDoc.h"
#include "AxAtlConView.h"
#include "SetNumDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAxAtlConView
IMPLEMENT_DYNCREATE(CAxAtlConView, CView)
BEGIN_MESSAGE_MAP(CAxAtlConView, CView)
//{{AFX_MSG_MAP(CAxAtlConView)
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()
/////////////////////////////////////////////////////////////////////////////
// CAxAtlConView construction/destruction
CAxAtlConView::CAxAtlConView()
{
// TODO: add construction code here
m_bIsDrag=FALSE; // 是否處于拖動(dòng)狀態(tài)
m_pTable=NULL;
if(CoInitialize(NULL)!=S_OK)
return;
HRESULT hr=CoCreateInstance(CLSID_AxTable,NULL,CLSCTX_INPROC_SERVER,
IID_IAxTable,(void **)&m_pTable);
if(SUCCEEDED(hr))
{
m_pTable->put_Top(0);
m_pTable->put_Bottom(0);
m_pTable->put_Left(0);
m_pTable->put_Right(0);
m_pTable->put_RowNum(1);
m_pTable->put_ColNum(1);
}
if(hr==CLASS_E_NOAGGREGATION )
{
m_pTable=NULL;
}
}
CAxAtlConView::~CAxAtlConView()
{
if(m_pTable!=NULL)
m_pTable->Release();
}
BOOL CAxAtlConView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CAxAtlConView drawing
void CAxAtlConView::OnDraw(CDC* pDC)
{
CAxAtlConDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
if(m_pTable!=NULL)
m_pTable->Draw(long(pDC->GetSafeHdc()));
}
/////////////////////////////////////////////////////////////////////////////
// CAxAtlConView printing
BOOL CAxAtlConView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CAxAtlConView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CAxAtlConView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CAxAtlConView diagnostics
#ifdef _DEBUG
void CAxAtlConView::AssertValid() const
{
CView::AssertValid();
}
void CAxAtlConView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CAxAtlConDoc* CAxAtlConView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CAxAtlConDoc)));
return (CAxAtlConDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CAxAtlConView message handlers
void CAxAtlConView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_bIsDrag==FALSE)
{
// 記錄矩形的起點(diǎn)
m_ptRect1=point;
m_ptRect2=point;
m_bIsDrag=TRUE;
}
CView::OnLButtonDown(nFlags, point);
}
void CAxAtlConView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_bIsDrag==TRUE)
{
CClientDC clientDC(this);
OnPrepareDC(&clientDC);
clientDC.DPtoLP(&point);
m_ptRect2=point;
// 對(duì)矩形進(jìn)行正則處理
CRect rect=CRect(m_ptRect1,m_ptRect2);
rect.NormalizeRect();
// 設(shè)置行列數(shù)
CSetNumDlg dlg;
if(dlg.DoModal()==IDOK)
{
// 設(shè)置表格屬性
m_pTable->put_Top(rect.top);
m_pTable->put_Bottom(rect.bottom);
m_pTable->put_Left(rect.left);
m_pTable->put_Right(rect.right);
m_pTable->put_RowNum(dlg.m_nRowNum);
m_pTable->put_ColNum(dlg.m_nColNum);
}
// 擦除拖畫矩形的痕跡
//設(shè)置繪圖模式
int iPrevMode = clientDC.SetROP2(R2_XORPEN);
//設(shè)置畫筆
CPen pen(PS_SOLID, 1, RGB(0,255,0) );
CPen* pOldPen = clientDC.SelectObject(&pen);
CBrush* pOldBrush=(CBrush*)(clientDC.SelectStockObject(NULL_BRUSH));
clientDC.Rectangle(rect);
//恢復(fù)設(shè)置
clientDC.SetROP2(iPrevMode);
clientDC.SelectObject(pOldPen);
clientDC.SelectObject(pOldBrush);
// 刷新屏幕
m_bIsDrag=FALSE;
Invalidate();
}
CView::OnLButtonUp(nFlags, point);
}
void CAxAtlConView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_bIsDrag==TRUE)
{
CClientDC clientDC(this);
OnPrepareDC(&clientDC);
clientDC.DPtoLP(&point);
//設(shè)置繪圖模式
int iPrevMode = clientDC.SetROP2(R2_XORPEN);
//設(shè)置畫筆
CPen pen(PS_SOLID, 1, RGB(0,255,0) );
CPen* pOldPen = clientDC.SelectObject(&pen);
CBrush* pOldBrush=(CBrush*)(clientDC.SelectStockObject(NULL_BRUSH));
// 擦出原先的繪制痕跡
CRect rect=CRect(m_ptRect1,m_ptRect2);
rect.NormalizeRect();
clientDC.Rectangle(rect);
m_ptRect2=point;
// 繪制新的矩形
rect=CRect(m_ptRect1,m_ptRect2);
rect.NormalizeRect();
clientDC.Rectangle(rect);
//恢復(fù)設(shè)置
clientDC.SetROP2(iPrevMode);
clientDC.SelectObject(pOldPen);
clientDC.SelectObject(pOldBrush);
}
CView::OnMouseMove(nFlags, point);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -