Page 1 of 1

Multiple Console Windows at Once?

Posted: Sat Sep 29, 2012 2:36 am
by oldefoxx
Lots of people see no purpose in having the ability to add or use Console
Windows to their applications. Others, and some languages, make great
use of Console Windows. They can be very handy for quick projects where
you need direct answers, or for a variety of other purposes. I once wrote
an extensive application that created three rows of boxes across the
screen, and used the colors to emphasize the data that needed attention.

That's taking one console screen, enlarging it, then filling it with data that
was organized to fit into one of the boxes. But how about the idea of having
more than one console screen in use as one time? Is it possible?

This link may steer you towards an answer:
http://www.codeproject.com/Articles/133 ... pplication

It might make you more aware of what is possible.

Oh, incidently, the Windows APIs have 64 Functions specifically related to the use of
the Console. A bit if effort in making use of these might bring big rewards. You
never know.

Re: Multiple Console Windows at Once?

Posted: Sat Sep 29, 2012 2:40 am
by MachineCode
Redacted. I apologize.

Re: Multiple Console Windows at Once?

Posted: Sat Sep 29, 2012 2:46 am
by oldefoxx
If you can't say anything nicer, than I for one would appreciate it if
you said nothing at all. You add nothing to these forums with your
derogatory remarks. Now whether my post add anything or not, I
am not sure. But at least I am trying.

Re: Multiple Console Windows at Once?

Posted: Sat Sep 29, 2012 11:23 am
by Danilo
oldefoxx wrote:But how about the idea of having more than one console screen in use as one time? Is it possible?

This link may steer you towards an answer:
http://www.codeproject.com/Articles/133 ... pplication
Start multiple processes, each with own console, and communicate via pipes.
The new processes can be the same executable, you start the EXE itself again via RunProgram().

Simple example for opening a main console and 3 new consoles. Hope it helps as a start:

Code: Select all

Import "kernel32.lib"
    GetConsoleWindow.i()
EndImport

