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. CFileDialog OnTypeChange issue

CFileDialog OnTypeChange issue

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionworkspace
4 Posts 2 Posters 1 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.
  • _ Offline
    _ Offline
    _Flaviu
    wrote on last edited by
    #1

    I derived a class from CFileDialog, named CFileDialogExt. Here, I have the following filters: 1.bmp 2.gif 3.jpg 4.png 5.tiff In order to setup the right extension for file name, I override OnTypeChange, just like this:

    void CFileDialogExt::OnTypeChange()
    {
    // TODO: Add your specialized code here and/or call the base class

    switch(GetOFN().nFilterIndex)
    {
    case 1:
    	SetDefExt(\_T("bmp"));
    	break;
    case 2:
    	SetDefExt(\_T("gif"));
    	break;
    case 3:
    	SetDefExt(\_T("jpg"));
    	break;
    case 4:
    	SetDefExt(\_T("png"));
    	break;
    case 5:
    	SetDefExt(\_T("tiff"));
    	break;
    }
    
    CFileDialog::OnTypeChange();
    

    }

    Default type is bmp. So, I type "aaa" as file name. Then, I change the type (from combo type), as gif. The file name is still "aaa". Then, I change again as jpg, the file name is changed as "aaa.gif" !! Is delayed by one changing ... strange ... why ? Furthermore, I change extension as tiff, the file name is "aaa.jpg", not "aaa.tiff" .... I have done something wrong here ?

    _ M 2 Replies Last reply
    0
    • _ _Flaviu

      I derived a class from CFileDialog, named CFileDialogExt. Here, I have the following filters: 1.bmp 2.gif 3.jpg 4.png 5.tiff In order to setup the right extension for file name, I override OnTypeChange, just like this:

      void CFileDialogExt::OnTypeChange()
      {
      // TODO: Add your specialized code here and/or call the base class

      switch(GetOFN().nFilterIndex)
      {
      case 1:
      	SetDefExt(\_T("bmp"));
      	break;
      case 2:
      	SetDefExt(\_T("gif"));
      	break;
      case 3:
      	SetDefExt(\_T("jpg"));
      	break;
      case 4:
      	SetDefExt(\_T("png"));
      	break;
      case 5:
      	SetDefExt(\_T("tiff"));
      	break;
      }
      
      CFileDialog::OnTypeChange();
      

      }

      Default type is bmp. So, I type "aaa" as file name. Then, I change the type (from combo type), as gif. The file name is still "aaa". Then, I change again as jpg, the file name is changed as "aaa.gif" !! Is delayed by one changing ... strange ... why ? Furthermore, I change extension as tiff, the file name is "aaa.jpg", not "aaa.tiff" .... I have done something wrong here ?

      _ Offline
      _ Offline
      _Flaviu
      wrote on last edited by
      #2

      Maybe if I could get a pointer to CComboBox from CFileDialog, I can find more about this problem ... but I can not ... I tried this:

      void CFileDialogExt::OnTypeChange()
      {
      // TODO: Add your specialized code here and/or call the base class

      CString sTemp;
      CComboBox\* pCombo = (CComboBox\*)GetDlgItem(cmb1);
      if(NULL != pCombo->GetSafeHwnd())
      {
      	int nIndex = pCombo->GetCurSel();
      	if(CB\_ERR != nIndex)
      		pCombo->GetLBText(nIndex, sTemp);
      }
      

      TRACE(">>>%s\n", sTemp);
      switch(GetOFN().nFilterIndex)
      {
      case 1:
      SetDefExt(_T("bmp"));
      break;
      case 2:
      SetDefExt(_T("gif"));
      break;
      case 3:
      SetDefExt(_T("jpg"));
      break;
      case 4:
      SetDefExt(_T("png"));
      break;
      case 5:
      SetDefExt(_T("tiff"));
      break;
      case 6:
      SetDefExt(_T("dcm"));
      break;
      }

      CFileDialog::OnTypeChange();
      

      }

      but pCombo seem to be null ...

      1 Reply Last reply
      0
      • _ _Flaviu

        I derived a class from CFileDialog, named CFileDialogExt. Here, I have the following filters: 1.bmp 2.gif 3.jpg 4.png 5.tiff In order to setup the right extension for file name, I override OnTypeChange, just like this:

        void CFileDialogExt::OnTypeChange()
        {
        // TODO: Add your specialized code here and/or call the base class

        switch(GetOFN().nFilterIndex)
        {
        case 1:
        	SetDefExt(\_T("bmp"));
        	break;
        case 2:
        	SetDefExt(\_T("gif"));
        	break;
        case 3:
        	SetDefExt(\_T("jpg"));
        	break;
        case 4:
        	SetDefExt(\_T("png"));
        	break;
        case 5:
        	SetDefExt(\_T("tiff"));
        	break;
        }
        
        CFileDialog::OnTypeChange();
        

        }

        Default type is bmp. So, I type "aaa" as file name. Then, I change the type (from combo type), as gif. The file name is still "aaa". Then, I change again as jpg, the file name is changed as "aaa.gif" !! Is delayed by one changing ... strange ... why ? Furthermore, I change extension as tiff, the file name is "aaa.jpg", not "aaa.tiff" .... I have done something wrong here ?

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

        We do something similar. In the OnTypeChange virtual method: We have a external list of extension (external to the file dialog) We get the selected filter extension (m_ofn.nFilterIndex). We get the current filename (GetFileName()) Extract the filename without extension and replace with the new extension and call this :

        // This only works is the bVistaStyle flag is set to false in the CFileDialog constructor.
        SetControlText(edt1, fileNameNoExtension ); // edt1 is undocumented.

        This will change the name of the file in the file dialog editbox. Good luck.

        I'd rather be phishing!

        _ 1 Reply Last reply
        0
        • M Maximilien

          We do something similar. In the OnTypeChange virtual method: We have a external list of extension (external to the file dialog) We get the selected filter extension (m_ofn.nFilterIndex). We get the current filename (GetFileName()) Extract the filename without extension and replace with the new extension and call this :

          // This only works is the bVistaStyle flag is set to false in the CFileDialog constructor.
          SetControlText(edt1, fileNameNoExtension ); // edt1 is undocumented.

          This will change the name of the file in the file dialog editbox. Good luck.

          I'd rather be phishing!

          _ Offline
          _ Offline
          _Flaviu
          wrote on last edited by
          #4

          Yes, there is a solution, but the file dialog has an old style ...

          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