0

ファイルを保存するメニューオプションを備えたMFCプログラムを作成しました。クリックすると CFileDialog が表示され、ファイルを保存する場所を選択できます。ダイアログで保存をクリックすると、ダイアログが閉じますが、その後は何もしません。そして、それは私のファイルを保存しませんでした。私は何を間違っていますか?

ここにコードがあります

CFileDialog *dlg = new CFileDialog(FALSE, L"dr", NULL, NULL,
                   L"Drawings (*.dr)|*.dr|"
                   L"All Files||");

bool result = dlg->DoModal();

if(result)
{
    MessageBox(0, dlg->GetPathName(), L"Draw", 0);
}

bool の結果は、問題/エラーがないかどうかを確認するためのものです。

4

2 に答える 2

2

ファイル保存ダイアログは、キャプションに「ファイルを保存」と表示され、単一のファイルのみを選択できるため、「ファイル保存ダイアログ」と呼ばれます。これは、実際にファイルの保存を行うという意味ではありません。ユーザーが選択したファイル名を返すだけです。このファイル名を使用してファイルを保存するコードを作成する責任は引き続きあります。

于 2015-02-11T14:29:35.820 に答える
1

The CFileDialog does not save the file for you, it only provides you with a dialog for the user to determine where (and if!) the file should be saved. The return value of DoModal() should be compared to IDOK before proceeding to save. From the dialog's member functions you can get the path and filename the user selected. With that, you can create/open a file and save your data.

于 2015-02-11T14:31:04.713 に答える