Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting pathname for CFileDialog box 1

Status
Not open for further replies.

BM

Programmer
Apr 26, 2000
27
GB
I would like to set the pathname for a CFileDialog box so that the directory is the same as that in which the .exe file resides.&nbsp;&nbsp;Is there a neat way of setting up the pathname in the CFileDialog statement to avoid the default?<br><br>Barry M<br>
 
Dear BM,<br><br>From the online MSDN documentation at msdn.microsoft.com<br><br>m_ofn is a structure of type OPENFILENAME. Use this structure to initialize the appearance of a File Open or File Save As dialog box after it is constructed but before it is displayed with the DoModal member function. For example, you can set the lpstrTitle member of m_ofn to the caption you want the dialog box to have.<br><br>For more information, see the OPENFILENAME structure in the Win32 SDK documentation. <br><br>--------------------------------<br><br>You can set the m_ofn.lpstrInitialDir member to a complete path before calling DoModal().<br><br>Good luck
 
Hi palbano,<br>Thanks for your reply.&nbsp;&nbsp;I have looked at the m_ofn info but <br>it does not explain the lpstrInitialDir parameter enough for<br>me to do what I want.&nbsp;&nbsp;The problem is that, if I place my .exe file in a different directory to that in which it was compiled, how do I indicate to Windows that this is the<br>directory I wish to appear in the 'Look in' box.<br><br>Thanks again<br><br>Barry<br>
 
Dear BM,<br><br>I'm having a little trouble understanding what you are attempting to state as the problem and what your desired affect exactly is.<br><br>Running my applications on NT 4 the 'look-in' combobox on the File Open dialog is always defaulted to the folder in which the .exe file resides, even if it is different from the project folder. As in:<br><br>'Project folder path'<br>C:\Files\Engineering\Projects\Rnd\PHog<br>&nbsp;&nbsp;&nbsp;&nbsp;When executed in debug mode from the VC++ IDE this is the folder that is opened in the 'Open File' dialog.<br><br>'Debug build executable folder'<br>C:\Files\Engineering\Projects\Rnd\PHog\Debug<br>&nbsp;&nbsp;&nbsp;&nbsp;When executing the phog.exe from Windows Explorer then this is the folder that is selected when the 'Open File' dialog is displayed.<br><br>Now copy the phog.exe to here:<br>C:\Files\Engineering<br>&nbsp;&nbsp;&nbsp;&nbsp;When executing the phog.exe from Windows Exporer that resides in this folder the 'Open File' dialogs default folder is 'C:\Files\Engineering' since that is the folder the process loaded the file from.<br><br>If you want to set the default folder to a specific location all you do is this:<br><br>&nbsp;&nbsp;CFileDialog dlg(true);<br>&nbsp;&nbsp;dlg.m_ofn.lpstrInitialDir = &quot;C:\\Files&quot;;<br>&nbsp;&nbsp;dlg.DoModal();<br><br>Hope this helps<br>-pete<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top