debug模式qt使用Cstring引入afxwin.h异常&内存泄漏

#define _AFXDLL
#include “afxwin.h”
把#include "afxwin.h"替换为#include “atlstr.h”

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 MFC 中,可以使用 `CWordDocument` 类以及 `IAutoShape` 接口来操控 Word 文档的页眉。下面是一个简单的示例代码,演示如何使用 MFC 操控 Word 页眉: ```cpp #include <afxwin.h> #include <afxdisp.h> void SetHeader(CWordDocument& doc, const CString& headerText) { // 获取文档的页眉部分 COleVariant headersVar(doc.GetHeaders()); Headers headers(headersVar); // 获取页眉的第一个段落 Paragraphs paragraphs(headers.GetItem(COleVariant((short)1)).GetRange().GetParagraphs()); // 清空页眉内容 paragraphs.SetAlignment(0); // 将段落对齐方式设置为左对齐 paragraphs.SetSpaceBefore(0); // 清空段前间距 paragraphs.SetSpaceAfter(0); // 清空段后间距 paragraphs.SetLineSpacing(1, 12); // 设置行间距为单倍行距,12磅字体大小 // 插入文本到页眉 COleVariant textVar(headerText); paragraphs.GetItem(COleVariant((short)1)).Range().SetText(textVar); } int main() { // 初始化 MFC AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0); // 创建 Word 应用程序实例 CWordApp app; app.CreateDispatch("Word.Application"); // 显示 Word 窗口 app.put_Visible(TRUE); // 创建新文档 Documents documents(app.get_Documents()); COleVariant vtFalse((short)FALSE); _Document doc = documents.Add(vtFalse, vtFalse, vtFalse, vtFalse); // 将文档转换为 CWordDocument 对象 CWordDocument wordDoc; wordDoc.AttachDispatch(doc); // 设置页眉 CString headerText = "这是页眉"; SetHeader(wordDoc, headerText); // 保存文档 wordDoc.SaveAs(COleVariant("C:\\path\\to\\your\\document.docx")); // 关闭 Word 应用程序 app.Quit(); return 0; } ``` 请注意,上述示例代码仅为演示如何使用 MFC 操控 Word 页眉的基本操作。你可以根据实际需求进行更多的操作和控制。如果有任何疑问,请随时提问!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值