Link to home
Start Free TrialLog in
Avatar of l_madhavi
l_madhavi

asked on

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
Avatar of mahesh1402
mahesh1402
Flag of India image

may be you need to derive your own file dialog box from CFileDialog and need to disable control ..

-MAHESH
I will suggest you to look at followin thread abt how to customize CFileFialog..
https://www.experts-exchange.com/questions/10009026/Customization-of-File-Open-Dialog.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
ASKER CERTIFIED SOLUTION
Avatar of mahesh1402
mahesh1402
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of l_madhavi
l_madhavi

ASKER

Thanks Mahesh..my problem is solved..