No announcement yet.

#console Off

  • Filter
  • Time
  • Show
Clear All
new posts

  • #console Off

    I compile my program with #COMPILE OFF option.

    How can I activate and show the windows cosole at the run time?


  • #2
    You can TRY the WinApi function AllocConsole() to create a console for the currently-executing program and make it the default STDIN/STDOUT/STDERROR.

    I say "try" because I don't know that the PB/CC compiler will treat a "foreign" console the same as it treats a console created when the program is compiled with #CONSOLE ON.

    I do know that at least thru version 3x of the compiler, PB/CC programs did not respect a change to the standard handles during execution (using SetStdHandle function), but that may have been addressed in 4x. (I have not tested with my 4x PB/CC).

    But this is pretty easy to try.

    The simpler answer is, of course, is to compile the program with #CONSOLE ON. I don't understand why you wouldn't just do this.
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]


    • #3

      When I launch my program in "normal way", I want that NOTHING appear
      on the screen but I want the possibility to open the console when the program is already running, for a diagnostic scope, and after that, put the console away.
      I'm sorry, may be easy, but is for me the first time with PBCC...

      In any case, I'll try your solution.


      • #4
        You could try this in your WinMain function somewhere

         LOCAL waiting AS STRING
          CONSOLE SET LOC 50,50
          CONSOLE SET LOC 1600,50
          CONSOLE SET LOC 50,50
        It will position the console outside the view area if nothing else works for you.

        In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.


        • #5
          Turn Console Off, and On again

          I recently did something similar in PBCC 4.04.

          If the console is turned off with #Console Off, a new console window may be created with AllocConsole, but PBCC does not recognize this window, and cannot print to it. I could not find a way to inform PBCC about the new console window.

          However, if the #Console Off option is omitted and the console is turned off with FreeConsole instead, it may be turned on and off at will and remains functioning.

          Arie Verheul


          • #6
            Well done!

            In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.


            • #7
              #INCLUDE "C:\PBcc40\WinAPI\"
              hConsole = CONSHNDL
              ShowWindow hConsole, %SW_Hide 'if you want to turn off the console
              ShowWindow hConsole, %SW_Show 'if you want to turn it back on.[/B]
              Last edited by Jerry Fielden; 11 Apr 2008, 04:43 PM.


              • #8
                Tht's correct, the console is just another window, so a simple call to ShowWindow can toggle the visibility state. Also, toggling the visibility state has the additional benefit of keeping what text is in the console.
       | Slam DBMS | PrpT Control | Other Downloads | Contact Me


                • #9
                  On top of what others have suggested, using a Shortcut to start your program can make the initial console less annoying. Tell the shortcut to start the program as Minimized, then use ShowWindow HIDE early in your program, and all you'll see is the momentary flash of a button on the Task Bar. The console window won't actually become visible for even a split second.

                  Then again if you want a lot of control, my company's Console Tools product includes a utility program that can launch a console program in a hidden console, and lots of other cool stuff... Click on the first link below.

                  -- Eric Pearson, Perfect Sync, Inc.
                  "Not my circus, not my monkeys."