Re: Relative Paths (noob question)
Here's how I do it:
CString CMyApp::GetApplicationExecutionFolder()
{
if(m_csAppExecutionFolder.IsEmpty()) {
TCHAR FileName[MAX_PATH];
::GetModuleFileName(AfxGetInstanceHandle(), FileName, MAX_PATH);
m_csAppExecutionFolder = AddSlash(GetFolderOnly(FileName));
}
return m_csAppExecutionFolder;
}
//
// Returns the folder portion from a path
//
CString GetFolderOnly(LPCTSTR Path)
{
// Strip off the file name so we can direct the file scanning dialog to
go
// back to the same directory as before.
CString temp = (LPCTSTR) Path; // Force CString to make a copy
::PathRemoveFileSpec(temp.GetBuffer(0));
temp.ReleaseBuffer(-1);
return temp;
}
Then using this function you can hook on the file you want to run:
//
// Adds a folder path and file together to make a file path
//
CString AddPathAndFile(LPCTSTR Folder, LPCTSTR File)
{
CString cs = Folder;
::PathAddBackslash(cs.GetBuffer(_MAX_PATH));
::PathAppend(cs.GetBuffer(_MAX_PATH),File);
cs.ReleaseBuffer(-1);
return cs;
}
Like:
CString csHTMLFile = AddPathAndFile(GetApplicationExecutionFolder(),
_T("MyFile.htm"));
Of course you'll have to have a CString m_csApplicationExecutionFolder; in
your class.
Tom
"huntedsnark" <maharg@cinci.rr.com> wrote in message
news:1156447703.515482.136560@74g2000cwt.googlegroups.com...
Hi,
I have a small application that displays an html file locally from the
hard drive.
Using Navigate2, I would like to launch the html from the same
directory using a relative path.
Right now I have:
Navigate2(_T("T:\\file.html"),NULL,NULL);
Instead of specifying the drive letter I would just like the program to
look in it's own directory. Is this possible?