Close console without terminating application

Just starting out? Need help? Post your questions and find answers here.
danny88
User
User
Posts: 38
Joined: Sun Jan 21, 2024 8:13 am

Close console without terminating application

Post by danny88 »

Hello

Is there a way to prevent terminating the whole application when closing a console opened with Openconsole() ?

Thanks
User avatar
jacdelad
Addict
Addict
Posts: 2032
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Close console without terminating application

Post by jacdelad »

Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
danny88
User
User
Posts: 38
Joined: Sun Jan 21, 2024 8:13 am

Re: Close console without terminating application

Post by danny88 »

Thanks. But they doesn't answer my question, otherwise I wouldn't have posted
User avatar
jacdelad
Addict
Addict
Posts: 2032
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Close console without terminating application

Post by jacdelad »

I'm quite sure they do answer your question. But someone may correct me if I'm wrong.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
infratec
Always Here
Always Here
Posts: 7664
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Close console without terminating application

Post by infratec »

He don't want to avoid to close the console.
He want to avoid that the whole program is terminated if he use CloseConsole().

Am I right?
danny88
User
User
Posts: 38
Joined: Sun Jan 21, 2024 8:13 am

Re: Close console without terminating application

Post by danny88 »

infratec wrote: Tue Jan 23, 2024 7:48 am He don't want to avoid to close the console.
He want to avoid that the whole program is terminated if he use CloseConsole().

Am I right?
Exactly. the mentioned examples detect when the console is being closed but doesn't prevent the app from closing.
danny88
User
User
Posts: 38
Joined: Sun Jan 21, 2024 8:13 am

Re: Close console without terminating application

Post by danny88 »

jacdelad wrote: Tue Jan 23, 2024 6:26 am I'm quite sure they do answer your question. But someone may correct me if I'm wrong.
they don't. those examples detect when the console is being closed but don't prevent the whole app (GUI, windows, etc) from terminating
User avatar
jacdelad
Addict
Addict
Posts: 2032
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Close console without terminating application

Post by jacdelad »

Yepp. Afaik it's not possible to do this. Closing the console always closes the application too. The onlY way would be preventing to close the console which is also between hard to do and impossible.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
danny88
User
User
Posts: 38
Joined: Sun Jan 21, 2024 8:13 am

Re: Close console without terminating application

Post by danny88 »

jacdelad wrote: Tue Jan 23, 2024 2:41 pm Yepp. Afaik it's not possible to do this. Closing the console always closes the application too. The onlY way would be preventing to close the console which is also between hard to do and impossible.
I tried hiding the console window, which doesn't work neither
User avatar
mk-soft
Always Here
Always Here
Posts: 6321
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Close console without terminating application

Post by mk-soft »

CloseConsole() not end the program ... Stop the console input, but close not close the terminal window
You can hide the window

Update

Code: Select all

CompilerIf #PB_Compiler_ExecutableFormat <> #PB_Compiler_Console
  CompilerError "Set Compiler Option Console!"
CompilerEndIf
  
Import ""
  GetConsoleWindow()
EndImport

If OpenConsole()
  Print("Input 1: ")
  a$ = Input()
  CloseConsole()
EndIf

hWnd = GetConsoleWindow()
ShowWindow_(hWnd, #SW_HIDE)
Delay(2000)
ShowWindow_(hWnd, #SW_NORMAL)

If OpenConsole()
  Print("Input 2: ")
  a$ = Input()
  CloseConsole()
EndIf
ShowWindow_(hWnd, #SW_HIDE)

For i = 1 To 10
  Debug i
  Delay(500)
Next
Last edited by mk-soft on Tue Jan 23, 2024 7:00 pm, edited 1 time in total.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
danny88
User
User
Posts: 38
Joined: Sun Jan 21, 2024 8:13 am

Re: Close console without terminating application

Post by danny88 »

mk-soft wrote: Tue Jan 23, 2024 6:46 pm CloseConsole() not end the program ...

Code: Select all

If OpenConsole()
  Print("Input: ")
  a$ = Input()
  CloseConsole()
EndIf

Delay(1000)

If OpenConsole()
  Print("Input 2: ")
  a$ = Input()
  CloseConsole()
EndIf

For i = 1 To 10
  Debug i
  Delay(500)
Next
it does. try opening a window
User avatar
mk-soft
Always Here
Always Here
Posts: 6321
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Close console without terminating application

Post by mk-soft »

You write a console program or a window application.
You should not mix them.

P.S. Update my example with hide console
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 6321
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Close console without terminating application

Post by mk-soft »

jacdelad wrote: Tue Jan 23, 2024 2:41 pm Yepp. Afaik it's not possible to do this. Closing the console always closes the application too. The onlY way would be preventing to close the console which is also between hard to do and impossible.
Simple with one line ;)

Code: Select all

DeleteMenu_(GetSystemMenu_(GetConsoleWindow(), #False),#SC_CLOSE, #MF_BYCOMMAND);
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
jacdelad
Addict
Addict
Posts: 2032
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Close console without terminating application

Post by jacdelad »

...only on Windows.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Post Reply