问题描述
我在代码中使用 CFileDialog时遇到问题。
I am facing an issue using CFileDialog in my code.
   当我从ModalDialog调用 CFileDialog时,选择一个文件。退出当前视图并重新打开后,我的整个ModalDialog背景都会被删除。
When I call the CFileDialog from ModalDialog, to select a file. My whole ModalDialog background gets erased once the current view is exited and reopened.
程序遵循:
Procedure followed:
- 主对话
- 打开ModalDialog
- 打开 CFileDialog 用于选择文件
- 退出ModalDialog
- 重新打开ModalDialo g [背景被删除]
注意: 此问题仅发生在WINPE环境中,如果我使用CFlieDialog选择文件。如果我在 CFileDialog中点击取消。没有问题。
Note : This issue happens only WINPE environment and if I select a file using CFlieDialog. If I click on Cancel in the CFileDialog. There is no issue.
PFB,我的CFileDialog的代码片段 使用:
PFB, the code snippet of my CFileDialog use:
//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);
}
它似乎不是绘画问题,它与winPE CFileDialog。它按预期工作当我在Windows 8.1上运行此代码时
It is not seems to be painting issue and it is related to winPE CFileDialog. It is working as expected When I run this code on my Windows 8.1
推荐答案
感谢您在此发布。
>>它似乎不是绘画问题,它与winPE有关CFileDialog的。当我在Windows 8.1上运行此代码时它按预期工作
在WinPE中,一些基本的Visual Studio项目设置可能与Visual Studio项目向导创建的默认设置不同。确保设置项目的构建设置以生成与Windows PE兼容的应用程序和DLL,如下所示:
In WinPE, some basic Visual Studio project settings may be different from the defaults created by the Visual Studio Project Wizard. Ensure that you set up your project’s build settings to produce apps and DLLs that are compatible with Windows PE, as follows:
1.您必须开发具有本机C或C ++代码的Windows PE应用程序不使用MFC或ATL。因此,如果您使用Visual Studio项目向导,请选择Win32项目并确保未选中MFC和ATL。
1.You must develop Windows PE apps with native C or C++ code that does not use MFC or ATL. Therefore, if you use the Visual Studio Project Wizard, choose a Win32 project and make sure that neither MFC nor ATL are checked.
2.设置项目选项以链接到静态C / C ++运行时库,而不是Msvcrt.dll的.dll版本。
2.Set your project options to link to the static C/C++ runtime libraries, not the .dll version of Msvcrt.dll.
...
有关详细信息,请参阅此文档。
For more information, please refer to this document.
最好的问候,
Sera Yu
这篇关于绘制CFileDialog在WinPE上运行时的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!