📄 wordtestfirstdlg.cpp
字号:
// WordTestFirstDlg.cpp : implementation file
//
#include "stdafx.h"
#include "WordTestFirst.h"
#include "WordTestFirstDlg.h"
#include "WzjOffice.h"
//#include "msword.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWordTestFirstDlg dialog
CWordTestFirstDlg::CWordTestFirstDlg(CWnd* pParent /*=NULL*/)
: CDialog(CWordTestFirstDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CWordTestFirstDlg)
// 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 CWordTestFirstDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CWordTestFirstDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CWordTestFirstDlg, CDialog)
//{{AFX_MSG_MAP(CWordTestFirstDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWordTestFirstDlg message handlers
BOOL CWordTestFirstDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 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
}
void CWordTestFirstDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 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 CWordTestFirstDlg::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 CWordTestFirstDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CWordTestFirstDlg::OnOK()
{
CWzjWordOffice wd; //定义一个操作word的对象
wd.Create(); //创建一个word应用程序增加一个文档
// wd.SetLineSpace(1);//设置行间距
// wd.SetPage();//页面设置
wd.SetTitle(-2);//设置成标题
wd.SetFont("宋体",25,RGB(128, 0, 0)); //设置字体(字号,字体名,颜色)
wd.SetFont(1,0,0); //设置字体 (粗体, 斜体, 划线)
wd.SetParaphformat(1); //设置文字为居中对齐
wd.WriteText("测试标题"); //写文字
wd.m_wdSel.TypeParagraph(); //回车换行
wd.SetTitle(-3);//设置成标题
wd.SetFont("黑体",15,RGB(0, 0, 0)); //设置字体(字号,字体名,颜色)
wd.SetFont(1,1,1); //设置字体为粗体,不是斜体,没有下划线
wd.SetParaphformat(0); //设置文字为居中对齐
wd.WriteText("测试正文"); //写文字
wd.m_wdSel.TypeParagraph(); //回车换行
wd.SetFont("魏碑",15,RGB(0, 0, 0)); //设置字体(字号,字体名,颜色)
wd.SetFont(1,1,1); //设置字体
wd.SetParaphformat(0); //设置文字为居左对齐
wd.WriteText("测试正文"); //写文字
wd.m_wdSel.TypeParagraph(); //回车换行
wd.AddPic("d:\\1.bmp");
//设置表格字体
wd.SetFont("宋体",9);
wd.SetFont(0,0,0);
wd.CreateTable(2,4); //创建一个2行4列的表格
wd.WriteCellText(1,1,"学号"); //往1行1列单元写“学号”
wd.WriteCellText(1,2,"姓名"); //往1行2列单元写“姓名”
wd.WriteCellText(1,3,"年龄"); //...
wd.WriteCellText(1,4,"省份");
wd.WriteCellText(2,1,"23020723");
wd.WriteCellText(2,2,"汪自军");
wd.WriteCellText(2,3,"25");
wd.WriteCellText(2,4,"湖北");
wd.SetLineSpace(1);//设置行间距
wd.ShowApp(); //显示word
//wd.SaveAs("c:\\word.doc");//保存
//wd.Close();
}
void CWordTestFirstDlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -