MSWord.h 2 KB
#pragma once

class CMSWord
{
protected:
	IDispatch*	m_pWApp;
	IDispatch*  m_pDocuments;
	IDispatch*	m_pActiveDocument;
	HRESULT		m_hr;
public:
	CMSWord();
	~CMSWord();
	HRESULT Initialize(bool bVisible=true);
	HRESULT SetVisible(bool bVisible=true);
	HRESULT Quit();
	HRESULT OpenDocument(LPCTSTR szFilename, bool bVisible=true);
	HRESULT NewDocument(bool bVisible=true);
	HRESULT CloseActiveDocument(bool bSave=true);
	HRESULT CloseDocuments(bool bSave=true);
	HRESULT SetSelectionText(LPCTSTR szText);
	HRESULT GetSelectionText(LPCTSTR& strText);
	HRESULT InserPicture(LPCTSTR szFilename, int iWidth, int iHeight);
	HRESULT AddComment(LPCTSTR szComment);
	HRESULT MoveCursor(int nDirection=2,bool bSelection=false);
	HRESULT DeleteChar(bool bBack=false);
	HRESULT CheckSpelling(LPCTSTR szWord, bool &bResult);
	HRESULT CheckGrammer(LPCTSTR szString, bool &bResult);
	HRESULT SetFont(LPCTSTR szFontName, int nSize, bool bBold, bool bItalic,COLORREF crColor);
	HRESULT SaveAs(LPCTSTR fileName);

	////word2003
	//void SaveAs(VARIANT* FileName, VARIANT* FileFormat, VARIANT* LockComments, VARIANT* Password, VARIANT* AddToRecentFiles, VARIANT* WritePassword, VARIANT* ReadOnlyRecommended, VARIANT* EmbedTrueTypeFonts, VARIANT* SaveNativePictureFormat,
	//	VARIANT* SaveFormsData, VARIANT* SaveAsAOCELetter, VARIANT* Encoding, VARIANT* InsertLineBreaks, VARIANT* AllowSubstitutions, VARIANT* LineEnding, VARIANT* AddBiDiMarks);
	////word2000
	//void SaveAs(VARIANT* FileName, VARIANT* FileFormat, VARIANT* LockComments, VARIANT* Password, VARIANT* AddToRecentFiles, VARIANT* WritePassword, VARIANT* ReadOnlyRecommended, VARIANT* EmbedTrueTypeFonts, VARIANT* SaveNativePictureFormat,
	//	VARIANT* SaveFormsData, VARIANT* SaveAsAOCELetter);

	//ActiveDocument.SaveAs FileName := "Hello.doc", FileFormat := wdFormatDocument, LockComments := False, Password := "", AddToRecentFiles := True, WritePassword := "", ReadOnlyRecommended := False, EmbedTrueTypeFonts := False, SaveNativePictureFormat := False, SaveFormsData := False, SaveAsAOCELetter := False
};