Stopping ctr-c from closing a console application
I''m writing a program and I want to use ctr-c to copy text to the clipboard. Yet ctr-c is the shell command to "kill" a console application. Does anyone know how to stop it from closing the console window?
Thank you,
Dave
You''ll need to make a few significant changes, the first being the use of the Win32 API:
Resources:
Win32 Console Functions
SetConsoleControlHandler
HandlerRoutine
Registering a Console Handler Function
#include <windows.h> int WINAPI WinMain( HINSTANCE, HINSTANCE, LPCTSTR, int ){ // explicitly create a console window AllocConsole() // install console control handler SetConsoleCtrlHandler( myHandler, TRUE ); // explicitly release a console window FreeConsole() return 0;}
The myHandler function is a HandlerRoutine that would look like this to handle Ctrl+C events only:BOOL WINAPI myHandler( DWORD ctrlType ){ if( ctrlType == CTRL_C_EVENT ) { // copy buffer contents to clipboard return TRUE; } else return FALSE;}
Resources:
Win32 Console Functions
SetConsoleControlHandler
HandlerRoutine
Registering a Console Handler Function
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement