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

📄 wordview.cpp

📁 word编程
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// wordView.cpp : implementation of the CWordView class
//

#include "stdafx.h"
#include "word.h"

#include "wordDoc.h"
#include "wordView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CWordView

IMPLEMENT_DYNCREATE(CWordView, CView)

BEGIN_MESSAGE_MAP(CWordView, CView)
//{{AFX_MSG_MAP(CWordView)
ON_COMMAND(IDM_WORD, OnWord)
	ON_COMMAND(IDM_POINT, OnPoint)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CWordView construction/destruction

CWordView::CWordView()
{
	// TODO: add construction code here
	
}

CWordView::~CWordView()
{
}

BOOL CWordView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
	
	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CWordView drawing

void CWordView::OnDraw(CDC* pDC)
{
	CWordDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CWordView printing

BOOL CWordView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CWordView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CWordView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CWordView diagnostics

#ifdef _DEBUG
void CWordView::AssertValid() const
{
	CView::AssertValid();
}

void CWordView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CWordDoc* CWordView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CWordDoc)));
	return (CWordDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CWordView message handlers

#include "msword.h"
#include "msword9.h"
#include <AtlBase.h>

void CWordView::OnWord() 
{
	// TODO: Add your command handler code here
	
	BeginWaitCursor();

	COleVariant vTrue((short)TRUE), vFalse((short)FALSE),vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
	
	_Application m_App;
	_AApplication m_App9;
	Documents m_Docs;
	DDocuments m_Docs9;
	Selection m_Sel;
	SSelection m_Sel9;
	
	BOOL Vertion2000=TRUE;
	BOOL Vertion2003=FALSE;	
	
	// 输出路径
	COleVariant varFilePath("C:\\3.doc");

	COleVariant varstrNull("");
	COleVariant varZero((short)0);
	COleVariant covTrue((short)TRUE),covFalse((short)FALSE);
	COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
	
	if(!m_App9.CreateDispatch("Word.Application.9",NULL))
	{ 
		//MessageBox("创建Word2000服务失败"); 
		Vertion2000=FALSE;
		Vertion2003=TRUE;
	}

	if((!m_App.CreateDispatch("Word.Application", NULL))&&(!Vertion2000))
	{
		//AfxMessageBox("创建Word2003失败"); 
		Vertion2003=FALSE;
	}	
	
	if((!Vertion2003)&&(!Vertion2000))
	{			
		MessageBox("创建Word失败"); 
	}	
	
	//AfxMessageBox("创建Word2000!");
	if(Vertion2000)
	{ 	
		m_App9.SetVisible(TRUE);
		m_Docs9.AttachDispatch(m_App9.GetDocuments());
		m_Docs9.Open(varFilePath,covFalse,covFalse,covFalse,
			varstrNull,varstrNull,covFalse,varstrNull,
			varstrNull,varZero,covOptional,covTrue);
		m_Sel9.AttachDispatch(m_App9.GetSelection());
		
		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)2),COleVariant((short)0));
		m_Sel9.TypeText("a1");

		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a2");

		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a3");

		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveLeft(COleVariant((short)1),COleVariant((short)4),COleVariant((short)0));
		m_Sel9.TypeText("a4");

		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a5");

		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a6");

		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a7");

		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a8");
		
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a9");

		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a10");

		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a11");

		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a12");

		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a13");

		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a14");

		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a15");

		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a16");

		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a17");

		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a18");

		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a19");

		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a20");

		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a21");

		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a22");

		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a23");

		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a24");

		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a25");

		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a26");

		m_Sel9.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a27");

		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a28");

		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a29");

		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a30");

		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a31");

		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel9.TypeText("a32");	

	}
	
	//AfxMessageBox("创建Word2003!");	
	if(Vertion2003)
	{	
		
		m_App.SetVisible(FALSE);
		m_Docs.AttachDispatch(m_App.GetDocuments());
		m_Docs.Open(varFilePath,covFalse,covFalse,covFalse,
			varstrNull,varstrNull,covFalse,varstrNull,
			varstrNull,varZero,covOptional,covTrue,
			covOptional, // OpenConflictDocument
			covOptional, // OpenAndRepair
			covFalse,     // DocumentDirection wdDocumentDirection LeftToRight
			varstrNull);  // NoEncodingDialo
		m_Sel.AttachDispatch(m_App.GetSelection());		
		
		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)2),COleVariant((short)0));
		m_Sel.TypeText("a1");

		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a2");

		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a3");

		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveLeft(COleVariant((short)1),COleVariant((short)4),COleVariant((short)0));
		m_Sel.TypeText("a4");

		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a5");

		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a6");

		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a7");

		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a8");
		
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a9");

		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a10");

		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a11");

		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a12");

		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a13");

		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.MoveRight(COleVariant((short)12),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a14");

		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a15");

		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a16");

		m_Sel.MoveDown(COleVariant((short)5),COleVariant((short)1),COleVariant((short)0));
		m_Sel.TypeText("a17");

⌨️ 快捷键说明

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