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. open a default fil by using the CFileDialog class

open a default fil by using the CFileDialog class

Scheduled Pinned Locked Moved C / C++ / MFC
comtutorial
11 Posts 4 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.
  • V Offline
    V Offline
    vikas amin
    wrote on last edited by
    #1

    How to open a default fil by using the CFileDialog class I open the dialog box like this . I want to keep one file as default selection CFileDialog dlg(TRUE,"bmp",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"Only BMP (*.bmp)|*.bmp|"); dlg.DoModal (); Vikas Amin Embin Technology Bombay vikas.amin@embin.com

    R 1 Reply Last reply
    0
    • V vikas amin

      How to open a default fil by using the CFileDialog class I open the dialog box like this . I want to keep one file as default selection CFileDialog dlg(TRUE,"bmp",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"Only BMP (*.bmp)|*.bmp|"); dlg.DoModal (); Vikas Amin Embin Technology Bombay vikas.amin@embin.com

      R Offline
      R Offline
      Russell
      wrote on last edited by
      #2

      Use dlg.m_ofn.lpstrFile=TEXT("DefaultFile.xxx"); before DoModal() Have a nice code day ;)

      V 1 Reply Last reply
      0
      • R Russell

        Use dlg.m_ofn.lpstrFile=TEXT("DefaultFile.xxx"); before DoModal() Have a nice code day ;)

        V Offline
        V Offline
        vikas amin
        wrote on last edited by
        #3

        I need to open a file named "1.bmp" located as "c:\1.bmp" but i get assertion for invalid address ASSERT(AfxIsValidAddress(m_ofn.lpstrFile, m_ofn.nMaxFile)); My code is somthing like this :-------- CFileDialog dlg(TRUE,"bmp",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"Only BMP (*.bmp)|*.bmp|"); dlg.m_ofn.lpstrFile=TEXT("c:\\1.bmp"); dlg.DoModal (); Vikas Amin Embin Technology Bombay vikas.amin@embin.com

        R D 2 Replies Last reply
        0
        • V vikas amin

          I need to open a file named "1.bmp" located as "c:\1.bmp" but i get assertion for invalid address ASSERT(AfxIsValidAddress(m_ofn.lpstrFile, m_ofn.nMaxFile)); My code is somthing like this :-------- CFileDialog dlg(TRUE,"bmp",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"Only BMP (*.bmp)|*.bmp|"); dlg.m_ofn.lpstrFile=TEXT("c:\\1.bmp"); dlg.DoModal (); Vikas Amin Embin Technology Bombay vikas.amin@embin.com

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

          sorry (error), now try with this: TCHAR str[100]=TEXT("c:\\1.bmp"); dlg.m_ofn.lpstrFile=str; Have a nice code day ;)

          V D 2 Replies Last reply
          0
          • R Russell

            sorry (error), now try with this: TCHAR str[100]=TEXT("c:\\1.bmp"); dlg.m_ofn.lpstrFile=str; Have a nice code day ;)

            V Offline
            V Offline
            vikas amin
            wrote on last edited by
            #5

            sorry there is some problem in the given code also some assertion at ASSERT(m_hFile != (UINT)hFileNull); I thing will have to go through the sturctre method i found some links will try from it http://eatworms.swmed.edu/~boris/B\_Player/VideoWnd.cpp http://www.codeproject.com/dialog/remove\_filters.asp Why simpe things are done so complicated in VC++ Vikas Amin Embin Technology Bombay vikas.amin@embin.com

            R 1 Reply Last reply
            0
            • V vikas amin

              sorry there is some problem in the given code also some assertion at ASSERT(m_hFile != (UINT)hFileNull); I thing will have to go through the sturctre method i found some links will try from it http://eatworms.swmed.edu/~boris/B\_Player/VideoWnd.cpp http://www.codeproject.com/dialog/remove\_filters.asp Why simpe things are done so complicated in VC++ Vikas Amin Embin Technology Bombay vikas.amin@embin.com

              R Offline
              R Offline
              Russell
              wrote on last edited by
              #6

              I don't know, it is strange! :( A good thing could be add the flag OFN_FILEMUSTEXIST here: CFileDialog dlg(TRUE,"bmp",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"Only BMP (*.bmp)|*.bmp|"); So you are sure that the file exist. And I don't like very much ...,"Only BMP (*.bmp)|*.bmp|" I prefere ...,"Only BMP (*.bmp)|*.bmp||" Let me know Have a nice code day ;)

              V 1 Reply Last reply
              0
              • V vikas amin

                I need to open a file named "1.bmp" located as "c:\1.bmp" but i get assertion for invalid address ASSERT(AfxIsValidAddress(m_ofn.lpstrFile, m_ofn.nMaxFile)); My code is somthing like this :-------- CFileDialog dlg(TRUE,"bmp",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"Only BMP (*.bmp)|*.bmp|"); dlg.m_ofn.lpstrFile=TEXT("c:\\1.bmp"); dlg.DoModal (); Vikas Amin Embin Technology Bombay vikas.amin@embin.com

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

                vikas amin wrote:

                How to open a default fil by using the CFileDialog class

                That is what the third parameter of CFileDialog's constructor is for.

                vikas amin wrote:

                I need to open a file named "1.bmp" located as "c:\1.bmp"

                Then why bother with CFileDialog if you already know the name of the file? Also, the filter should end with two ‘|’ characters.


                "Take only what you need and leave the land as you found it." - Native American Proverb

                V V 2 Replies Last reply
                0
                • D David Crow

                  vikas amin wrote:

                  How to open a default fil by using the CFileDialog class

                  That is what the third parameter of CFileDialog's constructor is for.

                  vikas amin wrote:

                  I need to open a file named "1.bmp" located as "c:\1.bmp"

                  Then why bother with CFileDialog if you already know the name of the file? Also, the filter should end with two ‘|’ characters.


                  "Take only what you need and leave the land as you found it." - Native American Proverb

                  V Offline
                  V Offline
                  VikramDelhi i
                  wrote on last edited by
                  #8

                  :zzz: yep if he knows filename & location then why he is using CFileDialog . well i guess he wants to show his skills here.;)

                  1 Reply Last reply
                  0
                  • D David Crow

                    vikas amin wrote:

                    How to open a default fil by using the CFileDialog class

                    That is what the third parameter of CFileDialog's constructor is for.

                    vikas amin wrote:

                    I need to open a file named "1.bmp" located as "c:\1.bmp"

                    Then why bother with CFileDialog if you already know the name of the file? Also, the filter should end with two ‘|’ characters.


                    "Take only what you need and leave the land as you found it." - Native American Proverb

                    V Offline
                    V Offline
                    vikas amin
                    wrote on last edited by
                    #9

                    vikas amin wrote: I need to open a file named "1.bmp" located as "c:\1.bmp" Then why bother with CFileDialog if you already know the name of the file? Yeh good qestion , i need this only for Testing purpose & when i cannot reach some thing in coding it makes me crazy to get it done . :cool: Vikas Amin Embin Technology Bombay vikas.amin@embin.com

                    1 Reply Last reply
                    0
                    • R Russell

                      I don't know, it is strange! :( A good thing could be add the flag OFN_FILEMUSTEXIST here: CFileDialog dlg(TRUE,"bmp",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"Only BMP (*.bmp)|*.bmp|"); So you are sure that the file exist. And I don't like very much ...,"Only BMP (*.bmp)|*.bmp|" I prefere ...,"Only BMP (*.bmp)|*.bmp||" Let me know Have a nice code day ;)

                      V Offline
                      V Offline
                      vikas amin
                      wrote on last edited by
                      #10

                      I will have to get the exact error if u have tested the code so u might be right , can be some error in my code . Vikas Amin Embin Technology Bombay vikas.amin@embin.com

                      1 Reply Last reply
                      0
                      • R Russell

                        sorry (error), now try with this: TCHAR str[100]=TEXT("c:\\1.bmp"); dlg.m_ofn.lpstrFile=str; Have a nice code day ;)

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

                        _Russell_ wrote:

                        dlg.m_ofn.lpstrFile=str;

                        If lpstrFile is assigned a non-NULL value, so must nMaxFile also be used to indicate the size of the buffer pointed to by lpstrFile. Why do it this way, however, when the constructor already has provisions for such?


                        "Take only what you need and leave the land as you found it." - Native American 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