exit event x button

Jun 29, 2012 at 9:55pm
how am i to save a list class using this isee no way to pass the class object or make the handler a member of the class i also can seem to find where the handler returns to also dtors dont hit on x button exits

BOOL WINAPI ConsoleHandler(DWORD CEvent)
{

ofstream o;

if(CEvent==CTRL_C_EVENT|| CTRL_BREAK_EVENT|| CTRL_CLOSE_EVENT|| CTRL_LOGOFF_EVENT||
CTRL_SHUTDOWN_EVENT)
{
cout<<"program exit detected ";


//save list
//class object

}
return 1;
}

void main()
{

//list l;
if (SetConsoleCtrlHandler( (PHANDLER_ROUTINE)ConsoleHandler,TRUE)==FALSE)
{
// unable to install handler...
// display message to the user
printf("Unable to install handler!\n")

}

//click x button
}
Last edited on Jun 29, 2012 at 10:09pm
Jul 2, 2012 at 4:33pm
Sorry that I am a bit late in seeing this. You are already setting the Callback with the "SetConsoleCtrlHandler()" function and passing it a pointer to the function you wrote. This basically makes your function a member of the class for the console window. This function won't return to your program, it's for handling Windows Messages that are sent to the console.
Topic archived. No new replies allowed.