Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to disable FileName edit box in CFileDialog?

Posted on 2006-07-04
4
1,038 Views
Last Modified: 2013-11-20
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
Comment
Question by:l_madhavi
  • 3
4 Comments
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17040507
may be you need to derive your own file dialog box from CFileDialog and need to disable control ..

-MAHESH
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17040527
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
 
LVL 22

Accepted Solution

by:
mahesh1402 earned 125 total points
ID: 17040550
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
 

Author Comment

by:l_madhavi
ID: 17041363
Thanks Mahesh..my problem is solved..
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Strange date stored 22 150
Expand data scrubbing tool 13 35
List out all word 7 316
Not needed 13 119
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question