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

CFileDialog

Scheduled Pinned Locked Moved C / C++ / MFC
help
8 Posts 6 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.
  • S Offline
    S Offline
    si_69
    wrote on last edited by
    #1

    Hi I am using CfileDialog, but i cant get it to display pointing to the correct directory it seems to ignore the path that i pass im using TCHAR szFilters[] = _T ("Log Files (*.txt)|*.txt|All files (*.*)|*.*||"); CFileDialog dlg(TRUE, _T ("txt"), _T ("*.txt"),NULL, szFilters); CString MyPath "c:\"; if (logPath.GetLength()) dlg.GetOFN().lpstrInitialDir = MyPath; if (dlg.DoModal()==TRUE) { CString result = dlg.GetPathName(); ShellExecute(NULL, "Open", _T(result), NULL, NULL, SW_SHOW); } can anyone help thanks simon

    R T R D 4 Replies Last reply
    0
    • S si_69

      Hi I am using CfileDialog, but i cant get it to display pointing to the correct directory it seems to ignore the path that i pass im using TCHAR szFilters[] = _T ("Log Files (*.txt)|*.txt|All files (*.*)|*.*||"); CFileDialog dlg(TRUE, _T ("txt"), _T ("*.txt"),NULL, szFilters); CString MyPath "c:\"; if (logPath.GetLength()) dlg.GetOFN().lpstrInitialDir = MyPath; if (dlg.DoModal()==TRUE) { CString result = dlg.GetPathName(); ShellExecute(NULL, "Open", _T(result), NULL, NULL, SW_SHOW); } can anyone help thanks simon

      R Offline
      R Offline
      Rajesh R Subramanian
      wrote on last edited by
      #2

      Try CString MyPath = "C:\\"

      "There are those who confuse bad management with fate"

      S 1 Reply Last reply
      0
      • S si_69

        Hi I am using CfileDialog, but i cant get it to display pointing to the correct directory it seems to ignore the path that i pass im using TCHAR szFilters[] = _T ("Log Files (*.txt)|*.txt|All files (*.*)|*.*||"); CFileDialog dlg(TRUE, _T ("txt"), _T ("*.txt"),NULL, szFilters); CString MyPath "c:\"; if (logPath.GetLength()) dlg.GetOFN().lpstrInitialDir = MyPath; if (dlg.DoModal()==TRUE) { CString result = dlg.GetPathName(); ShellExecute(NULL, "Open", _T(result), NULL, NULL, SW_SHOW); } can anyone help thanks simon

        T Offline
        T Offline
        toxcct
        wrote on last edited by
        #3

        String MyPath "c:\"; is invalid. **'\'** is the escape character, so if you want to print a \, you must specify '\\'

        CString MyPath = "C:\\";

        One last thing. if (dlg.DoModal()==TRUE) is not syntactically correct. CDialog::DoModal() doesn't return a BOOL (TRUE or FALSE). it returns the exit code specified in the dialog with the call to CDialog::EndDialog(). In general, it is the ID of the buttons pressed, so you should test your CFileDialog with either IDOK or IDCANCEL.

        if (dlg.DoModal() == IDOK)

        -- modified at 9:30 Wednesday 27th September, 2006


        TOXCCT >>> GEII power

        [VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]

        1 Reply Last reply
        0
        • S si_69

          Hi I am using CfileDialog, but i cant get it to display pointing to the correct directory it seems to ignore the path that i pass im using TCHAR szFilters[] = _T ("Log Files (*.txt)|*.txt|All files (*.*)|*.*||"); CFileDialog dlg(TRUE, _T ("txt"), _T ("*.txt"),NULL, szFilters); CString MyPath "c:\"; if (logPath.GetLength()) dlg.GetOFN().lpstrInitialDir = MyPath; if (dlg.DoModal()==TRUE) { CString result = dlg.GetPathName(); ShellExecute(NULL, "Open", _T(result), NULL, NULL, SW_SHOW); } can anyone help thanks simon

          R Offline
          R Offline
          Rinu_Raj
          wrote on last edited by
          #4

          I think you are using OS XP or 2000, then try dlg.GetOFN().lpstrFile = MyPath; it will work Rinu Raj

          1 Reply Last reply
          0
          • R Rajesh R Subramanian

            Try CString MyPath = "C:\\"

            "There are those who confuse bad management with fate"

            S Offline
            S Offline
            si_69
            wrote on last edited by
            #5

            brahmma wrote:

            Try CString MyPath = "C:\\"

            have already tried that, no joy :-(

            T H 2 Replies Last reply
            0
            • S si_69

              brahmma wrote:

              Try CString MyPath = "C:\\"

              have already tried that, no joy :-(

              T Offline
              T Offline
              toxcct
              wrote on last edited by
              #6

              did you read my answer ? does it provide much help ?


              TOXCCT >>> GEII power

              [VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]

              1 Reply Last reply
              0
              • S si_69

                Hi I am using CfileDialog, but i cant get it to display pointing to the correct directory it seems to ignore the path that i pass im using TCHAR szFilters[] = _T ("Log Files (*.txt)|*.txt|All files (*.*)|*.*||"); CFileDialog dlg(TRUE, _T ("txt"), _T ("*.txt"),NULL, szFilters); CString MyPath "c:\"; if (logPath.GetLength()) dlg.GetOFN().lpstrInitialDir = MyPath; if (dlg.DoModal()==TRUE) { CString result = dlg.GetPathName(); ShellExecute(NULL, "Open", _T(result), NULL, NULL, SW_SHOW); } can anyone help thanks simon

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

                si_69 wrote:

                CString MyPath "c:\";

                This is a syntax error.

                si_69 wrote:

                if (logPath.GetLength())

                What is logPath?

                si_69 wrote:

                dlg.GetOFN().lpstrInitialDir = MyPath;

                Since GetOFN() does not exist with VC++ v6, I used m_ofn instead. Other than that, this code works fine. Do not use strcpy(), as you simply need to assign a pointer to an existing address.


                "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                "Judge not by the eye but by the heart." - Native American Proverb

                1 Reply Last reply
                0
                • S si_69

                  brahmma wrote:

                  Try CString MyPath = "C:\\"

                  have already tried that, no joy :-(

                  H Offline
                  H Offline
                  Hamid Taebi
                  wrote on last edited by
                  #8

                  You can use from Data Member m_ofn In CFileDialog that you have access to parameters of dialogbox


                  WhiteSky


                  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