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. Opening a file with my program

Opening a file with my program

Scheduled Pinned Locked Moved C / C++ / MFC
questionwindows-admin
7 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.
  • M Offline
    M Offline
    mmagill0
    wrote on last edited by
    #1

    I have made a program that reads its own kind of file, which is written in plain text. When I run the program and select to open the file, it reads it perfectly, but how do I make it that when I double click on a file of this type it opens with my program? I have edited the registry and set it as default, but when I double click the file it runs the program with nothing there, the file hasn't loaded. Is there some code I should put into the program to allow it to open the file?

    If you're reading this, you're reading my signature - actually, no joke

    S C M L D 5 Replies Last reply
    0
    • M mmagill0

      I have made a program that reads its own kind of file, which is written in plain text. When I run the program and select to open the file, it reads it perfectly, but how do I make it that when I double click on a file of this type it opens with my program? I have edited the registry and set it as default, but when I double click the file it runs the program with nothing there, the file hasn't loaded. Is there some code I should put into the program to allow it to open the file?

      If you're reading this, you're reading my signature - actually, no joke

      S Offline
      S Offline
      Sauro Viti
      wrote on last edited by
      #2

      You have to get the filename from the command line. If you are using MFC look at the CCommandLineInfoClass (CCommandLineInfoClass (MFC)[^]) and the ParseCommandLine method of CWinApp (CWinApp::ParseCommandLine (MFC)[^])

      1 Reply Last reply
      0
      • M mmagill0

        I have made a program that reads its own kind of file, which is written in plain text. When I run the program and select to open the file, it reads it perfectly, but how do I make it that when I double click on a file of this type it opens with my program? I have edited the registry and set it as default, but when I double click the file it runs the program with nothing there, the file hasn't loaded. Is there some code I should put into the program to allow it to open the file?

        If you're reading this, you're reading my signature - actually, no joke

        C Offline
        C Offline
        Cool_Dev
        wrote on last edited by
        #3

        in addition to what sauro told, very simply, the extern variables __argc and __argv can do the role anywhere in your program.

        1 Reply Last reply
        0
        • M mmagill0

          I have made a program that reads its own kind of file, which is written in plain text. When I run the program and select to open the file, it reads it perfectly, but how do I make it that when I double click on a file of this type it opens with my program? I have edited the registry and set it as default, but when I double click the file it runs the program with nothing there, the file hasn't loaded. Is there some code I should put into the program to allow it to open the file?

          If you're reading this, you're reading my signature - actually, no joke

          M Offline
          M Offline
          mmagill0
          wrote on last edited by
          #4

          I'm not using MFC, can I still use __argc and __argv and if so how do i implement them?

          C 1 Reply Last reply
          0
          • M mmagill0

            I'm not using MFC, can I still use __argc and __argv and if so how do i implement them?

            C Offline
            C Offline
            Cool_Dev
            wrote on last edited by
            #5

            __argc is an integer variable holding the count of commandline arguments. __argv is pointer to two dimensional character array of comand line strings. first argument __argv[0] second argument __argv[1] last argument __argv[__argc-1] alternatively you can use GetCommandLine API also If your registry settings for file association are correct, you will be getting the file path as a commandline argument to your application.

            modified on Friday, July 30, 2010 9:24 AM

            1 Reply Last reply
            0
            • M mmagill0

              I have made a program that reads its own kind of file, which is written in plain text. When I run the program and select to open the file, it reads it perfectly, but how do I make it that when I double click on a file of this type it opens with my program? I have edited the registry and set it as default, but when I double click the file it runs the program with nothing there, the file hasn't loaded. Is there some code I should put into the program to allow it to open the file?

              If you're reading this, you're reading my signature - actually, no joke

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

              Assuming this is a Windows program then the command line parameters are passed in the third parameter of the WinMain() function. This is a simple text string which you need to parse for the specific details your program needs.

              It's time for a new signature.

              1 Reply Last reply
              0
              • M mmagill0

                I have made a program that reads its own kind of file, which is written in plain text. When I run the program and select to open the file, it reads it perfectly, but how do I make it that when I double click on a file of this type it opens with my program? I have edited the registry and set it as default, but when I double click the file it runs the program with nothing there, the file hasn't loaded. Is there some code I should put into the program to allow it to open the file?

                If you're reading this, you're reading my signature - actually, no joke

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

                mmagill0 wrote:

                I have edited the registry and set it as default, but when I double click the file it runs the program with nothing there...

                Did you put %1 in your registry string?

                "One man's wage rise is another man's price increase." - Harold Wilson

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                "Man who follows car will be exhausted." - Confucius

                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