LboxDlg *Dlg; LboxTextFile *TextFile; LRESULT CALLBACK About( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) { switch( message ) { case WM_INITDIALOG: Dlg = new LboxDlg( hDlg ); TextFile = new LboxTextFile( ); return TRUE; case WM_COMMAND: if( LOWORD(wParam) == IDCANCEL ) { Dlg->End( LOWORD(wParam) ); delete TextFile; delete Dlg; } break; } return FALSE; }
// ********************************************************* // デフォルトコンストラクタ // ********************************************************* LboxTextFile::LboxTextFile() { LboxTextFile::fp = NULL; } // ********************************************************* // デストラクタ // ********************************************************* LboxTextFile::~LboxTextFile() { if ( LboxTextFile::fp != NULL ) { fclose( fp ); } }
// ********************************************************* // テキストファイルを読込みモードでオープン // 戻り値 : 成功 true, 失敗 false // ********************************************************* BOOL LboxTextFile::ReadOpen( LboxString *LString ) { return LboxTextFile::ReadOpen( LString->szLboxString ); } BOOL LboxTextFile::ReadOpen( LPCTSTR lpFileName ) { if ( LboxTextFile::fp != NULL ) { fclose( fp ); } LboxFileSystem Fs; this->CurSize = 4096; Fs.Size( lpFileName, &(this->CurSize) ); LboxTextFile::fp = fopen( lpFileName, "rt" ); if ( LboxTextFile::fp == NULL ) { return false; } return true; }
// ********************************************************* // テキストファイルを1行読込み // 戻り値 : 成功 true, EOF false // ********************************************************* BOOL LboxTextFile::Get( LboxString *LString ) { if ( LboxTextFile::fp == NULL ) { return false; } ZeroMemory( LString->szLboxString, LString->nLboxString ); fgets( LString->szLboxString, LString->nLboxString, LboxTextFile::fp ); if ( feof( LboxTextFile::fp ) ) { if ( *(LString->szLboxString) == 0x00 ) { return false; } } return true; } BOOL LboxTextFile::Get( LPTSTR lpBuffer, int nSize ) { if ( LboxTextFile::fp == NULL ) { return false; } ZeroMemory( lpBuffer, nSize ); fgets( lpBuffer, nSize, LboxTextFile::fp ); if ( feof( LboxTextFile::fp ) ) { if ( *lpBuffer == 0x00 ) { return false; } } return true; }
// ********************************************************* // テキストファイルを書込みモードでオープン // 戻り値 : 成功 true, 失敗 false // ********************************************************* BOOL LboxTextFile::WriteOpen( LboxString *LString ) { return LboxTextFile::WriteOpen( LString->szLboxString ); } BOOL LboxTextFile::WriteOpen( LPCTSTR lpFileName ) { if ( LboxTextFile::fp != NULL ) { fclose( fp ); } LboxTextFile::fp = fopen( lpFileName, "wt" ); if ( LboxTextFile::fp == NULL ) { return false; } return true; }
// ********************************************************* // テキストファイルに文字列を書込み // 戻り値 : 成功 true, 失敗 false // ********************************************************* BOOL LboxTextFile::Put( LboxString *LString ) { int nLen; nLen = lstrlen( LString->szLboxString ); LString->Replace( "\r\n", "\n" ); int nRet; nRet = fputs( LString->szLboxString, LboxTextFile::fp ); if ( nRet >= 0 ) { return true; } return false; } BOOL LboxTextFile::Put( LPTSTR lpBuffer ) { LboxString LString; LString.operator = (lpBuffer); int nLen; nLen = lstrlen( LString.szLboxString ); LString.Replace( "\r\n", "\n" ); int nRet; nRet = fputs( LString.szLboxString, LboxTextFile::fp ); if ( nRet >= 0 ) { return true; } return false; }
// ********************************************************* // テキストファイルを可能な限り全て読み込む // 戻り値 : 成功 true, EOF false // ********************************************************* void LboxTextFile::GetAll( LboxString *LString ) { if ( LboxTextFile::fp == NULL ) { return; } if ( this->CurSize <= LBOX_STRINGMAX ) { LString->Resize( this->CurSize ); } LboxString *LstrWork; LstrWork = new LboxString( MAX_PATH ); LString->SetChar( 0, 0 ); while( 1 ) { ZeroMemory( LstrWork->szLboxString, LstrWork->nLboxString ); fgets( LstrWork->szLboxString, LstrWork->nLboxString, LboxTextFile::fp ); if ( feof( LboxTextFile::fp ) ) { if ( *(LstrWork->szLboxString) == 0x00 ) { break; } else { LString->operator += ( LstrWork ); break; } } LString->operator += ( LstrWork ); } delete LstrWork; }
// ********************************************************* // テキストファイルに文字列を書込み // 戻り値 : 成功 true, 失敗 false // ********************************************************* BOOL LboxTextFile::PutPrintf( LPTSTR FormatString, ...) { LboxString *LstrWork; LstrWork = new LboxString( 1024 ); va_list marker; va_start(marker, FormatString); wvsprintf(LstrWork->szLboxString, FormatString, marker); va_end(marker); BOOL bRet; bRet = LboxTextFile::Put( LstrWork ); delete LstrWork; return bRet; }
// ********************************************************* // テキストファイルをクローズ // 戻り値 : 無し // ********************************************************* void LboxTextFile::Close( void ) { if ( LboxTextFile::fp != NULL ) { fclose( fp ); } }
// ********************************************************* // レコード数取得 // 戻り値 : レコード数 ( 失敗 : -1 ) // ********************************************************* LONG LboxTextFile::RecordCount( LboxString *LFileName, LboxString *LBuffer ) { return LboxTextFile::RecordCount( LFileName->szLboxString, LBuffer ); } LONG LboxTextFile::RecordCount( LPTSTR lpFileName, LboxString *LBuffer ) { FILE *tmp; LONG nCount; nCount = 0; tmp = fopen( lpFileName, "rt" ); if ( tmp == NULL ) { return -1; } while( 1 ) { LBuffer->SetChar( 0, 0 ); fgets( LBuffer->szLboxString, LBuffer->nLboxString, tmp ); if ( feof( tmp ) ) { if ( *(LBuffer->szLboxString) == 0x00 ) { break; } } nCount++; } fclose( tmp ); return nCount; }
// ********************************************************* // テキストファイルを追加書込みモードでオープン // 戻り値 : 成功 true, 失敗 false // ********************************************************* BOOL LboxTextFile::AppendOpen( LboxString *LString ) { return LboxTextFile::AppendOpen( LString->szLboxString ); } BOOL LboxTextFile::AppendOpen( LPCTSTR lpFileName ) { if ( LboxTextFile::fp != NULL ) { fclose( fp ); } LboxTextFile::fp = fopen( lpFileName, "at" ); if ( LboxTextFile::fp == NULL ) { return false; } return true; }