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 specific file in a MFC single document

Open a specific file in a MFC single document

Scheduled Pinned Locked Moved C / C++ / MFC
c++questiontutorialvisual-studiohelp
3 Posts 2 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.
  • I Offline
    I Offline
    Iceberg76
    wrote on last edited by
    #1

    Hello, Can someone help me figure out how to make my MFC single document application open a specific file type. I created the MFC single document application using the VS C++ 7.0 Wizard. It defaults to open all file types. I found the ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen) in MyProject.cpp. How do I customize this so I can open a specific file type such as a .txt? I looked at the scribble example, but that is a multiple document type and I couldn't see how they did this without overriding OnFileOpen(). Is there a better example that I can learn from? I am assuming I am not supposed to overwrite the OnFileOpen, but where is this stored and once I select the file and click OK... Where is the filename stored? What is the correct way to do this? Thanks.

    P 1 Reply Last reply
    0
    • I Iceberg76

      Hello, Can someone help me figure out how to make my MFC single document application open a specific file type. I created the MFC single document application using the VS C++ 7.0 Wizard. It defaults to open all file types. I found the ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen) in MyProject.cpp. How do I customize this so I can open a specific file type such as a .txt? I looked at the scribble example, but that is a multiple document type and I couldn't see how they did this without overriding OnFileOpen(). Is there a better example that I can learn from? I am assuming I am not supposed to overwrite the OnFileOpen, but where is this stored and once I select the file and click OK... Where is the filename stored? What is the correct way to do this? Thanks.

      P Offline
      P Offline
      pubududilena
      wrote on last edited by
      #2

      hi, U have create own Method for ID_FILE_OEPN This will help you.. void CAView::OnFileOpen() { char szFilters[]= "TXT Files (*.txt)|*.txt|Jpeg File (*.jpg)|*.jpg|Gif file (*.gif)|*.gif|"; CFileDialog dlg (true, "txt", "",OFN_OVERWRITEPROMPT, szFilters, this); if (dlg.DoModal()==IDOK){ //Add what u want to do when OK button is pressed } }

      I 1 Reply Last reply
      0
      • P pubududilena

        hi, U have create own Method for ID_FILE_OEPN This will help you.. void CAView::OnFileOpen() { char szFilters[]= "TXT Files (*.txt)|*.txt|Jpeg File (*.jpg)|*.jpg|Gif file (*.gif)|*.gif|"; CFileDialog dlg (true, "txt", "",OFN_OVERWRITEPROMPT, szFilters, this); if (dlg.DoModal()==IDOK){ //Add what u want to do when OK button is pressed } }

        I Offline
        I Offline
        Iceberg76
        wrote on last edited by
        #3

        Thank You for the help. I will try your method.

        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