我在代码中使用CFileDialog面临一个问题。
当我从CFileDialog调用ModalDialog时,选择一个文件。一旦退出并重新打开当前视图,我的整个ModalDialog背景就会被擦除。
所遵循的程序:
CFileDialog以选择文件注意:只有当我选择一个文件时,才会出现这个问题。如果我单击CFileDialog中的Cancel。没有问题。
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);
}发布于 2016-11-10 12:59:12
我已经找到了这个问题背后的原因。
当我们使用CFileDialog保存/选择文件时,默认行为是更改正在运行的进程的WorkingDirectory。
由于这一点,背景图像无法在新的位置找到,因此背景被删除。
为了确保不发生这种情况,我们需要在OFN_NOCHANGEDIR中使用CFileDialog标志,它保留了工作目录。
https://stackoverflow.com/questions/40278875
复制相似问题