#import "office/MSO.DLL" rename("RGB", "msRGB")
#import "office/VBE6EXT.OLB" no_namespace
#import "office/MSWORD.OLB" \
rename("FindText", "msFindText")\
rename("ExitWindows","ExitWindowsEx")
void DumpComError(_com_error &e)
{
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
TCHAR szBuff[1024] = {0};
_stprintf_s(szBuff,
_T("Oops - hit an error!\n")
_T("\a\tCode = %08lx\n")
_T("\a\tCode meaning = %s\n")
_T("\a\tSource = %s\n")
_T("\a\tDescription = %s\n"),
e.Error(),
e.ErrorMessage(),
(LPCTSTR) bstrSource,
(LPCTSTR) bstrDescription );
TRACE(szBuff);
AfxMessageBox(szBuff);
ASSERT(0);
}
void TestWord()
{
using namespace Office;
using namespace Word;
_ApplicationPtr pApp;
_DocumentPtr pDoc;
try
{
do
{
if(OleInitialize(NULL) != S_OK)
break;
if(pApp.CreateInstance(L"Word.Application") != S_OK)
break;
pApp->Visible = true;
pDoc = pApp->GetDocuments()->Add();
Word::LineFormatPtr pLine = pDoc->Shapes->AddLine(100, 100, 100, 200)->Line; //画线
pLine->PutStyle(msoLineSingle); //Selection.ShapeRange.Line.Style = msoLineSingle //单根线
pLine->PutWeight(6); //Selection.ShapeRange.Line.Weight = 6# //6磅
pLine->PutDashStyle(msoLineLongDash); //Selection.ShapeRange.Line.DashStyle = msoLineLongDash //点画线
pLine->ForeColor->PutRGB( RGB(51, 102, 255) ); // Selection.ShapeRange.Line.ForeColor.RGB = RGB(51, 102, 255) //线颜色
//两段箭头
pLine->put_BeginArrowheadStyle(msoArrowheadTriangle); //Selection.ShapeRange.Line.BeginArrowheadStyle = msoArrowheadTriangle
pLine->put_EndArrowheadStyle(msoArrowheadTriangle); // Selection.ShapeRange.Line.EndArrowheadStyle = msoArrowheadTriangle
pLine->put_BeginArrowheadWidth(msoArrowheadWidthMedium); //Selection.ShapeRange.Line.BeginArrowheadWidth = msoArrowheadWidthMedium
pLine->put_BeginArrowheadLength(msoArrowheadLengthMedium); //Selection.ShapeRange.Line.BeginArrowheadLength = msoArrowheadLengthMedium
//可见
pLine->PutVisible(msoTrue); //Selection.ShapeRange.Line.Visible = msoTrue
pDoc->Close();
Sleep(1000);
pApp->Quit();
OleUninitialize();
}while(0);
}
catch(_com_error &e)
{
DumpComError(e);
}
}