2

コードで使用している問題に直面CFileDialogしています。

CFileDialogModalDialog から呼び出すと、ファイルを選択します。現在のビューを終了して再度開くと、ModalDialog の背景全体が消去されます。

手順は次のとおりです。

  1. メインダイアログ
  2. モーダルダイアログを開く
  3. CFileDialogファイルを選択するために開いた
  4. ModalDialog を終了する
  5. ModalDialog を再度開く [背景が消去される]

注 :この問題は、ファイルを選択した場合にのみ発生します。で [キャンセル] をクリックすると、CFileDialog. 問題ありません。

PFB、私のCFileDialog使用のコードスニペット:

//This is the code to Open the DoModal dialog from MainWindow 
//
void CCommonDlg::OnBnClickedButton1()
{

    COSDADlg dlg;
    //m_pMainWnd = &dlg;
    INT_PTR nResponse = dlg.DoModal();
    if (nResponse == IDOK)
    {

    }
    else if (nResponse == IDCANCEL)
    {
        // TODO: Place code here to handle when the dialog is
        //  dismissed with Cancel
    }

}

// This is the code for open CFileDialog from ModalDialog to save file
//
void COSDADlg::OnBnClickedButton1()
{

        CFileDialog dlgFile(FALSE);

        CString fileName;
        dlgFile.GetOFN().lpstrFile = fileName.GetBuffer(FILE_LIST_BUFFER_SIZE);
        dlgFile.GetOFN().nMaxFile = FILE_LIST_BUFFER_SIZE;


        INT_PTR nResult = dlgFile.DoModal();
        fileName.ReleaseBuffer();   

}

//This is the code to paint the background image for ModalDialog
//
void COSDADlg::OnPaint()
{
    CPaintDC dc(this); // device context for painting

    Graphics    graph(dc.m_hDC);
    CRect rt;
    GetWindowRect(&rt);
    graph.DrawImage(m_pImage, (INT)0, (INT)0,  (INT)rt.Width() , (INT)rt.Height() );
    DefWindowProc(WM_PAINT, (WPARAM)dc.m_hDC, (LPARAM)0);

}
4

1 に答える 1

2

問題の背後にある理由を見つけました。

CFileDialog を使用してファイルを保存/選択すると、デフォルトの動作は、実行中のプロセスの WorkingDirectory を変更することです。

このため、新しい場所で背景画像が見つからなかったため、背景が消去されました。

これが起こらないようにするために、作業ディレクトリを保持する CFileDialog で OFN_NOCHANGEDIR フラグを使用する必要があります。

于 2016-11-10T12:59:12.567 に答える