Procedure OpenNewConsole()
    ProcedureReturn RunProgram(ProgramFilename(),"Command.OpenConsole","",#PB_Program_Open|#PB_Program_Write)
EndProcedure

Procedure WriteConsole(console,txt.s)
    If ProgramRunning(console)
        WriteProgramString(console,txt)
    EndIf
EndProcedure

Procedure WriteConsoleN(console,txt.s)
    If ProgramRunning(console)
        WriteProgramStringN(console,txt)
    EndIf
EndProcedure

Procedure WriteConsoleCommand(console, command.s)
    WriteConsoleN(console,"Command."+command)
EndProcedure

Procedure ShutdownConsole(console)
    If ProgramRunning(console)
        WriteProgramStringN(console,"Command.End")
        WaitProgram(console,100)
        CloseProgram(console)
    EndIf
EndProcedure

If ProgramParameter(0) <> "Command.OpenConsole"
    ;******************************
    ;*
    ;* Main program
    ;*
    ;******************************
    If OpenConsole()
        win = GetConsoleWindow()
        GetWindowRect_(win,@r.RECT)
        MoveWindow_(win, 420, 200, r\right, r\bottom, #True)
        
        ConsoleTitle("Main Console")
    
        PrintN("Main Console")
        PrintN("press <Return> to end program")
        console1 = OpenNewConsole()
        console2 = OpenNewConsole()
        console3 = OpenNewConsole()
    
        WriteConsoleCommand(console1,"Resize 0 0 400 200")
        WriteConsoleCommand(console1,"SetTitle Console 1")
        WriteConsoleN(console1,"Console 1")

        WriteConsoleCommand(console2,"Resize 420 0 400 200")
        WriteConsoleCommand(console2,"SetTitle Console 2")
        WriteConsoleN(console2,"Console 2")

        WriteConsoleCommand(console3,"Resize 0 200 400 190")
        WriteConsoleCommand(console3,"SetTitle Debug Console")
        WriteConsoleN(console3,"Console 3")
        WriteConsoleN(console3,"Debugger Output:")
    
    
        Input()
        
        ShutdownConsole(console1) ;: Delay(1000)
        ShutdownConsole(console2) ;: Delay(1000)
        ShutdownConsole(console3) ;: Delay(1000)
        
    
        End
    EndIf
Else
    ;******************************
    ;*
    ;* Consoles
    ;*
    ;******************************
    FreeConsole_(): AllocConsole_() ; detach from default console and create new console (required for compiler mode CONSOLE)
    If OpenConsole()
        console = GetStdHandle_(#STD_INPUT_HANDLE)
        Repeat
            A$=Input()
            If A$ = "Command.End"
                CloseConsole()
                End
            ElseIf Left(A$,14) = "Command.Resize"
                r.RECT
                r\left   = Val(StringField(A$,2," "))
                r\top    = Val(StringField(A$,3," "))
                r\right  = Val(StringField(A$,4," "))
                r\bottom = Val(StringField(A$,5," "))
                win = GetConsoleWindow()
                MoveWindow_(win, r\left, r\top, r\right, r\bottom, #True)
            ElseIf Left(A$,16) = "Command.SetTitle"
                ConsoleTitle(Right(A$,Len(A$)-17))
            Else
                PrintN(A$)
            EndIf
        ForEver
    EndIf
EndIf

Re: Multiple Console Windows at Once?

Posted: Sat Sep 29, 2012 9:18 pm
by oldefoxx
In my readings on the subject, it was also suggested that you could
have multiple threads, each with its own console window. I haven't
tried it, but I've limited experience with threads, and none with
PureBasic at this point. I'm planning to do some experiments along
some of these lines, so may have more to relate later.

There are also a couple of freeware releases of something called
CONSOLE or CONSOLE2. These add additional features to the Console
window that normally comes up when you enter CMD at the Start/Run
line. I left two links to these on another thread about freeware and
what one person recommends.

What interests me is that I found that there is a CONSOLE.DLL on my
system that makes use of other API dlls, but none of them make use of
it. I wonder what it is there for?

Even more interesting perhaps is that my accumulated store of PureBasic
going back years has some example programs making use of ConsoleX,
and there is even a PowerConsole.dll found in my PureBasic folders.
I did find a DLL breakdown of Console.dll online, not what it is used for
or by, but what else it calls and the ordinal calls that it has inside. I
haven't found anything that tells me about PowerConsole.dll. I wonder
where it came from and what's it good for?

Re: Multiple Console Windows at Once?

Posted: Sat Sep 29, 2012 9:58 pm
by oldefoxx
I am engaged in playing the PCH games, on the faint possibility I might
actually win something. If you are retired, a semi-invalid, and no job
prospects, what else is there to do?

One of the ways you can play is engage in online searches where PCH
makes use of multiple search engines to get results for you. I get hit
with another chance to play two or three times a day. So I couple that
with my interest in things related to PureBasic, and I do searches. I
come up with some things of note quite often. And I try to share.

http://code.google.com/p/multi-console/downloads/list

This link takes you to a page where you can download a C++ version of a
multi-console program that lets one program have more than one console
going at once. It is intended to be compiled, meaning you get the source
code where you can see what is going on, assuming you know C++.

This might help somebody. Or it might give someone else Ideas, now that
they know it's possible. So how would it be done? Well, I guess you start with
the idea that each Console Window has its own handle, like files have
handles, then you carry it from there.

But enough on that. Get the idea across, then let it go. Let someone else
carry it for awhile.

What I want to mention now is that if you are smart, and keeping up with the
world's news, you know that every major country is in serious jeopardy with
regards to it economy, loss of jobs, decline in middle class, and risk of having
its currency devalued by inflation (too much printed) and rejection (no longer
accepted as payment for debts, by other nations or even by its own people).

This should be hardly news to you. My advice is keep a close eye on what is
going on, and do your best to work out how you plan to deal with the changes
that are coming. It won't be nice, and many people won't make it.

There is a class/type of government that always brings this to the fore as it
presses forward with its agendas. Rather than engage in a class war on the
subject by mentioning some of the names it is known by, a smart person should
be able to work this out for themselves. Please take that as a challenge.

Why mention this here? Because it is certainly off-topic, and merits its own
right to be mentioned wherever it is brought up. It is too important to neglect.
Neglect is one of the reasons it has become so pronounced and threatening.