描述:
将Word嵌入到ActiveX中并在IE中调用
如何得到编辑完成的文档数据并发送到服务端
解决方案1:
void CWebOfficeCtrl::SaveDoc(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// TODO: 在此添加调度处理程序代码
m_pWebOfficeFrame->m_pWebOfficeView->m_pSelection->DeactivateUI();
LPDISPATCH lpDisp;
lpDisp=m_pWebOfficeFrame->m_pWebOfficeView->m_pSelection->GetIDispatch();
TCHAR szTempPath[MAX_PATH],szTempFile[MAX_PATH];
DWORD dwResult=::GetTempPath(MAX_PATH,szTempPath);
GetTempFileName(szTempPath,_T("TelStar_"),0,szTempFile);
CString strTempDocPath;
strTempDocPath=szTempFile;
USES_CONVERSION;
WCHAR* wcPathName=T2W(szTempFile);
IStorage* pStorage=NULL;
BOOL bSuccess=FALSE;
if(SUCCEEDED(StgCreateDocfile(wcPathName,STGM_READWRITE|STGM_SHARE_EXCLUSIVE|STGM_CREATE,0,&pStorage)))
{
IPersistStorage* pPersistStorage=NULL;
if(SUCCEEDED(lpDisp->QueryInterface(IID_IPersistStorage,(void**)&pPersistStorage)))
{
if(SUCCEEDED(OleSave(pPersistStorage,pStorage,FALSE)))
{
pPersistStorage->SaveCompleted(NULL);
}
pPersistStorage->Release();
}
pStorage->Release();
}//保存到本地.
CInternetSession m_Session("DigitalTitan");
CHttpConnection* pServer=NULL;
CHttpFile* pFile=NULL;
CString strServerName=m_ServerName;
INTERNET_PORT nPort=(INTERNET_PORT)atoi(m_ServerPort);
CString strURL=m_DesignFile;
try
{
pServer=m_Session.GetHttpConnection(strServerName,nPort);
//AfxMessageBox(strServerName,MB_ICONINFORMATION);
pFile=pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST,strURL,NULL,1,NULL,NULL,INTERNET_FLAG_EXISTING_CONNECT);
//AfxMessageBox(strURL,MB_ICONINFORMATION);
CString strBoundary="-----------------------------7d33a816d302b6";//分界线视CGI程序做响应改动.
pFile->AddRequestHeaders("Content-Type: multipart/form-data, boundary="+strBoundary);
pFile->AddRequestHeaders("Accept: **");
//格式化你的数据到pBuf中吧
if(pFile->SendRequest(NULL,0,(LPVOID)pBuf,strlen(pBuf))==0)
{
AfxMessageBox("网络异常...",MB_ICONINFORMATION);
}
else
{
AfxMessageBox("完成设计...",MB_ICONINFORMATION);
}
pFile->Close();
pServer->Close();
}
catch(CInternetException* e)
{
char strErrorBuf[255];
e->GetErrorMessage(strErrorBuf,255,NULL);
AfxMessageBox(strErrorBuf,MB_ICONINFORMATION);
}
delete pFile;
delete pServer;
m_Session.Close();
}