Step3Dlg.cpp
上传用户:tjyzx0508
上传日期:2013-02-16
资源大小:254k
文件大小:4k
- // Step3Dlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "Step3.h"
- #include "Step3Dlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CStep3Dlg dialog
- CStep3Dlg::CStep3Dlg(CWnd* pParent /*=NULL*/)
- : CDialog(CStep3Dlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CStep3Dlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CStep3Dlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CStep3Dlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CStep3Dlg, CDialog)
- //{{AFX_MSG_MAP(CStep3Dlg)
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CStep3Dlg message handlers
- BOOL CStep3Dlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
-
- // TODO: Add extra initialization here
-
- return TRUE; // return TRUE unless you set the focus to a control
- }
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
- void CStep3Dlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CStep3Dlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- #include "msword9.h"
- #include <AtlBase.h>
- void CStep3Dlg::OnOK()
- {
- ////////////// 这次,我们要控制在WORD中输入一些字符了 /////////////////////
- /************* WORD 录制的宏,新建一个空文档,然后输入一些文字 ************
- Documents.Add Template:= _
- "C:Documents and SettingsAdministratorApplication DataMicrosoftTemplatesNormal.dot" _
- , NewTemplate:=False, DocumentType:=0
- Selection.TypeText Text:="HELLO"
- Selection.TypeParagraph
- Selection.TypeText Text:="大家好"
- ***************************************************************************/
- _Application app;
- app.CreateDispatch(_T("Word.Application"));
- app.SetVisible(TRUE);
- AfxMessageBox(_T("看好了,就要新建一个空白文档了"));
- //通过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);
- AfxMessageBox(_T("下面,程序要向WORD发送字符啦"));
- //通过WORD宏可以知道,由于要使用Selection,于是我们定义一个并从app中取得
- //Selection表示输入点,即光标闪烁的那个地方
- Selection sel=app.GetSelection();
- //调用函数Selection::TypeText 向WORD发送字符
- sel.TypeText(_T("HELLOrn大家好呀"));
- AfxMessageBox(_T("看见了吗?我要退出啦"));
- sel.ReleaseDispatch(); //Selection 不用了,一定要释放
- docs.ReleaseDispatch(); //Documents 也不用了
- CComVariant SaveChanges(false),OriginalFormat,RouteDocument;
- app.Quit(&SaveChanges,&OriginalFormat,&RouteDocument);
- app.ReleaseDispatch();
- AfxMessageBox(_T("下面该学习Setp4了"));
- }