我CFileDialog
在代码中使用时遇到问题。
当我CFileDialog
从 ModalDialog 调用时,选择一个文件。退出并重新打开当前视图后,我的整个 ModalDialog 背景都会被删除。
遵循的程序:
- 主对话框
- 打开的模态对话框
- 打开
CFileDialog
用于选择文件 - 退出模态对话框
- 重新打开 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);
}