I have a WinAPI/Win32 application that also opens a console window (with debugging purposes) before the main window is opened). I added a safe check for when the main window gets its X button pressed it asks the "Are you sure?" thing. However, if I click X on the console, it kills the application right away without asking anything. Is there any way to prevent that? Here is a snippet of my code:
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR args, int nCmdShow)
{
EnableDebug();
WNDCLASSA MainWindow = { 0 };
MainWindow.hbrBackground = (HBRUSH) COLOR_WINDOW;
MainWindow.hCursor = LoadCursor(NULL, IDC_ARROW);
MainWindow.hInstance = hInst;
MainWindow.lpszClassName = "WindowClass";
MainWindow.lpfnWndProc = WndProc;
ATOM result = RegisterClassA(&MainWindow);
if (!result)
{
MessageBoxA(NULL, "Failed to register window class", "Error", MB_OK);
return -1;
}
MSG msg = { 0 };
//here the app goes on
//here is the start of the debug function
void EnableDebug(){
if (AllocConsole() == 0)
{
MessageBoxA(NULL, "Unable to create a debug window!", "Error", MB_OK);
return;
}
freopen("CONOUT$", "w", stderr);
SetConsoleTitleA("Debug Window");
clog.clear();