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 thelpstrInitialDir
field it states that: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.If you set the filename location, you can get the dialog to open to a specific location. I would only use this if you really needed the folder location to open or if you have a default filename that you use.
or you could use the Windows function
GetModuleFileName
:Two options: 1. Old-fashioned dialog style, specifying OFN::lpstrInitialDir