Sign in to follow this  
sankari

problem closing a console by its close button

Recommended Posts

Hello, I have a dialog where pressing a: button (IDC_BUTTON1) calls to "AllocConsole()" showing a console and pressing in another button (IDC_BUTTON2)closes the console calling "FreeConsole()". Until here everything work fine. But if the console is closed using its close button then the next error appears: "user breakpoint called from code at 0x7c901230". Why this error appears? So a possible solution should be disable the close button at the console to avoid that the user does not touch such close button. But how to do it? Does anybody know what to do to avoid the error message when closing the console via close button (x). Or how to disable such a button. Thanks in advance. My best regards. Sankari.

Share this post


Link to post
Share on other sites
The close button on console windows is one of my biggest peeves about Windows. I don't get the breakpoint you mention however what I have found is that the close button is completely untrappable. Somebody hits that button and you get TerminateProcess'd and there's nothing you can do about it. I don't use AllocConsole for this reason, however convienent it would have been to be able to.

You can get the console window via GetConsoleWindow. However you don't own that window (it's owned by a system process even if your app called AllocConsole) so I don't know if you can play with it's attributes. It seems likely that even if it does work you would be falling into the realm of undocumented behavior.

Share this post


Link to post
Share on other sites
Create a handle to the console window once its created. With the handle monitor the window to make sure its open, once it closes call freeconsole(). That should fix the breakpoint error (in theory)

Share this post


Link to post
Share on other sites
What are you doing that is causing spurious breakpoint exceptions?

I have a hard time believing your problem is caused by Windows in any way, but if you want to prevent the X from closing the console anyways for whatever reason, just use SetConsoleCtrlHandler. Windows provides a lot more control over the console than most people seem to realize (and it also omits huge amounts of simple functionality as well).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this