Console off

New to FreeBASIC? Post your questions here.
Baptiste
Posts: 17
Joined: May 15, 2019 10:58

Console off

Post by Baptiste »

Hello,

when working with a graphical user interface and you do not need the "console" window, is there an instruction to close this console window in Freebasic. I did not find in the documentation

thank you
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Console off

Post by MrSwiss »

Compile with switch:
fbc -s gui "myFile.bas"

See: Compiler Options (FB-Manual)
Last edited by MrSwiss on Jun 28, 2019 16:22, edited 1 time in total.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Console off

Post by dodicat »

You can use switch -s gui.
Example:
fbc -s gui myfile.bas
But make sure that myfile.bas is graphical, otherwise you might need the task manager to kill it.

(Sorry Mr Swiss, I didn't see your answer)
bcohio2001
Posts: 556
Joined: Mar 10, 2007 15:44
Location: Ohio, USA
Contact:

Re: Console off

Post by bcohio2001 »

Just a side note.

On many IDE's, when using the "Quick Run" option, it leaves the console window up for any "debugging" printing. But in the compiled exe will not have a console window.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Console off

Post by dodicat »

If you are writing code for windows it can be done inside the code.(Without any compiler switches)
Example:

Code: Select all


declare function hideconsole alias "FreeConsole"() as boolean
declare function showconsole alias "AllocConsole"() as boolean

screen 19
hideconsole
print "Press a key for console"
sleep
showconsole
sleep 
Baptiste
Posts: 17
Joined: May 15, 2019 10:58

Re: Console off

Post by Baptiste »

I tried the first solution using the compiler options and it works perfectly.
better, the calculations made by the program (it is a calculation program) are carried out with a saving of time of 10%.

I will try the 2nd solution a little later in the evening.

Thank you very much to all .
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Console off

Post by caseih »

Indeed he would be using Windows because in no other operating system would it make sense to be talking about hiding the console. Windows is the only operating system that makes distinctions between console and GUI applications and has special console windows. However Microsoft is finally changing and modernizing the console system, including a proper terminal emulator, and hopefully a revamping of the console mechanism, making it more unix-like finally. The way things should works is that anything written to standard only ends up in a console window if the program is run from a command prompt.

Nearly all Linux applications write to standard out and standard error for a variety of reasons, mostly debugging and information. But most people never see them because they launch apps directly from the desktop, so they have nothing attached to stdout and stderr. Hopefully the Windows console subsystem will eventually work like that.

Maybe it's no longer like this, but at one point, I found that if my program outputed anything to standard out, even as a GUI app, Windows would popup a console window. So I had to remove anything that printed anything to standard out. But that was years ago.

I'm skeptical that hiding the console window sped up your program by 10%, although it is possible. The Windows console is horribly slow. Why did turning off the console window increase your speed?
Baptiste
Posts: 17
Joined: May 15, 2019 10:58

Re: Console off

Post by Baptiste »

I do not know why, but actually the execution of calculations is a little faster.
the program displays intermediate calculation results on the console. I think that removing the console should eliminate these displays and thus save some time.
I will do other tests with longer calculations to better measure the calculation times and make sure that there is a gain in all cases.
UEZ
Posts: 988
Joined: May 05, 2017 19:59
Location: Germany

Re: Console off

Post by UEZ »

Does anybody know how to suppress console window by using switches for -gen gcc compiler parameter?

@dodicat: thanks for tip
dodicat wrote:If you are writing code for windows it can be done inside the code.(Without any compiler switches)
Example:

Code: Select all


declare function hideconsole alias "FreeConsole"() as boolean
declare function showconsole alias "AllocConsole"() as boolean

screen 19
hideconsole
print "Press a key for console"
sleep
showconsole
sleep 
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Console off

Post by caseih »

The same flag should work for the GCC backend as the ASM one. If not, I'd say that's a bug.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Console off

Post by MrSwiss »

caseih wrote:If not, I'd say that's a bug.
No bug, works like a charm, both FBC's 32/64 bit.
caseih wrote:The same flag should work for the GCC backend as the ASM one.
It does, the question was a dumb one, because the two switches don't influence
each other, in any way (-s specifier is in any case, Windows only).
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Console off

Post by caseih »

Okay right. The console or gui flag is a linker flag too, not a compiler flag. I know most FB programmers don't use multiple modules and makefiles, but if you did, you wouldn't have to recompile anything to hide the gui; just re-link it with the subsystem flag you want.
UEZ
Posts: 988
Joined: May 05, 2017 19:59
Location: Germany

Re: Console off

Post by UEZ »

caseih wrote:The same flag should work for the GCC backend as the ASM one. If not, I'd say that's a bug.
Sorry, I think I didn't express it properly. Of course the code works with -gen gcc properly but what I want to know is if there is a command line switch argument for gcc to set the linker not to show the console window by default.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Console off

Post by MrSwiss »

UEZ wrote:... command line switch argument for gcc to set the linker not to show the console window by default.
No, the default setting is console (if the -s switch is omitted, too).

It's also a somewhat dangerous setting, in case of running a console job even
once in a while, only ...
See first comment from dodicat, earlier in this thread, for reasons.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Console off

Post by caseih »

UEZ wrote:Sorry, I think I didn't express it properly. Of course the code works with -gen gcc properly but what I want to know is if there is a command line switch argument for gcc to set the linker not to show the console window by default.
GCC itself uses the flag "-mwindows" which it passes to the linker.
Post Reply