CFileDialog
-
Hi I am using CfileDialog, but i cant get it to display pointing to the correct directory it seems to ignore the path that i pass im using TCHAR szFilters[] = _T ("Log Files (*.txt)|*.txt|All files (*.*)|*.*||"); CFileDialog dlg(TRUE, _T ("txt"), _T ("*.txt"),NULL, szFilters); CString MyPath "c:\"; if (logPath.GetLength()) dlg.GetOFN().lpstrInitialDir = MyPath; if (dlg.DoModal()==TRUE) { CString result = dlg.GetPathName(); ShellExecute(NULL, "Open", _T(result), NULL, NULL, SW_SHOW); } can anyone help thanks simon
-
Hi I am using CfileDialog, but i cant get it to display pointing to the correct directory it seems to ignore the path that i pass im using TCHAR szFilters[] = _T ("Log Files (*.txt)|*.txt|All files (*.*)|*.*||"); CFileDialog dlg(TRUE, _T ("txt"), _T ("*.txt"),NULL, szFilters); CString MyPath "c:\"; if (logPath.GetLength()) dlg.GetOFN().lpstrInitialDir = MyPath; if (dlg.DoModal()==TRUE) { CString result = dlg.GetPathName(); ShellExecute(NULL, "Open", _T(result), NULL, NULL, SW_SHOW); } can anyone help thanks simon
Try
CString MyPath = "C:\\"
"There are those who confuse bad management with fate"
-
Hi I am using CfileDialog, but i cant get it to display pointing to the correct directory it seems to ignore the path that i pass im using TCHAR szFilters[] = _T ("Log Files (*.txt)|*.txt|All files (*.*)|*.*||"); CFileDialog dlg(TRUE, _T ("txt"), _T ("*.txt"),NULL, szFilters); CString MyPath "c:\"; if (logPath.GetLength()) dlg.GetOFN().lpstrInitialDir = MyPath; if (dlg.DoModal()==TRUE) { CString result = dlg.GetPathName(); ShellExecute(NULL, "Open", _T(result), NULL, NULL, SW_SHOW); } can anyone help thanks simon
String MyPath "c:\";
is invalid.**'\'**
is the escape character, so if you want to print a \, you must specify '\\'CString MyPath = "C:\\";
One last thing.
if (dlg.DoModal()==TRUE)
is not syntactically correct.CDialog::DoModal()
doesn't return a BOOL (TRUE or FALSE). it returns the exit code specified in the dialog with the call toCDialog::EndDialog()
. In general, it is the ID of the buttons pressed, so you should test your CFileDialog with eitherIDOK
orIDCANCEL
.if (dlg.DoModal() == IDOK)
-- modified at 9:30 Wednesday 27th September, 2006
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
Hi I am using CfileDialog, but i cant get it to display pointing to the correct directory it seems to ignore the path that i pass im using TCHAR szFilters[] = _T ("Log Files (*.txt)|*.txt|All files (*.*)|*.*||"); CFileDialog dlg(TRUE, _T ("txt"), _T ("*.txt"),NULL, szFilters); CString MyPath "c:\"; if (logPath.GetLength()) dlg.GetOFN().lpstrInitialDir = MyPath; if (dlg.DoModal()==TRUE) { CString result = dlg.GetPathName(); ShellExecute(NULL, "Open", _T(result), NULL, NULL, SW_SHOW); } can anyone help thanks simon
-
Try
CString MyPath = "C:\\"
"There are those who confuse bad management with fate"
-
did you read my answer ? does it provide much help ?
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
Hi I am using CfileDialog, but i cant get it to display pointing to the correct directory it seems to ignore the path that i pass im using TCHAR szFilters[] = _T ("Log Files (*.txt)|*.txt|All files (*.*)|*.*||"); CFileDialog dlg(TRUE, _T ("txt"), _T ("*.txt"),NULL, szFilters); CString MyPath "c:\"; if (logPath.GetLength()) dlg.GetOFN().lpstrInitialDir = MyPath; if (dlg.DoModal()==TRUE) { CString result = dlg.GetPathName(); ShellExecute(NULL, "Open", _T(result), NULL, NULL, SW_SHOW); } can anyone help thanks simon
si_69 wrote:
CString MyPath "c:\";
This is a syntax error.
si_69 wrote:
if (logPath.GetLength())
What is
logPath
?si_69 wrote:
dlg.GetOFN().lpstrInitialDir = MyPath;
Since
GetOFN()
does not exist with VC++ v6, I usedm_ofn
instead. Other than that, this code works fine. Do not usestrcpy()
, as you simply need to assign a pointer to an existing address.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
You can use from Data Member
m_ofn
In CFileDialog that you have access to parameters of dialogbox
WhiteSky