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

📄 formatchangedlg.cpp

📁 MAPINFO各式转换极为TXT---->MIDMIF
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	UpdateData(false);
}

void CFormatChangeDlg::OnAboutinfo() 
{
	// TODO: Add your control notification handler code here
	CAboutDlg aboutDlg;				//调用关于窗口
	aboutDlg.DoModal();
}

void CFormatChangeDlg::OnLookpaht() 
{
	// TODO: Add your control notification handler code here
//	if(m_defaultpath!="")
//	{
//		strSyspath=m_defaultpath;
//	}
//	else if(m_userpath!="")
//	{
//		strSyspath=m_userpath;
//	}
	ShellExecute(NULL,"open","d:\\",strSyspath,"",SW_SHOW);//打开指定文件夹窗口
}

void CFormatChangeDlg::OnOpenpath() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
	if(!m_selformat)
	{
		CFileDialog dlg(TRUE,".txt",NULL,1,"Txt Files (*.txt)|*.txt||",NULL);
		if(dlg.DoModal()==IDOK)
		{
			m_openpath=dlg.GetPathName();
			strExt=dlg.GetFileExt();
			strFilename=dlg.GetFileTitle();
		}
		if(!m_seloutpath)
		{
			m_defaultpath=m_openpath.Mid(0,strlen(m_openpath)-strlen(strExt)-strlen(strFilename)-1);
		}
		strInfo="   您选择处理的文件具体路径为:  ";
		m_info=strInfo+m_openpath;
		UpdateData(false);
	}
	else
	{
		LPBROWSEINFO lpbi=new BROWSEINFO;
		lpbi->hwndOwner=GetSafeHwnd();
		lpbi->pidlRoot=NULL;
		lpbi->pszDisplayName=NULL;
		lpbi->lpszTitle="请选择要批处理文件的目录位置:";
		lpbi->ulFlags=BIF_RETURNONLYFSDIRS|BIF_STATUSTEXT;
		lpbi->lpfn=NULL;
		LPITEMIDLIST lpitemidlist=SHBrowseForFolder(lpbi);//显示文件对话框
		if(lpitemidlist==NULL)
		{
			delete lpbi;
			lpbi=NULL;
			return;
		}
		char path[MAX_PATH];
		SHGetPathFromIDList(lpitemidlist,path);//转换对象标志符列表为一个文件系统路径
		delete lpbi;
		m_openpath=path;
		if(!m_seloutpath)
		{
			m_defaultpath=m_openpath;
		}

		m_info=BrowseDir(m_openpath);

		strInfo="   您选择批处理的文件路径为:  ";
		m_info=strInfo+path;
	}
	UpdateData(FALSE);// 更新对话框	
}

void CFormatChangeDlg::OnUserpath() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
	m_defaultpath="";
	UpdateData(false);
		UpdateData(true);
		LPBROWSEINFO lpbi=new BROWSEINFO;
		lpbi->hwndOwner=GetSafeHwnd();
		lpbi->pidlRoot=NULL;
		lpbi->pszDisplayName=NULL;
		lpbi->lpszTitle="请选择要输出文件的目录位置:";
		lpbi->ulFlags=BIF_RETURNONLYFSDIRS|BIF_STATUSTEXT;
		lpbi->lpfn=NULL;
		LPITEMIDLIST lpitemidlist=SHBrowseForFolder(lpbi);//显示文件对话框
		if(lpitemidlist==NULL)
		{
			delete lpbi;
			lpbi=NULL;
			return;
		}
		char path[MAX_PATH];
		SHGetPathFromIDList(lpitemidlist,path);//转换对象标志符列表为一个文件系统路径
		delete lpbi;
		m_userpath=path;
		strInfo="   您选择输出的文件路径为:  ";
		m_info=strInfo+path;
	UpdateData(false);
}

void CFormatChangeDlg::OnDefaultpath() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_defaultpath=m_openpath.Mid(0,strlen(m_openpath)-strlen(strExt)-strlen(strFilename)-1);
	strSyspath=m_defaultpath;
	m_userpath="";
	UpdateData(FALSE);
}

