打开指定路径下文件
void CGFileCompileDlg::OnButtonOpen()
{
// TODO: Add your control notification handler code here
/***********************************************************************************/
CFile openfile;
int iFileLength;
char * lpGCodeBuffer; //G代码数据的存储区
// CString msg="文件打开失败!";
CFileDialog fileopen(true, ".nc", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"NC Files (*.NC)|*.NC|All Files (*.*)|*.*||", NULL);
if(fileopen.DoModal()==IDOK)
{
m_OpenPath.SetWindowText(fileopen.GetPathName());
if(!openfile.Open(fileopen.GetPathName(), openfile.modeReadWrite|openfile.modeNoInherit, NULL))
{
this->MessageBox("文件打开失败!");
}
iFileLength = openfile.GetLength();
lpGCodeBuffer = new char[iFileLength + 1]; //根据文件的长度创建G代码存储区
openfile.Read(lpGCodeBuffer, iFileLength);
//将G代码显示在编辑框中
lpGCodeBuffer[iFileLength] = '\0';
m_Para = lpGCodeBuffer;
delete lpGCodeBuffer;
openfile.Close();
UpdateData(FALSE);
}
/* else
{
MessageBox(msg);
}*/
}
保存文件
void CGFileCompileDlg::OnButtonSave()
{
// TODO: Add your control notification handler code here
/*****************************************************************************/
// CString msg="文件保存失败!请检查路径是否正确!";
CFile savefile;
char * lpGCodeBuffer; //G代码数据的存储区
int iFileLength;
CFileDialog fileopen(false, ".nc", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"NC Files (*.NC)|*.NC|All Files (*.*)|*.*||", NULL);
if(fileopen.DoModal()==IDOK)
{
m_SavePath.SetWindowText(fileopen.GetPathName());
UpdateData(true);
if(!savefile.Open(fileopen.GetPathName(), savefile.modeWrite|savefile.modeCreate, NULL))
{
this->MessageBox("文件保存失败!");
}
//保存G文件
iFileLength = m_Para.GetLength();
lpGCodeBuffer = new char[iFileLength + 1]; //根据文件的长度创建G代码存储区
strcpy(lpGCodeBuffer,m_Para);
lpGCodeBuffer[iFileLength] = '\0';
savefile.Write(lpGCodeBuffer,iFileLength);
delete lpGCodeBuffer;
savefile.Close();
UpdateData(false);
}
// else
// {
// MessageBox(msg);
// }
}