|
// *********************************************************
// テキストファイルの処理
// *********************************************************
void MyClass::LoadTextFile()
{
LboxTextFile Txt;
// 「ファイルを開く」ダイアログ用
LboxString LString;
LboxCommdlg Commdlg( this->hWnd );
Commdlg.lpstrTitle = "ファイルを開く";
Commdlg.lpstrFilter = "テキスト,*.txt,全て,*.*";
// コモンダイアログ呼び出し
if ( !Commdlg.OpenFileName( &LString ) ) {
MsgOk( "キャンセルされました " );
return;
}
// ファイルのオープン
if ( !Txt.ReadOpen( &LString ) ) {
MsgOk(
"%s をオープンできません ",
LString.szLboxString
);
return;
}
// 読み込みバッファ
LboxString LBuffer;
// 一行の読み込みに十分なサイズを確保
LBuffer.Resize( 1024 );
// データ表示用のリストビューを初期化
LView->Initialize();
LView->AddColumn( "行番号" );
LView->AddColumn( "テキストファイルの行データ" );
int nRow; // 行番号
nRow = 1;
LboxString LWork; // 最後尾文字列処理用
// 読み込み
while( Txt.Get( &LBuffer ) ) {
LView->AddRow();
LView->SetColumnPrintf( 0, "%d", nRow );
nRow++;
LBuffer.Right( 1, &LWork );
if ( LWork.operator == ("\n") ) {
LBuffer.RemoveLastchar();
}
LView->SetColumnText( 1, &LBuffer );
}
// ファイルのクローズ
Txt.Close();
// リストビュー表示の最適化
LView->Fit();
}
| |