Step2Dlg.cpp
上传用户:tjyzx0508
上传日期:2013-02-16
资源大小:254k
文件大小:3k
- // Step2Dlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "Step2.h"
- #include "Step2Dlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CStep2Dlg dialog
- CStep2Dlg::CStep2Dlg(CWnd* pParent /*=NULL*/)
- : CDialog(CStep2Dlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CStep2Dlg)
- // 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 CStep2Dlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CStep2Dlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CStep2Dlg, CDialog)
- //{{AFX_MSG_MAP(CStep2Dlg)
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CStep2Dlg message handlers
- BOOL CStep2Dlg::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 CStep2Dlg::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 CStep2Dlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- #include "msword9.h"
- #include <AtlBase.h> //新增加了一个头文件,为使用CComVariant替代VARIANT做准备
- void CStep2Dlg::OnOK()
- {
- //以下3行代码,同Step1。就不解释啦
- _Application app;
- //为了简单,没有判断返回值。如果没有成功,记得检查你有没有AfxOleInit()呀?
- app.CreateDispatch(_T("Word.Application"));
- app.SetVisible(TRUE);
- AfxMessageBox(_T("WORD已经启动,现在要退出啦"));
- AfxMessageBox(_T("怎么和Step1没有什么区别呀?"));
- AfxMessageBox(_T("嘿嘿,是没什么区别,但是使用方式简单了很多呀。看看源程序吧"));
- //准备调用_Application::Quit函数了,需要定义3个参数。
- //但是,这次我们使用CComVariant,这是一个模板类。
- //在定义的时候直接调用带参数的构造函数,比VARIANT使用简单多了吧
- CComVariant SaveChanges(false),OriginalFormat,RouteDocument;
- //使用 CComVariant 的不带参数的构造函数,默认就是使用VT_EMPTY,设置为空类型
- //另外,除了CComVariant,你还可以使用COleVariant和_variant_t,但我个人最喜欢前者
- app.Quit(&SaveChanges,&OriginalFormat,&RouteDocument);
- app.ReleaseDispatch();
- AfxMessageBox(_T("下面该学习Setp3了"));
- }