Console Concepts

 

A Windows "console" is a window which uses only fixed pitch text for output, just like the old DOS text mode screen (in fact, a console is often referred to as a "DOS box"). As such, it provides the quickest and easiest route for the conversion of programs written for DOS text mode to Windows.

 

A console primarily uses the keyboard for input, but the mouse may also be enabled for additional user input support, with the mouse location expressed in text screen rows and columns, as used in some DOS programs.

 

(PowerBASIC also provides support for the conversion of DOS programs written for graphics modes, in the form of the separate GRAPHIC WINDOW mechanism, available in both PB/Win and PB/CC.)

 

But Windows consoles have uses and functionality beyond the emulation of DOS text mode. Graphical User Interface (GUI) applications require a whole new, and more complex, programming paradigm which may not be worth the trouble for quick-and-dirty utilities. PB/Win's DDT mechanism makes GUI programming easier, but it may still be too time-consuming for some simple programs.

 

But even within a GUI application, a console may be useful for the output of debugging or logging information, maybe even retain an older text-mode interface while developing a new GUI interface. For the first time, LJ-CC allows the easy combination of PB/Win's DDT with the full console functionality of PB/CC.

 

However, note the following ...

 

There are two fundamental types of directly executable Windows programs, defined by a flag in the EXE header, "GUI applications" and "console applications". Windows simply lets a GUI application look after its own user interface, but starts a console application differently.

 

If an executable is marked as a console application, Windows automatically allocates or creates a console window for the program on startup. If the program is started from the command processor console ("DOS prompt"), the program will inherit the command processor console. If the program is started otherwise (usually by clicking on it within the GUI environment), Windows will create a new console for the application on startup.

 

PB/CC produces console applications by default, if #CONSOLE OFF is not specified, or GUI applications if #CONSOLE OFF is specified. PB/Win always produces GUI applications. Thus, in terms of Windows startup actions, creating a program using PB/Win+LJ-CC is equivalent to using PB/CC with #CONSOLE OFF.

 

When started from the GUI (i.e. with no existing console to inherit) LJ-CC attempts to simulate the behavior of a PB/CC program with #CONSOLE ON by automatically creating a console itself on the first execution of any of "Con..." command. This strategy is suitable for the majority of applications.

 

When started from another console (e.g. the command processor), standard Windows behavior is for a console application to inherit the parent console. However, as a GUI application, a PB/Win+LJ-CC program does not receive the parent console handle and so cannot inherit the parent console. Under these circumstances, LJ-CC will not automatically create a console and calls to any "Con..." command or function will be ignored. Only "Std..." commands and functions can be used. This emulates the behavior of PB/CC with #CONSOLE OFF.

 

This behavior may be exactly what you want, to produce CGI applications for example, which is one of the common uses for PB/CC with #CONSOLE OFF. Another common use of PB/CC with #CONSOLE OFF is to build a user interface with API calls (the so-called "SDK" programming technique). You don't need LJ-CC in this case. Just comment out the #CONSOLE OFF statement (if not enclosed within conditional compilation directives) and the program should compile directly with PB/Win.

 

If you need to, you can force the creation of a new console by calling ConNew. Then all console commands and functions will be available to a program started from the command line, but referencing the new console, not the parent console. Also be aware that doing this will lose all standard input/output redirection as stdin and stdout are assigned to the new console.

 

In summary, PB/Win+LJ-CC cannot inherit a parent console. Only a true console application can do this. Either use PB/CC, or use a utility that changes the EXE from a GUI application to a console application after compilation. One such utility, gui2con, is supplied with LJ-CC. Only in this way can a program created with PB/Win+LJ-CC truly emulate PB/CC with #CONSOLE ON.