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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Launching GUI or Console

Launching GUI or Console

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
6 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.
  • P Offline
    P Offline
    Prabhu977
    wrote on last edited by
    #1

    Hi, I have a Single Document MFC application. I have a requirement to give command line support to this application. This means based on the command line arguments provided to the existing MFC application, it should either come up in GUI mode or in console mode. For e.g: 1. Launching the application like: "Test.exe /mode: GUI" from command prompt should launch the existing GUI application. 2. Launching the application like: "Test.exe /mode: CLI" should launch a console window. I should be able to output data to this window say using "cout" and input data from the console window using "cin". Is this possible? Can someone please help me? Thanks in advance! Bye!

    D O A 3 Replies Last reply
    0
    • P Prabhu977

      Hi, I have a Single Document MFC application. I have a requirement to give command line support to this application. This means based on the command line arguments provided to the existing MFC application, it should either come up in GUI mode or in console mode. For e.g: 1. Launching the application like: "Test.exe /mode: GUI" from command prompt should launch the existing GUI application. 2. Launching the application like: "Test.exe /mode: CLI" should launch a console window. I should be able to output data to this window say using "cout" and input data from the console window using "cin". Is this possible? Can someone please help me? Thanks in advance! Bye!

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

      Have you looked at the console API?


      "One must learn from the bite of the fire to leave it alone." - Native American Proverb

      P 2 Replies Last reply
      0
      • P Prabhu977

        Hi, I have a Single Document MFC application. I have a requirement to give command line support to this application. This means based on the command line arguments provided to the existing MFC application, it should either come up in GUI mode or in console mode. For e.g: 1. Launching the application like: "Test.exe /mode: GUI" from command prompt should launch the existing GUI application. 2. Launching the application like: "Test.exe /mode: CLI" should launch a console window. I should be able to output data to this window say using "cout" and input data from the console window using "cin". Is this possible? Can someone please help me? Thanks in advance! Bye!

        O Offline
        O Offline
        oustar
        wrote on last edited by
        #3

        Just like that: From MSDN: CWinApp::m_lpCmdLine See Also CWinApp Overview | Class Members | Hierarchy ChartCorresponds to the lpCmdLine parameter passed by Windows to WinMain. LPTSTR m_lpCmdLine; Remarks Points to a null-terminated string that specifies the command line for the application. Use m_lpCmdLine to access any command-line arguments the user entered when the application was started. m_lpCmdLine is a public variable of type LPTSTR. Example BOOL CMyApp::InitInstance() { // ... if (m_lpCmdLine[0] == _T('\0')) { // Create a new (empty) document. OnFileNew(); } else { // Open a file passed as the first command line parameter. OpenDocumentFile(m_lpCmdLine); } // ... }

        1 Reply Last reply
        0
        • P Prabhu977

          Hi, I have a Single Document MFC application. I have a requirement to give command line support to this application. This means based on the command line arguments provided to the existing MFC application, it should either come up in GUI mode or in console mode. For e.g: 1. Launching the application like: "Test.exe /mode: GUI" from command prompt should launch the existing GUI application. 2. Launching the application like: "Test.exe /mode: CLI" should launch a console window. I should be able to output data to this window say using "cout" and input data from the console window using "cin". Is this possible? Can someone please help me? Thanks in advance! Bye!

          A Offline
          A Offline
          AHawk
          wrote on last edited by
          #4

          Does the application used for launching the two different applications dependent of those application? What I mean is. . .is the command line application included or attached to the two different applictions? If not you can query the system by the title of the two different application, and execute them depending on your logic. Aaron.

          1 Reply Last reply
          0
          • D David Crow

            Have you looked at the console API?


            "One must learn from the bite of the fire to leave it alone." - Native American Proverb

            P Offline
            P Offline
            Prabhu977
            wrote on last edited by
            #5

            I tried two options today and I think I found the solution. First of all what I wanted was: Depending on the parameters from the command line, I wanted to launch a console window or a GUI. So I wanted console/GUI support from the one and the same MFC application. So what I did was to use CCommandLineInfo derived class to determine the parameters. So if I found /mode: command in then: 1. I used (as suggested by one of you) used the console functions to determine the standard input handle and do a ReadConsole from it to get the character typed. i.e., AllocConsole();//to show the console HANDLE hIn = GetStdHandle(); ReadFile(hIn,...) But I had one problem with this. If this application is launched from cmd.exe, then two console windows were visible: One from where I call Start test.exe, one created in the test.exe using AllocConsole. 2. I found another solution. I used the #pragma directive: #pragma comment(linker, "/subsystem:console") This brought a console window as expected. When launched from cmd.exe this did not launch a new console. I think the second solution more cleaner and simple. Thanks for the help from all of you. If you have any suggestions regardig the above, please let me know. Bye and c ya!

            1 Reply Last reply
            0
            • D David Crow

              Have you looked at the console API?


              "One must learn from the bite of the fire to leave it alone." - Native American Proverb

              P Offline
              P Offline
              Prabhu977
              wrote on last edited by
              #6

              I tried two options today and I think I found the solution. First of all what I wanted was: Depending on the parameters from the command line, I wanted to launch a console window or a GUI. So I wanted console/GUI support from the one and the same MFC application. So what I did was to use CCommandLineInfo derived class to determine the parameters. So if I found /mode: command in then: 1. I used (as suggested by you) used the console functions to determine the standard input handle and do a ReadConsole from it to get the character typed. i.e., AllocConsole();//to show the console HANDLE hIn = GetStdHandle(); ReadFile(hIn,...) But I had one problem with this. If this application is launched from cmd.exe, then two console windows were visible: One from where I call Start test.exe, one created in the test.exe using AllocConsole. 2. I found another solution. I used the #pragma directive: #pragma comment(linker, "/subsystem:console") This brought a console window as expected. When launched from cmd.exe this did not launch a new console. I think the second solution more cleaner and simple. Thanks for the help from all of you. If you have any suggestions regardig the above, please let me know. Bye and c ya!

              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