<?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>ManvirSingh.net &#187; crash</title>
	<atom:link href="http://www.manvirsingh.net/index.php/tag/crash/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.manvirsingh.net</link>
	<description>Manvir&#039;s Blog!</description>
	<lastBuildDate>Tue, 01 Jun 2010 09:21:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>An MFC based ActiveX may crash Excel 2003 when inserted while recording a macro</title>
		<link>http://www.manvirsingh.net/index.php/an-mfc-based-activex-may-crash-excel-2003-when-inserted-while-recording-a-macro/</link>
		<comments>http://www.manvirsingh.net/index.php/an-mfc-based-activex-may-crash-excel-2003-when-inserted-while-recording-a-macro/#comments</comments>
		<pubDate>Sun, 31 May 2009 01:19:25 +0000</pubDate>
		<dc:creator>Manvir</dc:creator>
				<category><![CDATA[Office Automation]]></category>
		<category><![CDATA[activex]]></category>
		<category><![CDATA[crash]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://www.manvirsingh.net/?p=10</guid>
		<description><![CDATA[Let’s say we have created an ActiveX control using the wizard in Visual Studio 2008, and have checked the “Available in Insert Object Dialog” checkbox on the last page of the wizard as shown below: As the name suggests, this setting enables the ActiveX control to be in “Insert Object” dialog box, which is available [...]]]></description>
			<content:encoded><![CDATA[<p>Let’s say we have created an ActiveX control using the wizard in Visual Studio 2008, and have checked the “Available in Insert Object Dialog” checkbox on the last page of the wizard as shown below:</p>
<p style="text-align: center;"><img class="size-full wp-image-14 aligncenter" title="MFC ActiveX Control Wizard" src="http://www.manvirsingh.net/wp-content/uploads/2009/05/mfcwizard.jpg" alt="MFC ActiveX Control Wizard" width="614" height="523" /></p>
<p>As the name suggests, this setting enables the ActiveX control to be in “Insert Object” dialog box, which is available in most Compound Document container applications, such as, Wordpad, Word, Excel, PowerPoint, etc.</p>
<p>Now, when we insert such an ActiveX to Excel 2003 (using this Insert Object dialog box) while we are recording a macro; Excel may crash.</p>
<p>This happens because the default MFC implementation of the ActiveX enables it to capture the focus when instantiated. So, when we insert it to Excel while recording a macro, our ActiveX gets the focus and this causes Excel to crash.</p>
<p>If our ActiveX is not a compound document object (like Word document, PowerPoint spreadsheet etc.) then we can avoid this crash by modifying our ActiveX code generated by the MFC wizard. Here are the steps to achieve this:</p>
<ol>
<li>Open the <em>ActiveX</em>Ctrl.cpp file (here <em>ActiveX</em> is the name that you have given to your control).</li>
<li>Scroll down to the following comment and code block:</li>
<p style="text-align: left; padding-left: 60px;"><code>// Control type information<br />
</code></p>
<p style="text-align: left; padding-left: 60px;"><code>static const DWORD BASED_CODE _dwAxTest1OleMisc =<br />
OLEMISC_ACTIVATEWHENVISIBLE |<br />
OLEMISC_SETCLIENTSITEFIRST |<br />
OLEMISC_INSIDEOUT |<br />
OLEMISC_CANTLINKINSIDE |<br />
OLEMISC_RECOMPOSEONRESIZE;</code></p>
<p style="text-align: left; padding-left: 60px;"><code><br />
</code></p>
<li>Now OR a new flag <strong>OLEMISC_NOUIACTIVATE</strong> to the above list, as below:</li>
<p style="padding-left: 60px;"><code>// Control type information</code></p>
<p style="padding-left: 60px;"><code>static const DWORD BASED_CODE _dwAxTest1OleMisc =<br />
OLEMISC_ACTIVATEWHENVISIBLE |<br />
OLEMISC_SETCLIENTSITEFIRST |<br />
OLEMISC_INSIDEOUT |<br />
OLEMISC_CANTLINKINSIDE |<br />
OLEMISC_RECOMPOSEONRESIZE |<br />
<span style="color: #ff0000;"><strong>OLEMISC_NOUIACTIVATE</strong></span>;</code></p>
<p style="padding-left: 60px;"><code><br />
</code></ol>
<p>This flag ensures that our ActiveX will not get activated (or gain focus) when it is instantiated, thereby avoiding the crash in Excel 2003.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.manvirsingh.net/index.php/an-mfc-based-activex-may-crash-excel-2003-when-inserted-while-recording-a-macro/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
