mfc记录上次打开的文件目录

ret = init_path_record_file( gFile_record_file_Path, tmppath_content );          
if( ret == 0 ){
        tmppath = gCurrent_Path+"\\*.bin";
}else{
        index = tmppath_content.ReverseFind( '\\' );
        if( index != -1 ){
tmppath = tmppath_content.Left(index)+"\\*.bin";
        }else{
            tmppath = gCurrent_Path+"\\*.bin";
  }
}
CFileDialog dlg(TRUE, NULL, tmppath, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT, "´ý¼ÓÃܵÄÎļþ (*.bin)|*.bin||");
if( IDOK == dlg.DoModal() ){
gFile_encrypt_Path = dlg.GetPathName();
}
write_path_record_file( gFile_record_file_Path, gFile_encrypt_Path );

UpdateData(FALSE);






int init_path_record_file( const CString &strFileLocalFullPath, CString &strFileLocalFullPath_content )
{
    CString fileString; 
CStdioFile f;
    CFileException e;
int file_content_null;
    file_content_null = 0x01;
    if( !f.Open( strFileLocalFullPath, CFile::modeReadWrite, &e) ){  
        return 0;  
    }
    if( f.ReadString(fileString) != FALSE ){   
        file_content_null = 0;
        strFileLocalFullPath_content = fileString;
        //MessageBox(NULL,fileString,"Buffer Size",MB_OK);
}  
f.Flush();
f.Close();
if( file_content_null == 0 ){
        return 1;
}else{
        return 0;
    }
}






BOOL write_path_record_file( const CString &strFileLocalFullPath, CString &strFileLocalFullPath_content )
{
    ASSERT(strFileLocalFullPath != "");
    char* pszBuffer = NULL;
    DWORD dwWrite;
    int nWrite;
    const int BUFFER_LENGTH = 1024 * 2;
    pszBuffer = new char[BUFFER_LENGTH];  
    HANDLE hFile = CreateFile( strFileLocalFullPath ,GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,
    NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );              
    //´´½¨±¾µØÎļþ
    if( hFile == INVALID_HANDLE_VALUE ){
        return false;
    }
    SetFilePointer( hFile, 0, 0, FILE_BEGIN );
    memset( pszBuffer, 0, BUFFER_LENGTH );
    LPTSTR p = strFileLocalFullPath_content.GetBuffer( strFileLocalFullPath_content.GetLength() );   
    strcpy( pszBuffer, p );      
    strFileLocalFullPath_content.ReleaseBuffer();   
    nWrite = strlen( pszBuffer );
    WriteFile(hFile, pszBuffer, nWrite, &dwWrite, NULL);
//Òƶ¯ÎļþÖ¸Õ뵽еÄλÖÃ
    SetFilePointer( hFile, dwWrite, NULL, FILE_BEGIN );
    //ÉèÖÃÎļþеĽáÊøλÖá£
    SetEndOfFile(hFile);
    delete[]pszBuffer;
    pszBuffer = NULL;
    CloseHandle(hFile);
    return true;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值