docin转swf(vc源码)修正,更新下载!

来源:互联网 发布:linux qt多进程 编辑:程序博客网 时间:2024/03/28 16:30

(已修改,成功,下载已更新)

从docin转换为swf文件

由于docin文件有2种格式,特制作2个版本。

 

 

 

 

http://download.csdn.net/source/2492344

 

 

 

 

版本一(已修改,成功,下载更新)

#include "zlib.h"
#pragma comment(lib,"zlib.lib")

void CDocinDlg::OnButton2()
{
 // TODO: Add your control notification handler code here

 CFile mFile("c://docin_1512171.docin",CFile::modeRead);
 
 int pageWidth,pageHeight,totalPages,headerLength;
 if(mFile.GetLength()<2) return;

 mFile.SeekToBegin();
 mFile.Read(&pageWidth,4);
 mFile.Read(&pageHeight,4);
 mFile.Read(&totalPages,4);
 mFile.Read(&headerLength,4);
 
 BYTE *com=new BYTE[headerLength];
 mFile.Read(com,headerLength);

 unsigned long headerUncompressLength;
 BYTE *headerArray=new BYTE[headerLength*10];
 uncompress(headerArray,&headerUncompressLength,com,headerLength);

 for(int i=0;i<totalPages&&i<50;i++)
 {
  int bodyLen=0;
  mFile.Read(&bodyLen,4);
  
  BYTE *bodytmp=new BYTE[bodyLen];
  mFile.Read(bodytmp,bodyLen);
  unsigned long bodyUncompressLen=bodyLen*10;
  BYTE *bodyArrary=new BYTE[bodyUncompressLen];
  uncompress(bodyArrary,&bodyUncompressLen,bodytmp,bodyLen);

  int lengh=0;
  CString ss;

  lengh=headerUncompressLength+bodyUncompressLen+8;
  ss.Format("%d",lengh);
 // AfxMessageBox(ss);
  /*
  BYTE littleHeaderArray[]={70,87,83,9,0,0,0,0};
  littleHeaderArray[4]=lengh%256;
  littleHeaderArray[5]=lengh/256%256;
  littleHeaderArray[6]=lengh/256/256%256;
  littleHeaderArray[7]=lengh/256/256/256;
  */
  
  int littleHeaderArray[]={156456774,lengh};
  
  CString swfname;
  swfname.Format("c://%d_%d.swf",totalPages,i+1);
  CFile mFile2(swfname, CFile::modeWrite|CFile::modeCreate);
  mFile2.Write(littleHeaderArray,8);
  mFile2.Write(headerArray,headerUncompressLength);
  mFile2.Write(bodyArrary,bodyUncompressLen);
  mFile2.Flush();
  mFile2.Close();

 }


// 
// 
// 

mFile.Close();
AfxMessageBox("转换完成");

//mFile2.Write(hchar,q-1);
 
}

 

 

 

版本二

void CDocin2Dlg::OnBUTTONin()
{
 // TODO: Add your control notification handler code here
 CString filter="输入文件(.docin)|*.docin||";
 CFileDialog mydialog(TRUE,0,0, OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY, filter);
 if(mydialog.DoModal()==IDOK)
 {
  m_infile=mydialog.GetPathName();
  UpdateData(FALSE); 
 }
}
void CDocin2Dlg::OnBUTTONout()
{
 // TODO: Add your control notification handler code here
 BROWSEINFO   bf;  
    LPITEMIDLIST   lpitem;  
 memset(&bf,0,sizeof   BROWSEINFO);
 bf.lpszTitle="选择保存swf文件的文件夹";
 bf.ulFlags = BIF_STATUSTEXT|0x0040 |BIF_RETURNONLYFSDIRS|BIF_EDITBOX;//| BIF_BROWSEINCLUDEFILES;
    lpitem=SHBrowseForFolder(&bf);  
 char pBuffer[MAX_PATH];
    SHGetPathFromIDList(lpitem,pBuffer);
 m_outfile=pBuffer;
 UpdateData(FALSE);
}

 


//引入XML
#import "MSXML.DLL" named_guids
//引用命名空间
using namespace MSXML;

void CDocin2Dlg::OnOK()
{
 // TODO: Add extra validation here
 UpdateData(TRUE);
 if(m_infile=="")
 {
  AfxMessageBox("请先选择要转换的docin文件!");
  return;
 }
 if(m_outfile=="")
 {
  AfxMessageBox("请选择保存位置!");
  return;
 }
 WinExec("cmd.exe /c md /""+m_outfile+"/"", SW_HIDE);//必须加参数/c
 Sleep(100);
 CFile mFile(m_infile,CFile::modeRead);
 
 unsigned char b0,b1,b2,b3;
 if(mFile.GetLength()<2) return;
 
 mFile.SeekToBegin();
 mFile.Read(&b0,1);
 mFile.Read(&b1,1);
 mFile.Read(&b2,1);
 mFile.Read(&b3,1);
 int headerLen=b0+(b1<<8)+(b2<<18)+(b3<<24);
 BYTE *headertmp=new BYTE[headerLen];
 mFile.Read(headertmp,headerLen);
 CString xmldescriptionStr="";
 
 int aa=0;
 while(aa<headerLen)
 {
  xmldescriptionStr+=headertmp[aa]-99;
  aa++;
 }
 //AfxMessageBox(xmldescriptionStr);
 
 CString xmlname="xmldescriptionStr.xml";
 CFile xmlFile(xmlname, CFile::modeWrite|CFile::modeCreate);
 xmlFile.Write(xmldescriptionStr,headerLen);
 xmlFile.Close();
 
 
 //初始化com环境
 CoInitialize(NULL);
 IXMLDOMDocumentPtr pXmlDoc;
 HRESULT hr;
 hr = pXmlDoc.CreateInstance(MSXML::CLSID_DOMDocument);
 if (FAILED(hr))
 {
  AfxMessageBox(_T("无法创建Xml对象实例。"));
  return ;
 }
 if(!pXmlDoc->load((LPCTSTR)xmlname) )
 {
  AfxMessageBox(_T("无法加载Xml文件。"));
  return ;
 }
 //获取Xml文件首个元素
 IXMLDOMElementPtr pRoot = pXmlDoc->GetdocumentElement();
 if(pRoot != NULL)
 {
  //获取所有的子节点
  IXMLDOMNodeListPtr pNodes = pRoot->GetchildNodes();
  int totalPages=pNodes->Getlength();
  for(int i=0; i<totalPages; i++)
  {
   _bstr_t textaa=pNodes->nextNode()->attributes->item[0]->text;
   int ii=atoi(textaa);
   
   //CString ss;
   //ss.Format("%d",ii);
   // AfxMessageBox(ss);
   BYTE *bodytmp=new BYTE[ii];
   mFile.Read(bodytmp,ii);
   CString swfname;
   swfname.Format(m_outfile+"//"+m_rename+"(%d_%d).swf",totalPages,i+1);
   CFile mFile2(swfname, CFile::modeWrite|CFile::modeCreate);
   mFile2.Write(bodytmp,ii);
   mFile2.Close();
   
  }
  
 }

mFile.Close();
AfxMessageBox("转换完成"); 
WinExec("explorer.exe /""+m_outfile+"/"", SW_SHOWNORMAL); //速度快
// CDialog::OnOK();
}

 

原创粉丝点击