_Application app;
app.CreateDispatch(_T("Word.Application"));
app.SetVisible(TRUE);
//通过WORD宏可以知道,由于要使用Documents,于是我们定义一个并从app中取得
Documents docs=app.GetDocuments();
//准备调用Documents::Add函数了,需要定义4个参数。
//从WORD宏可以看出来3个参数的类型为:
//Template字符,NewTemplate布尔,DocumentType数值
//但Add函数还需要一个参数是Visible,傻子也能看出来这个值表示是否显示出新文档
//并且可以给默认值(VT_EMPTY)
CComVariant Template(_T("")); //为了简单,没有使用WORD的文档模板
CComVariant NewTemplate(false),DocumentType(0),Visible;
docs.Add(&Template,&NewTemplate,&DocumentType,&Visible);
//通过WORD宏可以知道,由于要使用Selection,于是我们定义一个并从app中取得
//Selection表示输入点,即光标闪烁的那个地方
Selection sel=app.GetSelection();
//调用函数Selection::TypeText 向WORD发送字符
_Font font(sel.GetFont());
/*页眉页脚*/
Window mWindowActive; //定义活动窗口对象
View mViewActive; //定义活动视图对象
Pane mPane; //定义当前窗格对象
Paragraph para;
Fields fields;
mWindowActive=app.GetActiveWindow(); //获得当前窗口
mPane=mWindowActive.GetActivePane(); //获得当前窗格
mViewActive=mPane.GetView(); //获得当前视图
mViewActive.SetSeekView(9); //设置页眉视图
font.SetSize(15);
font.SetColor(RGB(0,0,0));
sel.TypeText("设置页眉视图,,,,,,,,,,,,,");
para.SetAlignment(1); //居中
sel.TypeParagraph();
font.SetSize(9);
sel.TypeText("设置页眉视图。。。。。。。。。。。");
para.SetAlignment(1); //居中
font.SetSize(7);
mViewActive.SetSeekView(10); //设置页脚视图
sel.TypeText("- ");
fields.Add(sel.GetRange(),COleVariant(short(33)),COleVariant("PAGE "),COleVariant(short(1))); //增加页码域
sel.TypeText(" -");
font.SetSize(6);
font.SetColor(RGB(80,80,80));
para.SetAlignment(1); //居中
sel.TypeText("设置页脚视图");
para.SetAlignment(1); //居中
mViewActive.SetSeekView(0); //回到正文视图