Console window during graphics

General FreeBASIC programming questions.
Post Reply
xlucas
Posts: 334
Joined: May 09, 2014 21:19
Location: Argentina

Console window during graphics

Post by xlucas »

Hi, folks

In GNU/Linux and Windows, when I make a graphics-based program and at some point, my program calls a shell, a new window pops up somewhere on the screen with the output from my commands. I'm wondering if it's possible to either keep this window minimised or hidden during execution or if it can be forced to close once the command ends or resized or something. If it can be done on one platform, but not the other, I'm still interested. Can it? Thanks!
shadow008
Posts: 86
Joined: Nov 26, 2013 2:43

Re: Console window during graphics

Post by shadow008 »

I believe you're looking for https://www.freebasic.net/wiki/CompilerOpts

Compile with -s gui to hide the console (windows only).
hhr
Posts: 211
Joined: Nov 29, 2019 10:41

Re: Console window during graphics

Post by hhr »

You can try this line. The system waits until the console is active.
If you then start a graphics window, the console window remains in the background.

Code: Select all

Open Scrn As #1 : Close #1 ' Wait until console is active
In Linux, the line is useful when using QTerminal because QTerminal starts slowly.
In other cases (XTerm, Windows) the line is not needed, but it does not interfere either.
speedfixer
Posts: 606
Joined: Nov 28, 2012 1:27
Location: CA, USA moving to WA, USA
Contact:

Re: Console window during graphics

Post by speedfixer »

Also - depends on what you need from the external you are calling - use OPEN PIPE instead.

david
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Console window during graphics

Post by dodicat »

Windows:

Code: Select all

#include "crt.bi"
extern "windows"
declare function GetConsoleWindow() as any ptr
declare function ShowWindow(byval hWnd as any ptr, byval nCmdShow as long) as boolean
end extern
declare sub bird
declare Function Regulate(Byval As Long,Byref As Long) As Long
enum
    hide=0
    show=5
end enum
var handle = GetConsoleWindow()
screen 20,32
ShowWindow(handle, HIDE)
dim as long mx,my,btn,flag,fps
var t=timer
do
    btn=0
    getmouse mx,my,,btn
    screenlock
    cls
    bird
    locate 5
    print "left mouse click to show console, right click to hide, <esc> to end"
    print "framerate = "& fps
    screenunlock
    
    if flag=0 and btn=1 then ShowWindow(handle,SHOW):printf(!"%s    %f\n","Total elapsed time =  ",(timer-t) )
    if btn=2 then ShowWindow(handle,HIDE)
    sleep regulate(50,fps)

    flag=btn
    loop until inkey=chr(27)

sleep

Sub bird
    Dim As Integer xres,yres
    Screeninfo xres,yres
    Dim As Double PLOT_grade=10000
    Dim As Double temp1,temp2,x1,y1,x
    
    #macro sketch(_function,minx,maxx,miny,maxy)
    For x =minx To maxx Step (maxx-minx)/PLOT_GRADE
        x1=(xres)*(x-minx)/(maxx-minx)
        y1=(yres)*(_function-maxy)/(miny-maxy)
        Pset(x1,y1),Rgb(0,0,10)'10
        If Abs(x)<1e-3 Then
            temp1=x1:temp2=y1
        End If
    Next x
    Circle (temp1,temp2),50,Rgb(0,200,0),,,,f
    Circle (temp1-20,temp2-20),10,Rgb(200,200,200),,,,f
    Circle (temp1+20,temp2-20),10,Rgb(200,200,200),,,,f
    
    Circle (temp1-20-5*z,temp2-20),3,Rgb(00,00,200),,,,f
    Circle (temp1+20-5*z,temp2-20),3,Rgb(00,00,200),,,,f
    
    Circle (temp1,temp2),30,Rgb(0,0,0),4,5.5
    Circle (temp1,temp2-2),30,Rgb(0,0,0),4-k/3,5.5+k/3
    Circle (temp1,temp2),51,Rgb(0,0,10)
    #endmacro
    
    Static k As long=1
    Static z As Double
    Dim pi As Double=4*Atn(1)
    z=z+.02*k 
    sketch (-Sin(z*x+z),-(pi),pi,-2,2)
    sketch (Sin(z*x-z),-(pi),pi,-2,2)
    Paint (.25*xres,.5*yres),Rgba(100,100,120,190),Rgb(0,0,10)
    Paint (.75*xres,.5*yres),Rgba(100,100,120,190),Rgb(0,0,10)
    If z>1.1 Then k=-k
    If z<-1.1 Then k=-k
    If z>2*pi Then z=0
End Sub

Function Regulate(Byval MyFps As Long,Byref fps As Long) As Long
    Static As Double timervalue,lastsleeptime,t3,frames
    Var t=Timer
    frames+=1
    If (t-t3)>=1 Then t3=t:fps=frames:frames=0
    Var sleeptime=lastsleeptime+((1/myfps)-T+timervalue)*1000
    If sleeptime<1 Then sleeptime=1
    lastsleeptime=sleeptime
    timervalue=T
    Return sleeptime
End Function
 
Post Reply