初始目录不适用于CFileDialog [英] Initial directory is not working for CFileDialog
问题描述
我正在使用CFileDialog,我已经设置了如下所示的初始路径,如代码所示.它不起作用.如果我做错了,请纠正我.
I am using CFileDialog, I have set the initial path like below , as shown in the code. It's not working . Correct me if I made a mistake.
CFileDialog* filedlg = new CFileDialog(TRUE,(LPCTSTR)NULL , (LPCTSTR)NULL , OFN_HIDEREADONLY| OFN_ENABLESIZING , (LPCTSTR)NULL , FromHandle (hImgDlg) ,0 , FALSE );
filedlg ->m_ofn.lpstrInitialDir = "C:\\" ;
if ( filedlg ->DoModal() == IDOK )
{
/*** do somthing here *****/
}
推荐答案
If you see the reference for the OPENFILENAME
structure, you will see that for the lpstrInitialDir
field it states that:
如果
lpstrInitialDir
与应用程序第一次使用Open
或Save As
对话框时传递的值相同,则将用户最近选择的路径用作初始目录.
If
lpstrInitialDir
has the same value as was passed the first time the application used anOpen
orSave As
dialog box, the path most recently selected by the user is used as the initial directory.
这意味着lpstrInitialDir
字段实际上只能在您第一次在程序中使用对话框时使用.其余时间将使用用户选择的最后一个目录.
This means that the lpstrInitialDir
field can really only be used the first time you use the dialog in a program. The rest of the time it will use the last directory selected by the user.
这篇关于初始目录不适用于CFileDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!