<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>InsaneDevelopers &#187; signals</title>
	<atom:link href="http://insanedevelopers.net/tag/signals/feed/" rel="self" type="application/rss+xml" />
	<link>http://insanedevelopers.net</link>
	<description>My personal trash bin</description>
	<lastBuildDate>Sun, 06 May 2012 13:40:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Handling CTRL+C in your console application</title>
		<link>http://insanedevelopers.net/2009/03/13/handling-ctrlc-in-your-console-application/</link>
		<comments>http://insanedevelopers.net/2009/03/13/handling-ctrlc-in-your-console-application/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 23:50:37 +0000</pubDate>
		<dc:creator>Alessandro</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[signals]]></category>

		<guid isPermaLink="false">http://insanedevelopers.net/?p=7</guid>
		<description><![CDATA[First of all, to make sure we can receive this event, the ENABLE_PROCESSED_INPUT console mode must be enabled using SetConsoleMode; without this, the CTRL+C signal would be sent as a keystroke inside the input buffer. SetConsoleMode(hdlStdInput, ENABLE_ECHO_INPUT &#124; ENABLE_INSERT_MODE &#124; &#8230; <a href="http://insanedevelopers.net/2009/03/13/handling-ctrlc-in-your-console-application/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>First of all, to make sure we can receive this event, the ENABLE_PROCESSED_INPUT console mode must be enabled using SetConsoleMode; without this, the CTRL+C signal would be sent as a keystroke inside the input buffer.</p>
<pre>SetConsoleMode(hdlStdInput, ENABLE_ECHO_INPUT | ENABLE_INSERT_MODE | ENABLE_LINE_INPUT | ENABLE_MOUSE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_QUICK_EDIT_MODE);</pre>
<p>We can now register our HandlerRoutine function using SetConsoleCtrlHandler</p>
<pre>BOOL WINAPI blCtrlCHandler(DWORD dwCtrlType) { ... }
...
SetConsoleCtrlHandler(blCtrlCHandler, TRUE);</pre>
<p>The handler function can be also handy for cleanup code, since it does not receives only the CTRL+C signal, but other events as well. Checking the dwCtrlType variable allows you to detect CTRL+BREAK and system events like logoff, shutdown, and the program&#8217;s termination through the close button.</p>
<p>If you don&#8217;t need the CTRL+C signal, and you want to mask it, it is possible to register a null function pointer that will prevent the default handler from handling the signal.</p>
<pre>SetConsoleCtrlHandler(NULL, TRUE);</pre>
<p>Source code: <a href="http://www.insanedevelopers.net/downloads/Sources/CTRL-CHandling.zip">http://www.insanedevelopers.net/downloads/Sources/CTRL-CHandling.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://insanedevelopers.net/2009/03/13/handling-ctrlc-in-your-console-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

