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. Hide Command Prompt in Console Application

Hide Command Prompt in Console Application

Scheduled Pinned Locked Moved C / C++ / MFC
question
8 Posts 4 Posters 1 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.
  • A Offline
    A Offline
    avika
    wrote on last edited by
    #1

    I want to hide the command prompt while running my console application. I have used following code - HWND hWnd = GetConsoleWindow(); if(hWnd) { ShowWindow(hWnd, SW_HIDE); } This code is working fine, but for a moment it shows the command prompt and then hide it. Is there any way to hide Command Prompt completely?

    R S R 3 Replies Last reply
    0
    • A avika

      I want to hide the command prompt while running my console application. I have used following code - HWND hWnd = GetConsoleWindow(); if(hWnd) { ShowWindow(hWnd, SW_HIDE); } This code is working fine, but for a moment it shows the command prompt and then hide it. Is there any way to hide Command Prompt completely?

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

      1. Why do you need to do this? 2. If you don't want a window, you could use a Win32 application instead of a console application, where you could hide the window before it's shown. 3. Alternatively, if you're launching this console app from another app, then you could use CreateProcess[^], passing CREATE_NO_WINDOW[^] for the dwCreationFlags parameter.

      “Follow your bliss.” – Joseph Campbell

      A 1 Reply Last reply
      0
      • R Rajesh R Subramanian

        1. Why do you need to do this? 2. If you don't want a window, you could use a Win32 application instead of a console application, where you could hide the window before it's shown. 3. Alternatively, if you're launching this console app from another app, then you could use CreateProcess[^], passing CREATE_NO_WINDOW[^] for the dwCreationFlags parameter.

        “Follow your bliss.” – Joseph Campbell

        A Offline
        A Offline
        avika
        wrote on last edited by
        #3

        I am not launching my application from another application. I have to create console application because in some cases I have to show command prompt and in some cases not to show.

        R 1 Reply Last reply
        0
        • A avika

          I am not launching my application from another application. I have to create console application because in some cases I have to show command prompt and in some cases not to show.

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

          In which case, start your console application from a Win32 app and show or hide it as needed. You cannot 'hide' a console application from within itself before the console window is shown - or none that I know of. This is because the window creation is not done by the console program, but the system does it. The advice given in previous reply can be used if you decide to use a Win32 program for this.

          “Follow your bliss.” – Joseph Campbell

          1 Reply Last reply
          0
          • A avika

            I want to hide the command prompt while running my console application. I have used following code - HWND hWnd = GetConsoleWindow(); if(hWnd) { ShowWindow(hWnd, SW_HIDE); } This code is working fine, but for a moment it shows the command prompt and then hide it. Is there any way to hide Command Prompt completely?

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

            you can alloc a console by AllocConsole function and destroy by FreeConsole when you didn't need it. hope this will solve your problem.

            R 1 Reply Last reply
            0
            • S sunlin7

              you can alloc a console by AllocConsole function and destroy by FreeConsole when you didn't need it. hope this will solve your problem.

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

              lisunlin wrote:

              you can alloc a console by AllocConsole function and destroy by FreeConsole when you didn't need it.

              I don't see how could this solve the given problem.

              “Follow your bliss.” – Joseph Campbell

              S 1 Reply Last reply
              0
              • A avika

                I want to hide the command prompt while running my console application. I have used following code - HWND hWnd = GetConsoleWindow(); if(hWnd) { ShowWindow(hWnd, SW_HIDE); } This code is working fine, but for a moment it shows the command prompt and then hide it. Is there any way to hide Command Prompt completely?

                R Offline
                R Offline
                Rolf Kristensen
                wrote on last edited by
                #7

                Stop compiling your application as a console application, but as a windows application (Remove "console" from the compiler and linker options)

                1 Reply Last reply
                0
                • R Rajesh R Subramanian

                  lisunlin wrote:

                  you can alloc a console by AllocConsole function and destroy by FreeConsole when you didn't need it.

                  I don't see how could this solve the given problem.

                  “Follow your bliss.” – Joseph Campbell

                  S Offline
                  S Offline
                  sunlin7
                  wrote on last edited by
                  #8

                  complite your project as a windows application, there will be no console during it's executeing unless you AllocConsole when application need interactiving with user, FreeConsole when you want hide the console. Sorry for my English, I'm not good at it.

                  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