jeurk
asked on
feedback in an file opendialog ?
Hi,
How can I call an openfiledialog in visual studio 6
is it CFiledialog.dodialog ?
This is not the most important.
What I want is that whan the user selects a file I want
that my dialog box is notifyed of the thing. Because I
want to disable the ok button when the selected file is not appropriate.
Please I need source code, that I only have to cut and paste
or a sample project.
What I want.
Open a file dialog in MFC when I select a certain file
let's say c:\windows\system.ini the ok button should be disabled.
thanks in advance for your help.
How can I call an openfiledialog in visual studio 6
is it CFiledialog.dodialog ?
This is not the most important.
What I want is that whan the user selects a file I want
that my dialog box is notifyed of the thing. Because I
want to disable the ok button when the selected file is not appropriate.
Please I need source code, that I only have to cut and paste
or a sample project.
What I want.
Open a file dialog in MFC when I select a certain file
let's say c:\windows\system.ini the ok button should be disabled.
thanks in advance for your help.
ASKER
Hello,
it's nice that you took some time to answer that question.
but I'd like to do it in the tricky way. I can see that you know what there is to
do. Would you please do it for me ? I tryed to use the class wizard to derivate from
a CFileDialog but I can't find a valuable message to catch.
Please, i need this badly and I'm unable to do it. This would give you an A, if the
answer is exactly what I want. If yo want some more points let me know.
it's nice that you took some time to answer that question.
but I'd like to do it in the tricky way. I can see that you know what there is to
do. Would you please do it for me ? I tryed to use the class wizard to derivate from
a CFileDialog but I can't find a valuable message to catch.
Please, i need this badly and I'm unable to do it. This would give you an A, if the
answer is exactly what I want. If yo want some more points let me know.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is exactly what I wanted. Thanks.
thanks to you too nil_dib.
I'm pasting part of the solution here for the others to read.
Thanks again.
////////////////////////// ////////// ////////// ////////// ////////// ////////// /
// CCustomFileDialog
IMPLEMENT_DYNAMIC(CCustomF ileDialog, CFileDialog)
CCustomFileDialog::CCustom FileDialog (BOOL bOpenFileDialog, LPCTSTR lpszDefExt, LPCTSTR lpszFileName,
DWORD dwFlags, LPCTSTR lpszFilter, CWnd* pParentWnd) :
CFileDialog(bOpenFileDialo g, lpszDefExt, lpszFileName, dwFlags, lpszFilter, pParentWnd)
{
}
BEGIN_MESSAGE_MAP(CCustomF ileDialog, CFileDialog)
//{{AFX_MSG_MAP(CCustomFil eDialog)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
ON_NOTIFY_RANGE(CDN_SELCHA NGE,0,6553 5,OnSelCha nge)
END_MESSAGE_MAP()
void CCustomFileDialog::OnSelCh ange(UINT id, NMHDR* pNotifyStruct, LRESULT* pResult)
{
OFNOTIFY *pData=(OFNOTIFY*)pNotifyS truct;
CString strSelExt=GetFileExt();
CWnd *pOkBtn=GetParent()->GetDl gItem(IDOK );
if(pOkBtn==NULL) return;
if(strSelExt.CompareNoCase ("INI")==0 )
pOkBtn->EnableWindow(FALSE );
else
pOkBtn->EnableWindow(TRUE) ;
}
thanks to you too nil_dib.
I'm pasting part of the solution here for the others to read.
Thanks again.
//////////////////////////
// CCustomFileDialog
IMPLEMENT_DYNAMIC(CCustomF
CCustomFileDialog::CCustom
DWORD dwFlags, LPCTSTR lpszFilter, CWnd* pParentWnd) :
CFileDialog(bOpenFileDialo
{
}
BEGIN_MESSAGE_MAP(CCustomF
//{{AFX_MSG_MAP(CCustomFil
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
ON_NOTIFY_RANGE(CDN_SELCHA
END_MESSAGE_MAP()
void CCustomFileDialog::OnSelCh
{
OFNOTIFY *pData=(OFNOTIFY*)pNotifyS
CString strSelExt=GetFileExt();
CWnd *pOkBtn=GetParent()->GetDl
if(pOkBtn==NULL) return;
if(strSelExt.CompareNoCase
pOkBtn->EnableWindow(FALSE
else
pOkBtn->EnableWindow(TRUE)
}
CFileDialog myDlg( TRUE, "*.*", "*.*", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_EXPLORER, "All files", NULL);
if(myDlg.DoModal() == IDOK)
{ .....
The second question is a bit tricky. You have to catch the message of a file selction from the user. Therefore you have to
derive your own class from CFileDialog, catch the "file selected"
message (you have to override "OnFileNameChange" method), and disable the "Ok" button ( GetDlgItem(IDOK)->DisableW
But the much easyer way is to check the filename AFTER the user
pressed the "OK" button, and to display a message box is case of
a wrong file.
CFileDialog myDlg( TRUE, "*.*", "*.*", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_EXPLORER, "All files", NULL);
if(myDlg.DoModal() == IDOK)
{
CString csFile = myDlg.GetPathName();
if( csFile == "c:\windows\system.ini" )
AfxMessageBox( "File invalid" );
else
// do something csFile
......
}