Solved

How to disable FileName edit box in CFileDialog?

Posted on 2006-07-04
4
1,005 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now