建立了打开对话框后,第一次使用一般都显示“我的文档”哪个目录,以后可能显示最近一次使用的目录,请问有没有办法将它显示的目录固定下来呢?
例如我的软件安装在C:\software下面,每次打开文件的操作都肯定是针对C:\software\temp下的文件,所以我希望固定下来,让打开对话框每次显示时都是直接显示C:\software\temp的那些东西。MSDN上好像没有写。
谢谢了!!!!!!!!!!!!!!!
例如我的软件安装在C:\software下面,每次打开文件的操作都肯定是针对C:\software\temp下的文件,所以我希望固定下来,让打开对话框每次显示时都是直接显示C:\software\temp的那些东西。MSDN上好像没有写。
谢谢了!!!!!!!!!!!!!!!
如:m_ofn.lpstrInitialDir = "C:\software\temp";
typedef struct tagOFN {
DWORD lStructSize;
HWND hwndOwner;
HINSTANCE hInstance;
LPCTSTR lpstrFilter;
LPTSTR lpstrCustomFilter;
DWORD nMaxCustFilter;
DWORD nFilterIndex;
LPTSTR lpstrFile;
DWORD nMaxFile;
LPTSTR lpstrFileTitle;
DWORD nMaxFileTitle;
LPCTSTR lpstrInitialDir; ///这个地方设置成你的初始目录就可以了
LPCTSTR lpstrTitle;
DWORD Flags;
WORD nFileOffset;
WORD nFileExtension;
LPCTSTR lpstrDefExt;
LPARAM lCustData;
LPOFNHOOKPROC lpfnHook;
LPCTSTR lpTemplateName;
#if (_WIN32_WINNT >= 0x0500)
void * pvReserved;
DWORD dwReserved;
DWORD FlagsEx;
#endif // (_WIN32_WINNT >= 0x0500)
} OPENFILENAME, *LPOPENFILENAME;
********** this line *********
dlg.m_ofn.lpstrInitialDir=(LPCTSTR)sCurPath;//初始化最初的路径。
******************************void CTaxonomyView::OnOpenTaxonomies()
{
CString sFilter;
sFilter="XML文件(*.xml)|*.xml";
sFilter+="|所有文件(*.*)|*.*||";
CFileDialog dlg(true, NULL, NULL, 0, (LPCSTR)sFilter);
dlg.m_ofn.Flags|=OFN_ALLOWMULTISELECT|OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_LONGNAMES|OFN_PATHMUSTEXIST;
char buf[20480] = "";
dlg.m_ofn.lpstrFile = buf;
dlg.m_ofn.nMaxFile=20480;
dlg.m_ofn.lpstrTitle="打开分类法文件"; //先获得模板文件存放路径,与exe文件同路径下
CString paths=AfxGetApp()->m_pszHelpFilePath ;
char sCurPath[256];
int pos=paths.ReverseFind('\\');
paths=paths.Left(pos);
strcpy(sCurPath,paths);
strcat(sCurPath,"\\Taxonomies\\"); dlg.m_ofn.lpstrInitialDir=(LPCTSTR)sCurPath;//初始化最初的路径。
int ret=dlg.DoModal();
if(ret!=IDOK)
{
return;
}
CStringArray sarrFileName;
POSITION pos1;
pos1=dlg.GetStartPosition();
if(pos1==NULL)return;
CString sPath;
while(pos1!=NULL)
{
sPath=dlg.GetNextPathName(pos1);
sarrFileName.Add(sPath);
}
//CStringArray& sarrNames
FillTreeClassView(sarrFileName, false);
}