?? fileinout.cpp
字號:
// FileInOut.cpp: implementation of the CFileInOut class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "MixedCS.h"
#include "FileInOut.h"
#include "Window.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CFileInOut::CFileInOut()
{
fh_out = fh_in = 0;
}
CFileInOut::~CFileInOut()
{
CloseFile();
}
///////////////////////////////////////////////////////////////////////////////
// CFileInOut Functions
///////////////////////////////////////////////////////////////////////////////
#define CHECK(x) {if( !(x) ) return false;}
#define CHECK_MSG(x,msg) {if( !(x) ){CWindow::ShowMessage(msg);return false;}}
/******************************************************************************/
// 名稱:OpenFile
// 功能:打開輸入輸出文件
// 參數:
// 返回:打開成功返回true,否則返回false
// 備注:
// 更新:2002/12/25
// 作者:0200906高志剛
/******************************************************************************/
bool CFileInOut::OpenFile(const char *OutFile,const char *InFile)
{
// 輸入文件!=輸出文件
CHECK_MSG( OutFile && InFile && strcmp(OutFile,InFile), "錯誤:無輸入輸出,或輸入輸出相同!" )
CHECK_MSG( (fh_in=_lopen(InFile,OF_READ))!=-1, "錯誤:無法打開輸入文件! " )
if( CWindow::IsFileExist(OutFile) )
{
if( IDYES != MessageBox(GetActiveWindow(),"該文件已存在,是否覆蓋? ",
"提示",MB_YESNO | MB_ICONQUESTION) )
{
_lclose(fh_in);
return false;
}
}
if( (fh_out=_lcreat(OutFile,0)) == -1 )
{
_lclose(fh_in);
CWindow::ShowMessage("錯誤:無法創(chuàng)建輸出文件! ");
return false;
}
return true;
}
/******************************************************************************/
// 名稱:CloseFile()
// 功能:關閉輸入輸出文件
// 參數:
// 返回:
// 備注:
// 更新:2002/12/25
// 作者:0200906高志剛
/******************************************************************************/
void CFileInOut::CloseFile()
{
_lclose(fh_in);
if( fh_out )
_lclose(fh_out);
}
/******************************************************************************/
// 名稱:RunError
// 功能:錯誤處理
// 參數:
// 返回:
// 備注:
// 更新:2002/12/25
// 作者:0200906高志剛
/******************************************************************************/
void CFileInOut::RunError(const char *OutFile)
{
CloseFile();
if(OutFile)
DeleteFile(OutFile);
}
///////////////////////////////////////////////////////////////////////////////
// End of Files
///////////////////////////////////////////////////////////////////////////////
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -