Hello,
I recently used a set of console functions in my daemon program for some text output like this:
// Allocate a console
AllocConsole();
// Write some text
WriteConsole("something...");
// Close and free it when no use
FreeConsole();
Everything work fine. But if I click the "close" button or select "close" of sysmenu on the console window, the whole program exists immediately and unexpectedly. I found out a stupid way to disable the "close": GetSystemMenu() and DeleteMenu() on the "hwnd" of the console. It works, but not perfect:
1) if I right-click the console task on the task bar and select "close", I still can't prevent the program exiting;
2) actually I can't capture such kind message of program exiting yet, because the console has a different "hwnd" from the main program, and I don't know how to define another WndProc for this "hwnd"...
Please give any comments. Thanks!