Query For CFileDialog?
-
hi i m using CFileDialog to open the file. but there is one problem,
CString filter( "Text Files(*.txt)|*.txt||");
CWaitCursor cwt;CFileDialog fileDlg(TRUE, NULL, NULL, OFN\_PATHMUSTEXIST|OFN\_FILEMUSTEXIST|OFN\_HIDEREADONLY,filter,this,0); if (fileDlg.DoModal () == IDCANCEL) { return; } CString OpenFile = fileDlg.GetPathName (); SetDlgItemText(IDC\_PATH,OpenFile);
i want to open only .txt files,so i provide .txt format in filter. but i open the dialog box and enter file name with some other extension its display and open. i want as the list of CFileDialog not display the oher extension file same as its not open the other extension file from File Name field . please help me for this. thanks in advance.
-
hi i m using CFileDialog to open the file. but there is one problem,
CString filter( "Text Files(*.txt)|*.txt||");
CWaitCursor cwt;CFileDialog fileDlg(TRUE, NULL, NULL, OFN\_PATHMUSTEXIST|OFN\_FILEMUSTEXIST|OFN\_HIDEREADONLY,filter,this,0); if (fileDlg.DoModal () == IDCANCEL) { return; } CString OpenFile = fileDlg.GetPathName (); SetDlgItemText(IDC\_PATH,OpenFile);
i want to open only .txt files,so i provide .txt format in filter. but i open the dialog box and enter file name with some other extension its display and open. i want as the list of CFileDialog not display the oher extension file same as its not open the other extension file from File Name field . please help me for this. thanks in advance.
AFAIK, user can type in any name and the file dialog will accept it, you can detect that by deriving your own class from CFileDialog and override some of the members (see the documentation) Originally,
hook
ing was the proper method; but now override is the way to go.Watched code never compiles.
-
hi i m using CFileDialog to open the file. but there is one problem,
CString filter( "Text Files(*.txt)|*.txt||");
CWaitCursor cwt;CFileDialog fileDlg(TRUE, NULL, NULL, OFN\_PATHMUSTEXIST|OFN\_FILEMUSTEXIST|OFN\_HIDEREADONLY,filter,this,0); if (fileDlg.DoModal () == IDCANCEL) { return; } CString OpenFile = fileDlg.GetPathName (); SetDlgItemText(IDC\_PATH,OpenFile);
i want to open only .txt files,so i provide .txt format in filter. but i open the dialog box and enter file name with some other extension its display and open. i want as the list of CFileDialog not display the oher extension file same as its not open the other extension file from File Name field . please help me for this. thanks in advance.
-
hi i m using CFileDialog to open the file. but there is one problem,
CString filter( "Text Files(*.txt)|*.txt||");
CWaitCursor cwt;CFileDialog fileDlg(TRUE, NULL, NULL, OFN\_PATHMUSTEXIST|OFN\_FILEMUSTEXIST|OFN\_HIDEREADONLY,filter,this,0); if (fileDlg.DoModal () == IDCANCEL) { return; } CString OpenFile = fileDlg.GetPathName (); SetDlgItemText(IDC\_PATH,OpenFile);
i want to open only .txt files,so i provide .txt format in filter. but i open the dialog box and enter file name with some other extension its display and open. i want as the list of CFileDialog not display the oher extension file same as its not open the other extension file from File Name field . please help me for this. thanks in advance.
Have you considered something like:
CFileDialog fileDlg(TRUE, NULL, NULL, OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, _T("Text Files(*.txt)|*.txt||"), this);
do
{
if (fileDlg.DoModal () == IDCANCEL)
return;} while (fileDlg.GetFileExt() != _T("txt"));
SetDlgItemText(IDC_PATH, fileDlg.GetPathName());
[edit] Alain's suggestion is a much better solution. [/edit]
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
modified on Thursday, November 4, 2010 11:25 AM
-
hi i m using CFileDialog to open the file. but there is one problem,
CString filter( "Text Files(*.txt)|*.txt||");
CWaitCursor cwt;CFileDialog fileDlg(TRUE, NULL, NULL, OFN\_PATHMUSTEXIST|OFN\_FILEMUSTEXIST|OFN\_HIDEREADONLY,filter,this,0); if (fileDlg.DoModal () == IDCANCEL) { return; } CString OpenFile = fileDlg.GetPathName (); SetDlgItemText(IDC\_PATH,OpenFile);
i want to open only .txt files,so i provide .txt format in filter. but i open the dialog box and enter file name with some other extension its display and open. i want as the list of CFileDialog not display the oher extension file same as its not open the other extension file from File Name field . please help me for this. thanks in advance.
Hi, For custom file name validation derive from
CFileDialog
and override CFileDialog::OnFileNameOK[^]. This function allows you to reject a filename for any application-specific reason. cheers, ARWhen the wise (person) points at the moon the fool looks at the finger (Chinese proverb)