Step1Dlg.cpp
上传用户:tjyzx0508
上传日期:2013-02-16
资源大小:254k
文件大小:3k
- // Step1Dlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "Step1.h"
- #include "Step1Dlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CStep1Dlg dialog
- CStep1Dlg::CStep1Dlg(CWnd* pParent /*=NULL*/)
- : CDialog(CStep1Dlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CStep1Dlg)
- // 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 CStep1Dlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CStep1Dlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CStep1Dlg, CDialog)
- //{{AFX_MSG_MAP(CStep1Dlg)
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CStep1Dlg message handlers
- BOOL CStep1Dlg::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 CStep1Dlg::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 CStep1Dlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- #include "msword9.h" //为了使代码集中,方便阅读,所以把头文件放到了这里
- void CStep1Dlg::OnOK()
- {
- _Application app; //定义一个WORD的应用对象
- if(!app.CreateDispatch(_T("Word.Application"))) //启动WORD
- {
- AfxMessageBox(_T("居然你连OFFICE都没有安装吗?"));
- return;
- }
- AfxMessageBox(_T("WORD 已经运行启动啦,你可以用Ctrl+Alt+Del查看"));
- app.SetVisible(TRUE); //设置WORD可见。
- //当然,如果你想要悄悄地调用WORD的功能,则注释掉这条语句
- AfxMessageBox(_T("现在你已经看到WORD的程序界面了吧"));
- AfxMessageBox(_T("WORD准备要退出啦"));
- VARIANT SaveChanges,OriginalFormat,RouteDocument; //定义调用QUIT时使用的参数
- SaveChanges.vt=VT_BOOL; //设置退出WORD时候的保存参数
- SaveChanges.boolVal=VARIANT_FALSE; //为不保存任何文档,模板及设置
- ::VariantInit(&OriginalFormat); //清空变量
- RouteDocument.vt=VT_EMPTY; //清空变量的另一种方法
- //调用Quit退出WORD应用程序。当然不调用也可以,那样的话WORD还在运行着那
- app.Quit(&SaveChanges,&OriginalFormat,&RouteDocument);
- app.ReleaseDispatch(); //释放对象指针。切记,必须调用
- AfxMessageBox(_T("Step1执行完成。接着请学习Setp2"));
- }