<?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>Maurice&#039;s Musings &#187; ie</title>
	<atom:link href="http://www.calvert.ch/maurice/tag/ie/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.calvert.ch/maurice</link>
	<description>On People, Life and Technology</description>
	<lastBuildDate>Sat, 04 Feb 2012 22:37:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Displaying images using the RES: protocol from a IE BHO</title>
		<link>http://www.calvert.ch/maurice/2009/08/27/displaying-images-using-the-res-protocol-from-a-ie-bho/</link>
		<comments>http://www.calvert.ch/maurice/2009/08/27/displaying-images-using-the-res-protocol-from-a-ie-bho/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 15:12:11 +0000</pubDate>
		<dc:creator>maurice</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[addin]]></category>
		<category><![CDATA[ie]]></category>

		<guid isPermaLink="false">http://www.calvert.ch/maurice/?p=156</guid>
		<description><![CDATA[Problem: You&#8217;re using Visual Studio to write a Browser Helper Object for Internet Explorer and you want to add some images to the web page being displayed. Here is an example, taken from my Affine addin. The two images I insert are shown by the arrow: Finding out how to do this is trickier than <a href='http://www.calvert.ch/maurice/2009/08/27/displaying-images-using-the-res-protocol-from-a-ie-bho/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Problem: You&#8217;re using Visual Studio to write a Browser Helper Object for Internet<br />
Explorer and you want to add some images to the web page being displayed.</p>
<p>Here is an example, taken from my <a href="http://www.calvert.ch/affine">Affine addin</a>. The two images I insert are shown by the arrow:</p>
<p><img class="alignleft size-full wp-image-161" style="border:1px solid" src="http://www.calvert.ch/maurice/files/2009/08/ss11.jpg" alt="Affine in action" width="496" height="201" /></p>
<p>Finding out how to do this is trickier than expected, so here&#8217;s the recipe:</p>
<ol>
<li>Import the images into the project and create a .RC file which identifies them:<br />
<blockquote><p>affinehide.bmp bitmap &#034;affinehide.bmp&#034;<br />
affinefade.bmp bitmap &#034;affinefade.bmp&#034;</p></blockquote>
<p>I called this file images.rc in the images directory in my project.</li>
<li>You&#8217;ll need RC.EXE, the resource compiler, which is in the Windows SDK. The<br />
2008 version for .NET 3.5 is <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=53F9CBB4-B4AF-4CF2-BFE5-260CFB90F7C3&amp;displaylang=en">here</a></li>
<li>In your setup project&#8217;s, set the prebuild event to<br />
<blockquote><p>&#034;D:Affinerc.exe&#034; /r &#034;d:affineimagesimages.rc&#034;</p></blockquote>
<p>I copied RC.exe into my project directory because I sometimes work on a 64-bit box, where Program Files becomes Program Files (X86). Adjust the paths to suit your installation.</li>
<li>Open your project&#8217;s .VBPROJ file and insert the three red lines shown:<br />
<blockquote><p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#034;utf-8&#034;?&gt;<br />
&lt;Project DefaultTargets=&#034;Build&#034;<br />
xmlns=&#034;http://schemas.microsoft.com/developer/msbuild/2003&#034;<br />
ToolsVersion=&#034;3.5&#034;&gt;<span style="color:red;font-weight:bold"><br />
&lt;PropertyGroup&gt;<br />
&lt;Win32Resource&gt;imagesimages.res&lt;/Win32Resource&gt;<br />
&lt;/PropertyGroup&gt;</span><br />
&lt;PropertyGroup&gt;<br />
&lt;Configuration Condition=&#034; &#039;$(Configuration)&#039; == &#039;&#039; &#034;&gt;Debug&lt;/Configuration&gt;
</p></blockquote>
<p>Thanks to <a href="http://blogs.infosupport.com/blogs/wouterv/">Wouter van Vugt</a> for this!</li>
<li>The HTML to insert the images is straightforward:<br />
<blockquote><p>&lt;img src=&#034;res://affine.dll/#2/affinehide.bmp&#034;</p></blockquote>
<p>where #2 means that the embedded object is an image<br />
Assuming this string is stored in the variable &#034;buttonhtml&#034; then the code to insert the button on the page is</p>
<blockquote><p>a.insertAdjacentHTML(&amp;#34afterEnd&amp;#34, buttonhtml)</p></blockquote>
</li>
<li>Now for the events. You need an event handler for the DHTML event itself:<br />
<blockquote><p>
Imports mshtml<br />
Public Delegate Sub DHTMLEvent(ByVal e As IHTMLEventObj)<br />
 _<br />
Public Class DHTMLEventHandler<br />
    Public Handler As DHTMLEvent<br />
    Private Document As mshtml.IHTMLDocument<br />
    Public Sub New(ByVal doc As mshtml.IHTMLDocument)<br />
        Me.Document = doc<br />
    End Sub<br />
     _<br />
    Public Sub [Call]()<br />
        Handler(CType(Document.parentWindow.event, mshtml.IHTMLEventObj))<br />
    End Sub<br />
End Class</p></blockquote>
<p>Thanks to <a href="http://www.west-wind.com/Weblog/posts/393.aspx">Rick Strahl</a></li>
<li>A handler which the above will call, to actually deal with the event:<br />
<blockquote><p>
Imports mshtml<br />
Module BrowserEventHandler_<br />
    Public Sub BrowserEventHandler(ByVal e As mshtml.IHTMLEventObj)<br />
        Try<br />
            If e.type = &#034;click&#034;&#8221; AndAlso e.srcElement.tagName = &#034;IMG&#034; Then<br />
&#8230;</p></blockquote>
<li>and finally tghe code to add in in your DocumentComplete event:<br />
<blockquote><p>
Dim Handler As DHTMLEventHandler = New DHTMLEventHandler(doc)<br />
Handler.Handler = AddressOf BrowserEventHandler<br />
doc.onclick = Handler</p></blockquote>
</li>
</ol>
<p>Happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.calvert.ch/maurice/2009/08/27/displaying-images-using-the-res-protocol-from-a-ie-bho/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