CString CFormatChangeDlg::Ch(CString stropenfile, CString stroutmif, CString stroutmid)
{
	int linecount=0;
	int itemcount=0;
	//打开源文件,读取数据
	ifstream ifile;
	ifile.open (stropenfile);
	vector<string> content;
    string temp;
	while(!ifile.eof ())
	{
		getline(ifile,temp,'\n');
		content.push_back (temp);
		linecount++;
	}
    ifile.close ();

	//将每行数据以逗号分割,存储.
	vector<vector<string> > lines;
	lines.resize(linecount);
	vector<string>::iterator it=content.begin ();
	int count=0;
	while(count<linecount)
	{
		int i=0,j=0;
 		while(j!=it->npos)
		{
			j=it->find (",",i);
			if(j==-1)
				break;
			string temp=it->substr (i,j-i);
			lines[count].push_back (temp);
			i=++j;

			if(count==0 && temp!="lat" && temp!="lon")
				itemcount++;
		}
		it++;
		count++;
	}

	//打开.mid,写入数据
	ofstream ofile1,ofile2;

	ofile1.open (stroutmid);
	if(!ofile1)
	{
		return "异常提示:请您检查mid文件,源文件打开失败!";
	}

	for(int i=1;i<linecount;i++)
	{
		for(int j=0;j<lines[i].size ();j++)
		{
			if(j==1 || j==2)
				continue;
			ofile1<<"\""<<lines[i].at(j)<<"\"";
			if(j!=lines[i].size ()-1)
				ofile1<<",";
		}
		ofile1<<endl;
	}
	ofile1.close ();

	//打开.mif,写入数据
	ofile2.open (stroutmif);
	if(!ofile2)
	{
		return "异常提示:请您检查mif文件,源文件打开失败!";
	}

	ofile2<<"Version 300\nCharset \"WindowsSimpChinese\"\n"
		<<"Delimiter \",\"\nCoordSys Earth Projection 1, 104\n"
		<<"Columns  "<<itemcount+1<<endl;

	vector<string> last;
	last.push_back ("Char(50)");
	last.push_back ("Char(50)");
	last.push_back ("Char(100)");
	last.push_back ("Char(100)");
	last.push_back ("Char(100)");
	last.push_back ("Char(100)");
	last.push_back ("Char(100)");
	last.push_back ("Char(100)");
	last.push_back ("Char(20)");
	last.push_back ("Char(20)");
	last.push_back ("Char(20)");
	last.push_back ("Char(20)");
	last.push_back ("Char(100)");
	last.push_back ("Char(100)");
	last.push_back ("Char(100)");
	last.push_back ("Char(100)");
	last.push_back ("Char(100)");
	last.push_back ("Char(100)");
	last.push_back ("Char(100)");
	last.push_back ("Char(100)");
	last.push_back ("Char(100)");
	last.push_back ("Char(50)");
	last.push_back ("Char(50)");
	last.push_back ("Char(50)");
	last.push_back ("Char(20)");
	last.push_back ("Char(20)");
	last.push_back ("Char(20)");
	last.push_back ("Char(20)");
	last.push_back ("Char(20)");
	last.push_back ("Char(20)");
	last.push_back ("Char(20)");
	last.push_back ("Char(20)");

	vector<string>::iterator o=lines[0].begin ();
	vector<string>::iterator y=last.begin ();
	while(o!=lines[0].end())
	{
		if(*o=="lat" || *o=="lon")
		{
			o++;
			continue;
		}
		ofile2<<"  "<<*o<<" "<<*y<<endl;
		o++;
		y++;
	}
	ofile2<<"Data"<<endl<<endl;

	for(i=1;i<linecount;i++)
	{
		ofile2<<"Point "<<lines[i].at (1)<<" "<<
			lines[i].at (2)<<endl;
		ofile2<<"    Symbol (33,255,8)"<<endl;
	}

	ofile2.close ();
	return "友情提示:恭喜您,您已的转换操作已经成功完成!";
}

CString CFormatChangeDlg::BrowseDir(CString &strDir)//批处理文件路径输出
{
	CFileFind cff;
	CString str;
	CStdioFile ExportFile;
	int ldirCount=0,lfileCount=0;
	CString szDir=strDir;
	ExportFile.Open("D:\path.txt",CFile::modeCreate|CFile::modeWrite,NULL);
	if(szDir.Right(1)!="\\")
		szDir+="\\";
	szDir+="*.txt";
	BOOL bResult=cff.FindFile(szDir);
	while(bResult)
	{
		bResult=cff.FindNextFile();
		if(cff.IsDirectory()&&!cff.IsDots())
		{
			CString strPath=cff.GetFilePath();
			BrowseDir(strPath);
			ldirCount++;
		}
		else if(!cff.IsDirectory()&&!cff.IsDots())
		{
			str.Format("%s",cff.GetFilePath());
			ExportFile.WriteString(str+"\n");
			lfileCount++;
			Sleep(10);
		}
		str="";
	}
	cff.Close();
	return "您已经成功检索打开文件目录下的所有txt文件!";
}

void CFormatChangeDlg::OnSingle() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_openpath="";
	m_userpath="";
	m_defaultpath="";
	UpdateData(FALSE);	
}

void CFormatChangeDlg::OnBatch() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_openpath="";
	m_userpath="";
	m_defaultpath="";
	UpdateData(FALSE);	
}

⌨️ 快捷键说明

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