Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to disable FileName edit box in CFileDialog?

Posted on 2006-07-04
4
Medium Priority
?
1,103 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
[X]
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
  • 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 500 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

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…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

730 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