初始目录不适用于CFileDialog [英] Initial directory is not working for CFileDialog

查看:116
本文介绍了初始目录不适用于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与应用程序第一次使用OpenSave As对话框时传递的值相同,则将用户最近选择的路径用作初始目录.

If lpstrInitialDir has the same value as was passed the first time the application used an Open or Save 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