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. Change Dir inside CFileDialog

Change Dir inside CFileDialog

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
28 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.
  • U Offline
    U Offline
    User 401087
    wrote on last edited by
    #1

    Hi everyone, I have a problem in vc6. In a CFileDialog with 2 configured extensions (eg .Txt and .doc) I want automatically change directory in my CFileDialog when the extension changes: when I select the .txt extension I want the CFileDialog in the 'C:\FileTxt' directory, when instead I select the extension .doc I want the CFileDialog in the directory 'C:\FileDoc' with the corresponding files list ... ...Can someone help me with some example? Thank you

    I Try, but I'm not sure :))

    CPalliniC L L V 4 Replies Last reply
    0
    • U User 401087

      Hi everyone, I have a problem in vc6. In a CFileDialog with 2 configured extensions (eg .Txt and .doc) I want automatically change directory in my CFileDialog when the extension changes: when I select the .txt extension I want the CFileDialog in the 'C:\FileTxt' directory, when instead I select the extension .doc I want the CFileDialog in the directory 'C:\FileDoc' with the corresponding files list ... ...Can someone help me with some example? Thank you

      I Try, but I'm not sure :))

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      I don't get you. I mean, the user once the file dialog is open, chooses both the folder and the file extension (by choosing an allowed file). What do you want to do, instead?

      In testa che avete, signor di Ceprano?

      U 1 Reply Last reply
      0
      • CPalliniC CPallini

        I don't get you. I mean, the user once the file dialog is open, chooses both the folder and the file extension (by choosing an allowed file). What do you want to do, instead?

        U Offline
        U Offline
        User 401087
        wrote on last edited by
        #3

        I want that automatically when I change the extension of the files I want to see, the dialog automatically also change the folder of the list of files. The '.txt' files are in one folder, the '.doc' files in another ...

        I Try, but I'm not sure :))

        CPalliniC 1 Reply Last reply
        0
        • U User 401087

          I want that automatically when I change the extension of the files I want to see, the dialog automatically also change the folder of the list of files. The '.txt' files are in one folder, the '.doc' files in another ...

          I Try, but I'm not sure :))

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          Ok but... How do you change the extension of the files you wanto to see?

          In testa che avete, signor di Ceprano?

          U 1 Reply Last reply
          0
          • U User 401087

            Hi everyone, I have a problem in vc6. In a CFileDialog with 2 configured extensions (eg .Txt and .doc) I want automatically change directory in my CFileDialog when the extension changes: when I select the .txt extension I want the CFileDialog in the 'C:\FileTxt' directory, when instead I select the extension .doc I want the CFileDialog in the directory 'C:\FileDoc' with the corresponding files list ... ...Can someone help me with some example? Thank you

            I Try, but I'm not sure :))

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            CFileDialog Class - ontypechange[^]

            U 1 Reply Last reply
            0
            • CPalliniC CPallini

              Ok but... How do you change the extension of the files you wanto to see?

              U Offline
              U Offline
              User 401087
              wrote on last edited by
              #6

              in the Combo box that appared in CFileDialog when I configure more extension, I intercept the OnTypeChange() and in this routine I want change the dir...

              I Try, but I'm not sure :))

              CPalliniC 1 Reply Last reply
              0
              • L Lost User

                CFileDialog Class - ontypechange[^]

                U Offline
                U Offline
                User 401087
                wrote on last edited by
                #7

                Thank's Richard, I have see the class... I have that routine and in that routine I want change the dir. Different dir for different extension.

                I Try, but I'm not sure :))

                L 1 Reply Last reply
                0
                • U User 401087

                  Thank's Richard, I have see the class... I have that routine and in that routine I want change the dir. Different dir for different extension.

                  I Try, but I'm not sure :))

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Then you need to handle the notification message, as documented in that link.

                  U 1 Reply Last reply
                  0
                  • L Lost User

                    Then you need to handle the notification message, as documented in that link.

                    U Offline
                    U Offline
                    User 401087
                    wrote on last edited by
                    #9

                    Thank's Richard, I'm using VC6++ and I need a simple example to understand.. my OnTypeChange() { if(m_ofn.nFilterIndex==1) m_ofn.lpstrDefExt=".txt"; if(m_ofn.nFilterIndex==2) m_ofn.lpstrDefExt=".doc"; if(m_ofn.nFilterIndex==1) ...code for change dir1 if(m_ofn.nFilterIndex==2) ...code for change dir2 }

                    I Try, but I'm not sure :))

                    L 1 Reply Last reply
                    0
                    • U User 401087

                      Hi everyone, I have a problem in vc6. In a CFileDialog with 2 configured extensions (eg .Txt and .doc) I want automatically change directory in my CFileDialog when the extension changes: when I select the .txt extension I want the CFileDialog in the 'C:\FileTxt' directory, when instead I select the extension .doc I want the CFileDialog in the directory 'C:\FileDoc' with the corresponding files list ... ...Can someone help me with some example? Thank you

                      I Try, but I'm not sure :))

                      L Offline
                      L Offline
                      leon de boer
                      wrote on last edited by
                      #10

                      I don't use MFC but as it shims the Win32 I will explain how you do it in raw Win32. The FILEOPEN dialog in common controls take a structure called OPENFILENAME one of it's fields is lpfnHook which allows you to install your own handler. OPENFILENAMEA (commdlg.h) - Win32 apps | Microsoft Docs[^] In your handler in the WM_NOTIFY message you handle the CDN_TYPECHANGE message CDN_TYPECHANGE notification code (Commdlg.h) - Win32 apps | Microsoft Docs[^] So a minimal handler looks like this

                      UINT_PTR CALLBACK OpenHookProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
                      {
                      switch (Msg)
                      {
                      case WM_NOTIFY:
                      {
                      LPOFNOTIFY pnh = (LPOFNOTIFY)lParam;
                      if (pnh && (pnh->hdr.code == CDN_TYPECHANGE))
                      {
                      switch (pnh->lpOFN->nFilterIndex)
                      {
                      case 0:
                      // First extension type selected
                      break;
                      case 1:
                      // Second selection type selected
                      break;
                      }
                      }
                      break;
                      }
                      }
                      return (0);
                      }

                      In vino veritas

                      U 1 Reply Last reply
                      0
                      • U User 401087

                        Thank's Richard, I'm using VC6++ and I need a simple example to understand.. my OnTypeChange() { if(m_ofn.nFilterIndex==1) m_ofn.lpstrDefExt=".txt"; if(m_ofn.nFilterIndex==2) m_ofn.lpstrDefExt=".doc"; if(m_ofn.nFilterIndex==1) ...code for change dir1 if(m_ofn.nFilterIndex==2) ...code for change dir2 }

                        I Try, but I'm not sure :))

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #11

                        You need to check which property or method controls the current directory, and add code to manage it. Again the documentation will give you the information.

                        1 Reply Last reply
                        0
                        • U User 401087

                          in the Combo box that appared in CFileDialog when I configure more extension, I intercept the OnTypeChange() and in this routine I want change the dir...

                          I Try, but I'm not sure :))

                          CPalliniC Offline
                          CPalliniC Offline
                          CPallini
                          wrote on last edited by
                          #12

                          You are right, in time I forgot the behavior of such a dialog. Here you may find an hint: https://www.experts-exchange.com/questions/20090938/Changing-location-in-Open-Save-dialog.html[^].

                          In testa che avete, signor di Ceprano?

                          U 1 Reply Last reply
                          0
                          • U User 401087

                            Hi everyone, I have a problem in vc6. In a CFileDialog with 2 configured extensions (eg .Txt and .doc) I want automatically change directory in my CFileDialog when the extension changes: when I select the .txt extension I want the CFileDialog in the 'C:\FileTxt' directory, when instead I select the extension .doc I want the CFileDialog in the directory 'C:\FileDoc' with the corresponding files list ... ...Can someone help me with some example? Thank you

                            I Try, but I'm not sure :))

                            V Offline
                            V Offline
                            Victor Nijegorodov
                            wrote on last edited by
                            #13

                            Have you already customized your CFileDialog?

                            U 1 Reply Last reply
                            0
                            • L leon de boer

                              I don't use MFC but as it shims the Win32 I will explain how you do it in raw Win32. The FILEOPEN dialog in common controls take a structure called OPENFILENAME one of it's fields is lpfnHook which allows you to install your own handler. OPENFILENAMEA (commdlg.h) - Win32 apps | Microsoft Docs[^] In your handler in the WM_NOTIFY message you handle the CDN_TYPECHANGE message CDN_TYPECHANGE notification code (Commdlg.h) - Win32 apps | Microsoft Docs[^] So a minimal handler looks like this

                              UINT_PTR CALLBACK OpenHookProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
                              {
                              switch (Msg)
                              {
                              case WM_NOTIFY:
                              {
                              LPOFNOTIFY pnh = (LPOFNOTIFY)lParam;
                              if (pnh && (pnh->hdr.code == CDN_TYPECHANGE))
                              {
                              switch (pnh->lpOFN->nFilterIndex)
                              {
                              case 0:
                              // First extension type selected
                              break;
                              case 1:
                              // Second selection type selected
                              break;
                              }
                              }
                              break;
                              }
                              }
                              return (0);
                              }

                              In vino veritas

                              U Offline
                              U Offline
                              User 401087
                              wrote on last edited by
                              #14

                              I already intercept CDN_TYPECHANGE in my OnTypeChange () ...to change the directory what code I have to write where in your example you put the rem // First extension type selected and // Second selection type selected for list in my CFileDialog a different dir? Thank's

                              I Try, but I'm not sure :))

                              L 1 Reply Last reply
                              0
                              • CPalliniC CPallini

                                You are right, in time I forgot the behavior of such a dialog. Here you may find an hint: https://www.experts-exchange.com/questions/20090938/Changing-location-in-Open-Save-dialog.html[^].

                                U Offline
                                U Offline
                                User 401087
                                wrote on last edited by
                                #15

                                sorry... in expert-exchange : "You can use the DlgDirList() function (of CWnd class). It fills a list box with a file or directory listing. Only thing you should know is the ID of the list control." and I haven't the ID of the list control :(

                                I Try, but I'm not sure :))

                                CPalliniC 1 Reply Last reply
                                0
                                • V Victor Nijegorodov

                                  Have you already customized your CFileDialog?

                                  U Offline
                                  U Offline
                                  User 401087
                                  wrote on last edited by
                                  #16

                                  not yet :(

                                  I Try, but I'm not sure :))

                                  1 Reply Last reply
                                  0
                                  • U User 401087

                                    sorry... in expert-exchange : "You can use the DlgDirList() function (of CWnd class). It fills a list box with a file or directory listing. Only thing you should know is the ID of the list control." and I haven't the ID of the list control :(

                                    I Try, but I'm not sure :))

                                    CPalliniC Offline
                                    CPalliniC Offline
                                    CPallini
                                    wrote on last edited by
                                    #17

                                    I think the more promising approach shown in the linked page is writing the address of folder in the edit box and then (programmatically) clicking the OK button (check out the final comments).

                                    In testa che avete, signor di Ceprano?

                                    1 Reply Last reply
                                    0
                                    • U User 401087

                                      I already intercept CDN_TYPECHANGE in my OnTypeChange () ...to change the directory what code I have to write where in your example you put the rem // First extension type selected and // Second selection type selected for list in my CFileDialog a different dir? Thank's

                                      I Try, but I'm not sure :))

                                      L Offline
                                      L Offline
                                      leon de boer
                                      wrote on last edited by
                                      #18

                                      So just change directory then invalidate the dialog so it refreshes, you did all the hard part :-) SetCurrentDirectory function (winbase.h) - Win32 apps | Microsoft Docs[^] Do remember if you want to go back to the original directory after the dialog closes, save the directory before you call the dialog with GetCurrentDirectory and the set it back when you exit.

                                      In vino veritas

                                      U 1 Reply Last reply
                                      0
                                      • L leon de boer

                                        So just change directory then invalidate the dialog so it refreshes, you did all the hard part :-) SetCurrentDirectory function (winbase.h) - Win32 apps | Microsoft Docs[^] Do remember if you want to go back to the original directory after the dialog closes, save the directory before you call the dialog with GetCurrentDirectory and the set it back when you exit.

                                        In vino veritas

                                        U Offline
                                        U Offline
                                        User 401087
                                        wrote on last edited by
                                        #19

                                        I changed the dir with SetCurrent Directory , I invalidated and I did UpdateData(false) for refresh but nothing happens ...

                                        I Try, but I'm not sure :))

                                        V 1 Reply Last reply
                                        0
                                        • U User 401087

                                          I changed the dir with SetCurrent Directory , I invalidated and I did UpdateData(false) for refresh but nothing happens ...

                                          I Try, but I'm not sure :))

                                          V Offline
                                          V Offline
                                          Victor Nijegorodov
                                          wrote on last edited by
                                          #20

                                          I guess that UpdateData has nothing to do with what you are trying to achieve. Could you post your actual code?

                                          U 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