都是抄网上的,open这里就停止了,弹出一个对话框来,如图
void CMyDialog::OnBnClickedButton1()
{
CApplication objWordApp; //word对象
COleVariant ovTrue((short)TRUE); //true
COleVariant ovFalse((short)FALSE); //false
COleVariant ovOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
//创建一个IDispatch指针
if (!objWordApp.CreateDispatch("Word.Application"))
{
AfxMessageBox("Couldn't get Word object.");
return;
}
objWordApp.put_Visible(FALSE); //显示应用程序
CDocuments docs(objWordApp.get_Documents()); //word文档
CDocument0 docPrint; //word文档
COleVariant FileName(LPCTSTR(_T("my.doc")));
//到这个函数就 弹出一个对话框来,下面我会贴一个截图, 看截图就懂了
docPrint=docs.Open(&FileName, &ovOptional,
&ovOptional, &ovOptional,
&ovOptional,&ovOptional,
&ovOptional, &ovOptional,
&ovOptional,&ovOptional,
&ovOptional, &ovOptional,
&ovOptional, &ovOptional,
&ovOptional, &ovOptional);
//docPrint=objWordApp.get_ActiveDocument();
CSelection sel=objWordApp.get_Selection();
COleVariant What((long)1);
COleVariant Which((long)2);
COleVariant Count((long)1);
COleVariant Name((long)2);
sel.GoTo(What, Which, Count, Name); //第2页
sel.Copy(); //copy the page to clipboard
HANDLE hEmf = ::GetClipboardData(CF_ENHMETAFILE);
char szEmfFile[MAX_PATH];
memset(szEmfFile,0,MAX_PATH);
strcpy(szEmfFile,"1.bmp");
if (hEmf)
{
memset(szEmfFile,0,MAX_PATH);
strcpy(szEmfFile,"my.emf");
HENHMETAFILE h = CopyEnhMetaFile((HENHMETAFILE)hEmf, szEmfFile);
if (h > 0)
{
DeleteEnhMetaFile(h);
EmfToBmp(szEmfFile, "1.jpg"); //将emf文件转换为图片文件
::DeleteFile(szEmfFile);
}
}
CloseClipboard();
objWordApp.Quit(
ovFalse, // 保存修改
ovTrue, // 原始格式
ovFalse // RouteDocument.
);
docPrint.ReleaseDispatch();
docs.ReleaseDispatch();
objWordApp.ReleaseDispatch();
}
代码赋值网上的, 运行到open哪里就这样了,
下面的代码都没有运行
open哪里就弹出一个对话框来。
运行前,已经将机子的office都关闭了,进程也关闭了
4 个解决方案
#1
void CMyDialog::OnBnClickedButton1()
{
CApplication objWordApp; //word对象
COleVariant ovTrue((short)TRUE); //true
COleVariant ovFalse((short)FALSE); //false
COleVariant ovOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
//创建一个IDispatch指针
if (!objWordApp.CreateDispatch("Word.Application"))
{
AfxMessageBox("Couldn't get Word object.");
return;
}
objWordApp.put_Visible(FALSE); //显示应用程序
objWordApp.put_DisplayAlerts(FALSE);
CDocuments docs(objWordApp.get_Documents()); //word文档
CDocument0 docPrint; //word文档
COleVariant FileName(LPCTSTR(_T("f:\\1.doc")));
WdOpenFormat tempFormat;
改成这个了,还是会出现 哪个截图
#2
如果用 OleInitialize and OleUninitialize 替代 AfxOleInit就不会出现这个对话框了。
问题是:
docPrint=docs.Open(&FileName, &ovOptional,
&ovOptional, &ovOptional,
&ovOptional,&ovOptional,
&ovOptional, &ovOptional,
&ovOptional,&ovOptional,
&ovOptional, &ovOptional, //
&ovOptional, &ovOptional,
&ovOptional, &ovOptional);
open的时候半天不返回
问题是:
docPrint=docs.Open(&FileName, &ovOptional,
&ovOptional, &ovOptional,
&ovOptional,&ovOptional,
&ovOptional, &ovOptional,
&ovOptional,&ovOptional,
&ovOptional, &ovOptional, //
&ovOptional, &ovOptional,
&ovOptional, &ovOptional);
open的时候半天不返回
#3
你重启下机器看看还有这个问题嘛?这个主要是office的问题。
另外网上说的这个方法,你看看可以不?(没测试)
#include <afxole.h>
AfxOleGetMessageFilter()->EnableBusyDialog(FALSE);
AfxOleGetMessageFilter()->SetBusyReply(SERVERCALL_RETRYLATER);
AfxOleGetMessageFilter()->EnableNotRespondingDialog(TRUE);
AfxOleGetMessageFilter()->SetMessagePendingDelay(-1);
另外网上说的这个方法,你看看可以不?(没测试)
#include <afxole.h>
AfxOleGetMessageFilter()->EnableBusyDialog(FALSE);
AfxOleGetMessageFilter()->SetBusyReply(SERVERCALL_RETRYLATER);
AfxOleGetMessageFilter()->EnableNotRespondingDialog(TRUE);
AfxOleGetMessageFilter()->SetMessagePendingDelay(-1);
#4
2楼
啊
#1
void CMyDialog::OnBnClickedButton1()
{
CApplication objWordApp; //word对象
COleVariant ovTrue((short)TRUE); //true
COleVariant ovFalse((short)FALSE); //false
COleVariant ovOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
//创建一个IDispatch指针
if (!objWordApp.CreateDispatch("Word.Application"))
{
AfxMessageBox("Couldn't get Word object.");
return;
}
objWordApp.put_Visible(FALSE); //显示应用程序
objWordApp.put_DisplayAlerts(FALSE);
CDocuments docs(objWordApp.get_Documents()); //word文档
CDocument0 docPrint; //word文档
COleVariant FileName(LPCTSTR(_T("f:\\1.doc")));
WdOpenFormat tempFormat;
改成这个了,还是会出现 哪个截图
#2
如果用 OleInitialize and OleUninitialize 替代 AfxOleInit就不会出现这个对话框了。
问题是:
docPrint=docs.Open(&FileName, &ovOptional,
&ovOptional, &ovOptional,
&ovOptional,&ovOptional,
&ovOptional, &ovOptional,
&ovOptional,&ovOptional,
&ovOptional, &ovOptional, //
&ovOptional, &ovOptional,
&ovOptional, &ovOptional);
open的时候半天不返回
问题是:
docPrint=docs.Open(&FileName, &ovOptional,
&ovOptional, &ovOptional,
&ovOptional,&ovOptional,
&ovOptional, &ovOptional,
&ovOptional,&ovOptional,
&ovOptional, &ovOptional, //
&ovOptional, &ovOptional,
&ovOptional, &ovOptional);
open的时候半天不返回
#3
你重启下机器看看还有这个问题嘛?这个主要是office的问题。
另外网上说的这个方法,你看看可以不?(没测试)
#include <afxole.h>
AfxOleGetMessageFilter()->EnableBusyDialog(FALSE);
AfxOleGetMessageFilter()->SetBusyReply(SERVERCALL_RETRYLATER);
AfxOleGetMessageFilter()->EnableNotRespondingDialog(TRUE);
AfxOleGetMessageFilter()->SetMessagePendingDelay(-1);
另外网上说的这个方法,你看看可以不?(没测试)
#include <afxole.h>
AfxOleGetMessageFilter()->EnableBusyDialog(FALSE);
AfxOleGetMessageFilter()->SetBusyReply(SERVERCALL_RETRYLATER);
AfxOleGetMessageFilter()->EnableNotRespondingDialog(TRUE);
AfxOleGetMessageFilter()->SetMessagePendingDelay(-1);
#4
2楼
啊