So yea, am aware this question probably get asked a ton, but im also aware each time its answered in a pretty vague way (at least the answer i've been able to find)
So... is there a way?
There has to... right?
..
...
Keep in mind that you cannot stop the console from closing -- only the user can do that by responding negatively to the Windows "End Program" dialogue that will pop-up.
I find this function only useful with a GUI program with an attached console (see AllocConsole()), since the user can be warned that attempts to close the console will summarily terminate the program. My control handler will typically look something like this
BOOL WINAPI HandlerRoutine( DWORD dwCtrlType )
{
#ifdef __cplusplus
cout <<
#else
printf( "%s",
#endif
"\n""+-----------------------------------------------+\n""| HEY YOU THERE! CLOSING ME ENDS THE PROGRAM! |\n""+-----------------------------------------------+\n\n""To make this window disappear, select\n""File -> Hide Console from the main window''s menu.\n"
#ifndef __cplusplus
)
#endif
;
return dwCtrlType == CTRL_CLOSE_EVENT
}
Note that there is an officially confirmed bug under Windows 9x where the handler is not called for CTRL_CLOSE_EVENT signals, so you may be out of luck if the user presses the little X on that obnoxious black window that pops-up with your GUI program while holding down the Ctrl key...
I don't know about this stuff on Linux. It really isn't necessary in that environment...