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

📄 axatlconview.cpp

📁 vc++ acticex原代码
💻 CPP
字号:
// 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;	//	是否处于拖动状态
	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)
	{
		//	记录矩形的起点
		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;

		//	对矩形进行正则处理
		CRect rect=CRect(m_ptRect1,m_ptRect2);
		rect.NormalizeRect();

		//	设置行列数
		CSetNumDlg dlg;	
		if(dlg.DoModal()==IDOK)
		{
			//	设置表格属性
			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);
		}

		//	擦除拖画矩形的痕迹
		//设置绘图模式
		int iPrevMode = clientDC.SetROP2(R2_XORPEN);
		//设置画笔
		CPen pen(PS_SOLID, 1, RGB(0,255,0) );
		CPen* pOldPen = clientDC.SelectObject(&pen);
		CBrush* pOldBrush=(CBrush*)(clientDC.SelectStockObject(NULL_BRUSH)); 

		clientDC.Rectangle(rect);

		//恢复设置
		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);

		//设置绘图模式
		int iPrevMode = clientDC.SetROP2(R2_XORPEN);
		//设置画笔
		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);
		//恢复设置
		clientDC.SetROP2(iPrevMode);
		clientDC.SelectObject(pOldPen);
		clientDC.SelectObject(pOldBrush);
	}

	CView::OnMouseMove(nFlags, point);
}

⌨️ 快捷键说明

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