Page 1 of 1

Close console without terminating application

Posted: Mon Jan 22, 2024 10:04 pm
by danny88
Hello

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

Thanks

Re: Close console without terminating application

Posted: Tue Jan 23, 2024 12:22 am
by jacdelad

Re: Close console without terminating application

Posted: Tue Jan 23, 2024 5:55 am
by danny88
Thanks. But they doesn't answer my question, otherwise I wouldn't have posted

Re: Close console without terminating application

Posted: Tue Jan 23, 2024 6:26 am
by jacdelad
I'm quite sure they do answer your question. But someone may correct me if I'm wrong.

Re: Close console without terminating application

Posted: Tue Jan 23, 2024 7:48 am
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?

Re: Close console without terminating application

Posted: Tue Jan 23, 2024 9:35 am
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.

Re: Close console without terminating application

Posted: Tue Jan 23, 2024 9:36 am
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

Re: Close console without terminating application

Posted: Tue Jan 23, 2024 2:41 pm
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.

Re: Close console without terminating application

Posted: Tue Jan 23, 2024 3:18 pm
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

Re: Close console without terminating application

Posted: Tue Jan 23, 2024 6:46 pm
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

Re: Close console without terminating application

Posted: Tue Jan 23, 2024 6:48 pm
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

Re: Close console without terminating application

Posted: Tue Jan 23, 2024 7:03 pm
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

Re: Close console without terminating application

Posted: Tue Jan 23, 2024 7:35 pm
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);

Re: Close console without terminating application

Posted: Tue Jan 23, 2024 10:33 pm
by jacdelad
...only on Windows.