⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datastreamdlg.cpp

📁 对数据进行一些流方面的操作
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		OFN_OVERWRITEPROMPT, szFilter );
	if (dlg.DoModal() == IDCANCEL) return;
	CString strDataName=dlg.GetPathName();
	if(strDataName.GetLength()==0)return;  
	m_strDocFile=strDataName;
	CString str=m_strDocFile;
	CWnd* pWnd=GetDlgItem(IDC_DOCFILE);
	pWnd->SetWindowText(str);
    OnWrite();
}

void CDataStreamDlg::OnAddzip() 
{
	////得到要保存的压缩数据文件名
	char szFilter[] = "数据文件 (*.dat)|*.dat||";
	CFileDialog dlg( TRUE, "*.dat", NULL, OFN_HIDEREADONLY , szFilter );
	if (dlg.DoModal() == IDCANCEL) return;
	CString strDataName=dlg.GetPathName();
	if(strDataName.GetLength()==0)return;   
	m_strDocFile=strDataName;

	OnWrite();
}

void CDataStreamDlg::OnWrite() 
{
	OpenFile();
	if(m_files.GetSize()==0)return;
	Invalidate();
	m_list.Invalidate();
	WriteFile(m_strDocFile);
}

void CDataStreamDlg::OpenFile()
{
	CGetDataDlg dlg;
	dlg.m_strZipName=m_strDocFile;
	dlg.DoModal();
	m_strPreName=dlg.m_strPreName;
    m_files.Copy(dlg.m_files);

	CWnd* pWnd=GetDlgItem(IDC_DOCFILE);
	pWnd->SetWindowText(m_strDocFile);
    pWnd=GetDlgItem(IDC_SNAME);
	pWnd->SetWindowText(m_strPreName);
}

int CDataStreamDlg::LoadBmp(LPCSTR sDocName)
{
/*	CString strDataName=sDocName;
	if(!open_StgDoc(strDataName))
	{
		MessageBox("压缩文件损坏!");
		return 0;
	}
 	CString strIniFile=strDataName;
    strIniFile.Replace(".dat",".ini");
	DeletContents();
	
	////////读取配置文件得到流对应的文件名
	CString sName,fName,str;
	char szValue[256];
	int n=GetPrivateProfileInt("totals","number",0,strIniFile);
    if(!n) return 0;
	m_iTotalSize=n;
	m_iCurPos=0;
	DWORD iSize=0;
	CComPtr<IStream> pStream;
	CBitmapEx * pBitmap;
	for(int i=0;i<n;i++)
	{
		str.Format("%d",i);
		GetPrivateProfileString(str,"sName",NULL,
			szValue,sizeof(szValue),strIniFile);
		sName = szValue;
		iSize=GetPrivateProfileInt(str,"iSize",0,strIniFile);
		pStream=read_stream(sName,iSize);
		if(pStream == NULL)
		{
			CString str;
			str.Format("数据流%s无法打开!",sName);
			MessageBox(str);
			continue;
		}
		pBitmap=new CBitmapEx;
		if(pBitmap->LoadFromStream(pStream))
			m_bitmaps.Add(pBitmap);
		pStream.Release();
	}
	Invalidate();
	close_StgDoc();*/
	return 1;
}


int CDataStreamDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;
	//取程序当前目录
	char szFileName[256];
	memset(szFileName,0,sizeof(szFileName));
	GetModuleFileName(NULL,szFileName,sizeof(szFileName));
    char *lpSlash=strrchr(szFileName,'\\');
	if(lpSlash)lpSlash[1]=0;
	m_strInstallPath=szFileName;	
	return 0;
}

void CDataStreamDlg::LoadBtnImages()
{
/*	CComPtr<IStream> pStream;
	CString sName,str;
	sName="btn_0";
	CStreamItem * pItem=m_bmpLst.GetStream(sName);
	DWORD dwSize;
	dwSize=pItem->dwSize;
	pStream=read_stream(sName,dwSize);
	if(pStream == NULL)
	{
		str.Format("数据流%s无法打开!",sName);
		MessageBox(str);
		return;
	}
	CBitmapEx * pBitmap=new CBitmapEx;
	pBitmap->LoadFromStream(pStream);
	m_btnFileOpen.m_bitmap.Attach(pBitmap->m_hObject);
	pStream.Release();
	delete pBitmap;*/
}

