Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Query For CFileDialog?

Query For CFileDialog?

Scheduled Pinned Locked Moved C / C++ / MFC
helpdatabasequestion
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Le rner
    wrote on last edited by
    #1

    hi i m using CFileDialog to open the file. but there is one problem,

    CString filter( "Text Files(*.txt)|*.txt||");
    CWaitCursor cwt;

    	CFileDialog fileDlg(TRUE, NULL, NULL, OFN\_PATHMUSTEXIST|OFN\_FILEMUSTEXIST|OFN\_HIDEREADONLY,filter,this,0);
    
    	if (fileDlg.DoModal () == IDCANCEL) 
    	{
    		return;
    	}
    			CString OpenFile = fileDlg.GetPathName ();
    
    	SetDlgItemText(IDC\_PATH,OpenFile);
    

    i want to open only .txt files,so i provide .txt format in filter. but i open the dialog box and enter file name with some other extension its display and open. i want as the list of CFileDialog not display the oher extension file same as its not open the other extension file from File Name field . please help me for this. thanks in advance.

    M G D A 4 Replies Last reply
    0
    • L Le rner

      hi i m using CFileDialog to open the file. but there is one problem,

      CString filter( "Text Files(*.txt)|*.txt||");
      CWaitCursor cwt;

      	CFileDialog fileDlg(TRUE, NULL, NULL, OFN\_PATHMUSTEXIST|OFN\_FILEMUSTEXIST|OFN\_HIDEREADONLY,filter,this,0);
      
      	if (fileDlg.DoModal () == IDCANCEL) 
      	{
      		return;
      	}
      			CString OpenFile = fileDlg.GetPathName ();
      
      	SetDlgItemText(IDC\_PATH,OpenFile);
      

      i want to open only .txt files,so i provide .txt format in filter. but i open the dialog box and enter file name with some other extension its display and open. i want as the list of CFileDialog not display the oher extension file same as its not open the other extension file from File Name field . please help me for this. thanks in advance.

      M Offline
      M Offline
      Maximilien
      wrote on last edited by
      #2

      AFAIK, user can type in any name and the file dialog will accept it, you can detect that by deriving your own class from CFileDialog and override some of the members (see the documentation) Originally, hooking was the proper method; but now override is the way to go.

      Watched code never compiles.

      1 Reply Last reply
      0
      • L Le rner

        hi i m using CFileDialog to open the file. but there is one problem,

        CString filter( "Text Files(*.txt)|*.txt||");
        CWaitCursor cwt;

        	CFileDialog fileDlg(TRUE, NULL, NULL, OFN\_PATHMUSTEXIST|OFN\_FILEMUSTEXIST|OFN\_HIDEREADONLY,filter,this,0);
        
        	if (fileDlg.DoModal () == IDCANCEL) 
        	{
        		return;
        	}
        			CString OpenFile = fileDlg.GetPathName ();
        
        	SetDlgItemText(IDC\_PATH,OpenFile);
        

        i want to open only .txt files,so i provide .txt format in filter. but i open the dialog box and enter file name with some other extension its display and open. i want as the list of CFileDialog not display the oher extension file same as its not open the other extension file from File Name field . please help me for this. thanks in advance.

        G Offline
        G Offline
        GAJERA
        wrote on last edited by
        #3

        Override the CFileDialog http://www.codeguru.com/cpp/w-d/dislog/commondialogs/article.php/c1933[^]

        1 Reply Last reply
        0
        • L Le rner

          hi i m using CFileDialog to open the file. but there is one problem,

          CString filter( "Text Files(*.txt)|*.txt||");
          CWaitCursor cwt;

          	CFileDialog fileDlg(TRUE, NULL, NULL, OFN\_PATHMUSTEXIST|OFN\_FILEMUSTEXIST|OFN\_HIDEREADONLY,filter,this,0);
          
          	if (fileDlg.DoModal () == IDCANCEL) 
          	{
          		return;
          	}
          			CString OpenFile = fileDlg.GetPathName ();
          
          	SetDlgItemText(IDC\_PATH,OpenFile);
          

          i want to open only .txt files,so i provide .txt format in filter. but i open the dialog box and enter file name with some other extension its display and open. i want as the list of CFileDialog not display the oher extension file same as its not open the other extension file from File Name field . please help me for this. thanks in advance.

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Have you considered something like:

          CFileDialog fileDlg(TRUE, NULL, NULL, OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, _T("Text Files(*.txt)|*.txt||"), this);

          do
          {
          if (fileDlg.DoModal () == IDCANCEL)
          return;

          } while (fileDlg.GetFileExt() != _T("txt"));

          SetDlgItemText(IDC_PATH, fileDlg.GetPathName());

          [edit] Alain's suggestion is a much better solution. [/edit]

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "Man who follows car will be exhausted." - Confucius

          modified on Thursday, November 4, 2010 11:25 AM

          1 Reply Last reply
          0
          • L Le rner

            hi i m using CFileDialog to open the file. but there is one problem,

            CString filter( "Text Files(*.txt)|*.txt||");
            CWaitCursor cwt;

            	CFileDialog fileDlg(TRUE, NULL, NULL, OFN\_PATHMUSTEXIST|OFN\_FILEMUSTEXIST|OFN\_HIDEREADONLY,filter,this,0);
            
            	if (fileDlg.DoModal () == IDCANCEL) 
            	{
            		return;
            	}
            			CString OpenFile = fileDlg.GetPathName ();
            
            	SetDlgItemText(IDC\_PATH,OpenFile);
            

            i want to open only .txt files,so i provide .txt format in filter. but i open the dialog box and enter file name with some other extension its display and open. i want as the list of CFileDialog not display the oher extension file same as its not open the other extension file from File Name field . please help me for this. thanks in advance.

            A Offline
            A Offline
            Alain Rist
            wrote on last edited by
            #5

            Hi, For custom file name validation derive from CFileDialog and override CFileDialog::OnFileNameOK[^]. This function allows you to reject a filename for any application-specific reason. cheers, AR

            When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups