Closing a console window.

BlitzMax Forums/BlitzMax Programming/Closing a console window.

Thareh(Posted 2010) [#1]
Hi! :)
Is there any way to see when the user closes your console application with the 'X'?
Thanks!


Jesse(Posted 2010) [#2]
appTerminate() ?


Thareh(Posted 2010) [#3]
Tried that, doesn't seem to do the trick :/


plash(Posted 2010) [#4]
Tried that, doesn't seem to do the trick :/
How did you use it? The AppTerminate function checks to see whether the close button was pressed or not. You should be checking if AppTerminate() = True, and ending the program if it is.

I have not checked if AppTerminate does respond to the close button on console windows, but it should.


GfK(Posted 2010) [#5]
AppTerminate() only checks for the window close gadget being clicked - you need to tell it what to do, ie:

Repeat
  'do stuff
  Until AppTerminate()

End


[edit] Oh wait - a console window? I'm not sure on that one but I suspect thats the problem.

[edit again] Right, not sure what you're talking about now - a console window just closes when you click the close button without any intervening code.


Czar Flavius(Posted 2010) [#6]
I think he wants to "hijack" when the console close button is clicked, and do something else.


Thareh(Posted 2010) [#7]
Yeah, I need to know when the user is closing the console window so I can close some sockets and other stuff.


plash(Posted 2010) [#8]
Have you tried OnEnd? You can attach a function to be called when the program ends using OnEnd, but I don't know if it will work with win32 consoles.


Thareh(Posted 2010) [#9]
Yeah, Tried both OnEnd and AppTerminate and neither seems to work :/


Czar Flavius(Posted 2010) [#10]
Try putting something in the Delete() method of a type?


Thareh(Posted 2010) [#11]
Doesn't work either :/


Thareh(Posted 2010) [#12]
Surely there must be some way? I don't want to have to use MaxGUI or a Graphics window >.<


Thareh(Posted 2010) [#13]
No one? :(


Dreamora(Posted 2010) [#14]
Console windows technically aren't windows.

They are programs themself (on windows the cmd application, on osx the terminal)

I guess thats why you don't get any window events


slenkar(Posted 2010) [#15]
you could make it into a windows service?


Czar Flavius(Posted 2010) [#16]
Perhaps you could make an invisible program that then calls this console program?


Thareh(Posted 2010) [#17]
Thanks for your answers, how does one go ahead and make the program into a windows service?

@Czar Flavius
I'd rather not do it that way, thanks for the suggestion though ^^