void CDataStreamDlg::OnFolder() 
{
	////得到要保存的压缩数据文件名
	char szFilter[] = "数据文件 (*.dat)|*.dat||";
	CFileDialog dlg( FALSE, "*.dat", NULL, OFN_HIDEREADONLY |
		OFN_OVERWRITEPROMPT, szFilter );
	if (dlg.DoModal() == IDCANCEL) return;
	CString strDataName=dlg.GetPathName();
	if(strDataName.GetLength()==0)return;  
	m_strDocFile=strDataName;
	CString str=m_strDocFile;

	char szFilter1[] = "配置文件 (*.ini)|*.ini||";
	CFileDialog dlg1( TRUE, "*.ini", NULL, OFN_HIDEREADONLY |
		OFN_OVERWRITEPROMPT, szFilter1 );
	if (dlg1.DoModal() == IDCANCEL) return;
	strDataName=dlg1.GetPathName();
	if(strDataName.GetLength()==0)return;  
MakeRINI(strDataName);
	////////读取配置文件得到对应的文件名
	CString strSection,sName,fName,strSTV,strTCH,strDSTV,strACT,strMP3,strINIFileName;
	char szValue[256];
	int n=GetPrivateProfileInt("totals","number",0,strDataName);
    if(!n) return ;
	open_StgDoc(m_strDocFile);
	CFile f;
	byte * lpBuf;
	int iSize=0;
   //把文件列表写入配置文件中
	CStdioFile fINI;
	strINIFileName=m_strDocFile;
    strINIFileName.Replace(".dat",".ini");
	//创建配置文件
	if(!fINI.Open(strINIFileName,CFile::modeWrite|CFile::modeCreate))
		return;
	str.Format("[Totals]\n");
	fINI.WriteString(str);
	str.Format("Number=%d\n",n);
	fINI.WriteString(str);
	fINI.SeekToEnd();
	////
	for(int i=0;i<n;i++)
	{
		strSection.Format("%d",i);
	
		strSTV.Format("STV_%d",i);
	   	GetPrivateProfileString(strSection,strSTV,NULL,
			szValue,sizeof(szValue),strDataName);
		fName = szValue;
		sName = strSTV;
		f.Open(fName,CFile::modeRead,NULL);
		iSize=f.GetLength();
		if(iSize>0)
		{
			lpBuf=(byte *)malloc(iSize);
			f.Read(lpBuf, iSize);
			write_stream(sName,lpBuf,iSize);
			free(lpBuf);
		
			str.Format("[%s]\n",sName);
			fINI.WriteString(str);
		
			str.Format("fName=%s\n",fName);
			fINI.WriteString(str);
			
			str.Format("iSize=%d\n",iSize);
			fINI.WriteString(str);
		}

		strTCH.Format("TCH_%d",i);
			GetPrivateProfileString(strSection,strTCH,NULL,
			szValue,sizeof(szValue),strDataName);
		fName = szValue;
		sName = strTCH;
		f.Open(fName,CFile::modeRead,NULL);
		iSize=f.GetLength();
		if(iSize>0)
		{
			lpBuf=(byte *)malloc(iSize);
			f.Read(lpBuf, iSize);
			write_stream(sName,lpBuf,iSize);
			free(lpBuf);
		
			str.Format("[%s]\n",sName);
			fINI.WriteString(str);
		
			str.Format("fName=%s\n",fName);
			fINI.WriteString(str);
			
			str.Format("iSize=%d\n",iSize);
			fINI.WriteString(str);
		}
		strDSTV.Format("DSTV_%d",i);
			GetPrivateProfileString(strSection,strDSTV,NULL,
			szValue,sizeof(szValue),strDataName);
		fName = szValue;
		sName = strDSTV;
		f.Open(fName,CFile::modeRead,NULL);
		iSize=f.GetLength();
		if(iSize>0)
		{
			lpBuf=(byte *)malloc(iSize);
			f.Read(lpBuf, iSize);
			write_stream(sName,lpBuf,iSize);
			free(lpBuf);
		
			str.Format("[%s]\n",sName);
			fINI.WriteString(str);
		
			str.Format("fName=%s\n",fName);
			fINI.WriteString(str);
			
			str.Format("iSize=%d\n",iSize);
			fINI.WriteString(str);
		}
		strACT.Format("ACT_%d",i);
			GetPrivateProfileString(strSection,strACT,NULL,
			szValue,sizeof(szValue),strDataName);
		fName = szValue;
		sName = strACT;
		f.Open(fName,CFile::modeRead,NULL);
		iSize=f.GetLength();
		if(iSize>0)
		{
			lpBuf=(byte *)malloc(iSize);
			f.Read(lpBuf, iSize);
			write_stream(sName,lpBuf,iSize);
			free(lpBuf);
		
			str.Format("[%s]\n",sName);
			fINI.WriteString(str);
		
			str.Format("fName=%s\n",fName);
			fINI.WriteString(str);
			
			str.Format("iSize=%d\n",iSize);
			fINI.WriteString(str);
		}
		strMP3.Format("MP3_%d",i);
			GetPrivateProfileString(strSection,strMP3,NULL,
			szValue,sizeof(szValue),strDataName);
		fName = szValue;
		sName = strMP3;
		f.Open(fName,CFile::modeRead,NULL);
		iSize=f.GetLength();
		if(iSize>0)
		{
			lpBuf=(byte *)malloc(iSize);
			f.Read(lpBuf, iSize);
			write_stream(sName,lpBuf,iSize);
			free(lpBuf);
		
			str.Format("[%s]\n",sName);
			fINI.WriteString(str);
		
			str.Format("fName=%s\n",fName);
			fINI.WriteString(str);
			
			str.Format("iSize=%d\n",iSize);
			fINI.WriteString(str);
		}
	}
	fINI.Close();
	close_StgDoc();
	MessageBox("ok!");
}

 		

