|
// *********************************************************
// テキストファイルの処理
// *********************************************************
void MyClass::SaveTextFile()
{
int nCols; // カラム数
nCols = LView->ColumnCount();
if ( nCols == 0 ) {
MsgOk( "カラムがありません " );
return;
}
if ( LView->Count() == 0 ) {
MsgOk( "行データがありません " );
return;
}
LboxTextFile Txt;
// 「ファイルを保存する」ダイアログ用
LboxString LString;
LboxCommdlg Commdlg( this->hWnd );
Commdlg.lpstrTitle = "ファイルを保存する";
Commdlg.lpstrFilter = "テキスト,*.txt,全て,*.*";
Commdlg.lpstrDefExt = "txt";
// コモンダイアログ呼び出し
if ( !Commdlg.SaveFileName( &LString ) ) {
MsgOk( "キャンセルされました " );
return;
}
// ファイルのオープン
if ( !Txt.WriteOpen( &LString ) ) {
MsgOk(
"%s をオープンできません ",
LString.szLboxString
);
return;
}
// 書き込みバッファ
LboxString LBuffer;
// カラム用バッファ
LboxString LColumn;
// ループ用ワーク
int i,nRow;
nRow = -1;
// リストビューからデータ取得
while( LView->FindNextRow( &nRow ) ) {
LString.SetChar( 0, 0 ); // 文字列の先頭に 0x00 をセット
for( i = 0; i < nCols; i++ ) {
if ( i != 0 ) {
LString.operator += (",");
}
LView->GetColumnText( i, &LColumn );
LString.operator += ( &LColumn );
}
LString.operator += ( "\n" ); // 改行
Txt.Put( &LString );
}
// ファイルのクローズ
Txt.Close();
}
| |