让电脑做傻事 欢迎大家查看

时间:2013-04-27 14:54:26
【文件属性】:

文件名称:让电脑做傻事 欢迎大家查看

文件大小:4KB

文件格式:TXT

更新时间:2013-04-27 14:54:26

C++

CString CUtilsDlg::GetExtName( CString name ) { CString strext = _T(""); CString strTemp = name; int i = strTemp.ReverseFind( '.' ); if( i != -1 ) { strext = strTemp.Right( strTemp.GetLength() - i - 1 ); } return strext; } void CUtilsDlg::DoToChar( CString mfile ) { CString mExt = GetExtName( mfile ); mExt.MakeLower(); if( ( mExt.Compare( _T("cpp") ) == 0 ) || ( mExt.Compare( _T("h") ) == 0 ) || ( mExt.Compare( _T("txt") ) == 0 ) ) { m_result.AddString( mfile ); CString mstrfile = mfile; m_before.SetSel( 0, -1 ); m_after.SetSel( 0, -1 ); m_before.Clear(); m_after.Clear(); m_before.SetWindowText(_T("")); m_after.SetWindowText(_T("")); //m_result.ResetContent(); CStdioFile file; if( !file.Open( mstrfile, CFile::modeRead ) ) { return; } CString strall; CString strSave; CString str; int i = 0; while( file.ReadString( str ) ) { CString strhead; strhead.Format( _T("%d"),i ); int nlen = strhead.GetLength(); switch( nlen ) { case 1: strhead += _T("------"); break; case 2: strhead += _T("-----"); break; case 3: strhead += _T("----"); break; case 4: strhead += _T("---"); break; case 5: strhead += _T("--"); break; case 6: strhead += _T("-"); break; } CString strafln = strhead; strafln += str; m_before.ReplaceSel( strafln ); m_before.ReplaceSel( _T("\r\n") ); CString strTemp = str; int nRet = -1; CString strTChar = ToTChar( strTemp, &nRet ); strSave += strTChar; strSave += _T("\r\n"); CString strbfln = strhead; strbfln += strTChar; m_after.ReplaceSel( strbfln ); m_after.ReplaceSel( _T("\r\n") ); if( nRet == 0 ) { CString strResult; strResult.Format("%d",i); m_result.AddString( strResult ); } i ++; } file.Close(); CFile fsave; if( fsave.Open( mstrfile, CFile::modeWrite ) ) { fsave.Write( strSave, strSave.GetLength() ); fsave.Close(); } } }


网友评论