void CDataStreamDlg::MakeRINI(LPCSTR lpProfileName)
{
	////////读取配置文件得到对应的文件名
	CString str,strSection,fName,strSTV,strINIFileName;
	char szValue[256];
	int n=GetPrivateProfileInt("totals","number",0,lpProfileName);
    if(!n) return ;
    //把文件列表写入配置文件中
	CStdioFile fINI;
	strINIFileName=m_strDocFile;
    strINIFileName.Replace(".dat",".ini");

	//创建配置文件
	if(!fINI.Open(strINIFileName,CFile::modeWrite|CFile::modeCreate))
		return;
	str.Format("[Totals]\n");
	fINI.WriteString(str);
	str.Format("Number=%d\n",n);
	fINI.WriteString(str);
	fINI.SeekToEnd();
	////
	for(int i=0;i<n;i++)
	{
		strSection.Format("%d",i);
		strSTV.Format("STV_%d",i);
	   	GetPrivateProfileString(strSection,strSTV,NULL,
			szValue,sizeof(szValue),lpProfileName);
		fName = szValue;
		fName.Replace(".stv","");
		str.Format("[%d]\n",i);
		fINI.WriteString(str);

		str.Format("fName=%s\n",fName);
		fINI.WriteString(str);

	    str.Format("stv=STV_%d\n",i);
		fINI.WriteString(str);

		str.Format("tch=TCH_%d\n",i);
		fINI.WriteString(str);

		str.Format("dstv=dSTV_%d\n",i);
		fINI.WriteString(str);

		str.Format("act=ACT_%d\n",i);
		fINI.WriteString(str);

        str.Format("mp3=MP3_%d\n",i);
		fINI.WriteString(str);
		
	}
	fINI.Close();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -