Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1127
  • Last Modified:

How to disable FileName edit box in CFileDialog?

Hi

I am working in VC++. I'm using CFileDialog class for opening files. Here I am allowing the user to open only text and pdf files by providing a filter in the constructor as shown below.

      char szFilter[64];
      memset(szFilter, 0, sizeof(szFilter));
      strcpy(szFilter, "JobDoc File(*.pdf;*.txt)");
      strcpy(&szFilter[strlen(szFilter)+1], "*.pdf;*.txt");

      CFileDialog fileDlg(TRUE, _T("*.pdf"), NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_NOCHANGEDIR, szFilter);
      fileDlg.m_ofn.lpstrFilter = szFilter;
      fileDlg.m_ofn.lpstrTitle = "Browse Job Options File";
      fileDlg.m_ofn.lpstrInitialDir = penDrive;
      fileDlg.m_ofn.lpstrDefExt = _T("pdf");
      fileDlg.m_ofn.Flags |= OFN_NOCHANGEDIR;

Now the problem is, if the user types abc.bin file in the filename edit box on CfileDialog, and clicks on open , it tries to open that file name with that extension. So I want to disable the FileName edit box and allow the user to select & open only files from the displayed list in CFileDialog.

Can you please let me know how to disable the FileName edit box in CFileDialog.

Thanks
0
l_madhavi
Asked:
l_madhavi
  • 3
1 Solution
 
mahesh1402Commented:
may be you need to derive your own file dialog box from CFileDialog and need to disable control ..

-MAHESH
0
 
mahesh1402Commented:
I will suggest you to look at followin thread abt how to customize CFileFialog..
http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_10009026.html

derive your own class from CFileDialog and on InitDialog of your class disable  / enable controls. stc2, stc3, edt1,lst1,cmb1 are control ids of CFileDialog . Refer above for more.


-MAHESH
0
 
mahesh1402Commented:
e.g
//CMyFileDialog is a CFileDialog-derived class
//OnInitDialog is the handler for WM_INITDIALOG
BOOL CMyFileDialog::OnInitDialog()
{
   CFileDialog::OnInitDialog();

   CWnd* pWndParent = GetParent();

   //make sure you add #include <dlgs.h> for IDs 'edt1' & 'stc3'
   //disables the 'file name' edit and static control
   //of the standard file open dialog

   //get handle of 'file name' edit control & disable it
   CWnd* pWnd = pWndParent->GetDlgItem(edt1);
   pWnd->EnableWindow(FALSE);

   //get handle of 'file name' static control & disable it
   pWnd = pWndParent->GetDlgItem(stc3);
   pWnd->EnableWindow(FALSE);
   
   return TRUE;
}

For more source help refer following
http://www.codeproject.com/dialog/select_all_button.asp
http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_10264962.html

-MAHESH
0
 
l_madhaviAuthor Commented:
Thanks Mahesh..my problem is solved..
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now