<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Secretbytes's Weblog</title>
	<atom:link href="http://secretbytes.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://secretbytes.wordpress.com</link>
	<description>Programming Tips and Tricks</description>
	<lastBuildDate>Sat, 18 Dec 2010 09:02:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='secretbytes.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Secretbytes's Weblog</title>
		<link>http://secretbytes.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://secretbytes.wordpress.com/osd.xml" title="Secretbytes&#039;s Weblog" />
	<atom:link rel='hub' href='http://secretbytes.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Finding registered application for an extension.</title>
		<link>http://secretbytes.wordpress.com/2008/12/16/finding-registred-application-for-an-extension/</link>
		<comments>http://secretbytes.wordpress.com/2008/12/16/finding-registred-application-for-an-extension/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 17:44:02 +0000</pubDate>
		<dc:creator>secretbytes</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://secretbytes.wordpress.com/?p=70</guid>
		<description><![CDATA[One day my colleague asked me if there is a way to know the registered application to a specific extension, or how OS executes Notepad when user double clicks on any txt files. Here is my finding over it. And here is the sample application source &#160; using System; using Microsoft.Win32; &#160; namespace FileAssociationCheck { [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=secretbytes.wordpress.com&amp;blog=3612912&amp;post=70&amp;subd=secretbytes&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><!--[if gte mso 9]&gt;  Normal 0     false false false  EN-US X-NONE X-NONE              MicrosoftInternetExplorer4              &lt;![endif]--><!--[if gte mso 9]&gt;                                                                                                                                            &lt;![endif]--> <!--[if gte mso 10]&gt; &lt;!   /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Table Normal"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-priority:99; 	mso-style-qformat:yes; 	mso-style-parent:""; 	mso-padding-alt:0in 5.4pt 0in 5.4pt; 	mso-para-margin-top:0in; 	mso-para-margin-right:0in; 	mso-para-margin-bottom:10.0pt; 	mso-para-margin-left:0in; 	line-height:115%; 	mso-pagination:widow-orphan; 	font-size:11.0pt; 	font-family:"Calibri","sans-serif"; 	mso-ascii-font-family:Calibri; 	mso-ascii-theme-font:minor-latin; 	mso-fareast-font-family:"Times New Roman"; 	mso-fareast-theme-font:minor-fareast; 	mso-hansi-font-family:Calibri; 	mso-hansi-theme-font:minor-latin;} --> <!--[endif]--></p>
<p class="MsoNormal">One day my colleague asked me if there is a way to know the registered application to a specific extension, or how OS executes Notepad when user double clicks on any txt files. Here is my finding over it.<span id="more-70"></span></p>
<p class="MsoNormal"><a rel="attachment wp-att-71" href="http://secretbytes.wordpress.com/2008/12/16/finding-registred-application-for-an-extension/tst/"><img class="aligncenter size-full wp-image-71" title="Flowchart" src="http://secretbytes.files.wordpress.com/2008/12/tst.jpg?w=468&#038;h=419" alt="Flowchart" width="468" height="419" /></a></p>
<p class="MsoNormal">And here is the sample application source</p>
<p class="MsoNormal">&nbsp;</p>
<div style="background:white none repeat scroll 0 0;font-family:Courier New;font-size:10pt;color:black;">
<p style="margin:0;"><span style="color:blue;">using</span> System;</p>
<p style="margin:0;"><span style="color:blue;">using</span> Microsoft.Win32;</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;"><span style="color:blue;">namespace</span> FileAssociationCheck</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:blue;">class</span> <span style="color:#2b91af;">Program</span></p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:blue;">static</span> <span style="color:blue;">void</span> Main(<span style="color:blue;">string</span>[] args)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:blue;">while</span> (<span style="color:blue;">true</span>)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#2b91af;">Console</span>.WriteLine(<span style="color:#a31515;">&#8220;Extension:&#8221;</span>);</p>
<p style="margin:0;"><span style="color:blue;">string</span> val = GetAssociatedFileName(<span style="color:#2b91af;">Console</span>.ReadLine());</p>
<p style="margin:0;"><span style="color:#2b91af;">Console</span>.WriteLine(val);</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">}</p>
<p style="margin:0;">}</p>
<p style="margin:0;"><span style="color:blue;">private</span> <span style="color:blue;">static</span> <span style="color:blue;">string</span> GetAssociatedFileName(<span style="color:blue;">string</span> Extension)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#2b91af;">RegistryKey</span> ClassRoot = <span style="color:#2b91af;">Registry</span>.ClassesRoot;</p>
<p style="margin:0;"><span style="color:#2b91af;">String</span> AssociatedFileName = <span style="color:#a31515;">&#8220;&#8221;</span>;</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;"><span style="color:blue;">if</span> (ClassRoot != <span style="color:blue;">null</span>)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:blue;">try</span></p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#2b91af;">RegistryKey</span> ExtensionKey = ClassRoot.OpenSubKey(Extension);</p>
<p style="margin:0;"><span style="color:blue;">if</span> (ExtensionKey != <span style="color:blue;">null</span>)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:blue;">string</span> ExtensionValue = (<span style="color:blue;">string</span>) ExtensionKey.GetValue(<span style="color:#a31515;">&#8220;&#8221;</span>);</p>
<p style="margin:0;"><span style="color:#2b91af;">RegistryKey</span> FileTypeKey = ClassRoot.OpenSubKey(ExtensionValue);</p>
<p style="margin:0;"><span style="color:blue;">if</span> (FileTypeKey != <span style="color:blue;">null</span>)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#2b91af;">RegistryKey</span> ShellKey = FileTypeKey.OpenSubKey(<span style="color:#a31515;">&#8220;shell&#8221;</span>);</p>
<p style="margin:0;"><span style="color:blue;">if</span> (ShellKey != <span style="color:blue;">null</span>)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#2b91af;">String</span> FileType = (<span style="color:#2b91af;">String</span>) ShellKey.GetValue(<span style="color:#a31515;">&#8220;&#8221;</span>);</p>
<p style="margin:0;">AssociatedFileName = <span style="color:#2b91af;">String</span>.IsNullOrEmpty(FileType)</p>
<p style="margin:0;">? OpenDefaultKey(ShellKey)</p>
<p style="margin:0;">: OpenSpecifiedKey(ShellKey, FileType);</p>
<p style="margin:0;">}</p>
<p style="margin:0;">FileTypeKey.Close();</p>
<p style="margin:0;">}</p>
<p style="margin:0;">ExtensionKey.Close();</p>
<p style="margin:0;">}</p>
<p style="margin:0;">}</p>
<p style="margin:0;"><span style="color:blue;">catch</span> (<span style="color:#2b91af;">Exception</span> ex)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#2b91af;">Console</span>.WriteLine(ex.Message);</p>
<p style="margin:0;">}</p>
<p style="margin:0;">ClassRoot.Close();</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">}</p>
<p style="margin:0;"><span style="color:blue;">return</span> ParseString(AssociatedFileName);</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">}</p>
<p style="margin:0;"><span style="color:blue;">private</span> <span style="color:blue;">static</span> <span style="color:blue;">readonly</span> <span style="color:blue;">char</span>[] nonChars = <span style="color:blue;">new</span>[] {<span style="color:#a31515;">&#8216;&amp;&#8217;</span>,<span style="color:#a31515;">&#8216;&#8221;&#8216;</span>, <span style="color:#a31515;">&#8216;/&#8217;</span>,<span style="color:#a31515;">&#8216;%&#8217;</span>,<span style="color:#a31515;">&#8216;*&#8217;</span>};</p>
<p style="margin:0;"><span style="color:blue;">private</span> <span style="color:blue;">static</span> <span style="color:blue;">string</span> ParseString(<span style="color:blue;">string</span> name)</p>
<p style="margin:0;">{</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">name = name.Trim(nonChars);</p>
<p style="margin:0;"><span style="color:blue;">string</span>[] split = name.Split(nonChars);</p>
<p style="margin:0;"><span style="color:blue;">if</span>(split.Length &gt;0)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:blue;">string</span> str= split[0].Trim();</p>
<p style="margin:0;"><span style="color:blue;">return</span> str;</p>
<p style="margin:0;">}</p>
<p style="margin:0;"><span style="color:blue;">return</span> <span style="color:#a31515;">&#8220;&#8221;</span>;</p>
<p style="margin:0;">}</p>
<p style="margin:0;"><span style="color:blue;">private</span> <span style="color:blue;">static</span> <span style="color:blue;">string</span> OpenSpecifiedKey(<span style="color:#2b91af;">RegistryKey</span> ShellKey, <span style="color:blue;">string</span> CommandType)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:blue;">string</span> Value = <span style="color:#a31515;">&#8220;&#8221;</span>;</p>
<p style="margin:0;"><span style="color:#2b91af;">RegistryKey</span> SpecifiedKey = ShellKey.OpenSubKey(CommandType);</p>
<p style="margin:0;"><span style="color:blue;">if</span>(SpecifiedKey==<span style="color:blue;">null</span>)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:blue;">string</span>[] names = ShellKey.GetSubKeyNames();</p>
<p style="margin:0;"><span style="color:blue;">if</span>(names.Length&gt;0)</p>
<p style="margin:0;">{</p>
<p style="margin:0;">SpecifiedKey = ShellKey.OpenSubKey(names[0]);</p>
<p style="margin:0;">}</p>
<p style="margin:0;">}</p>
<p style="margin:0;"><span style="color:blue;">if</span> (SpecifiedKey != <span style="color:blue;">null</span>)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#2b91af;">RegistryKey</span> CommandKey = SpecifiedKey.OpenSubKey(<span style="color:#a31515;">&#8220;command&#8221;</span>);</p>
<p style="margin:0;"><span style="color:blue;">if</span> (CommandKey != <span style="color:blue;">null</span>)</p>
<p style="margin:0;">{</p>
<p style="margin:0;">Value = (<span style="color:blue;">string</span>)CommandKey.GetValue(<span style="color:#a31515;">&#8220;&#8221;</span>);</p>
<p style="margin:0;">CommandKey.Close();</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">}</p>
<p style="margin:0;">SpecifiedKey.Close();</p>
<p style="margin:0;">}</p>
<p style="margin:0;"><span style="color:blue;">return</span> Value;</p>
<p style="margin:0;">}</p>
<p style="margin:0;"><span style="color:blue;">private</span> <span style="color:blue;">static</span> <span style="color:blue;">string</span> OpenDefaultKey(<span style="color:#2b91af;">RegistryKey</span> ShellKey)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#2b91af;">String</span> Value = <span style="color:#a31515;">&#8220;&#8221;</span>;</p>
<p style="margin:0;"><span style="color:#2b91af;">RegistryKey</span> OpenKey = ShellKey.OpenSubKey(<span style="color:#a31515;">&#8220;Open&#8221;</span>);</p>
<p style="margin:0;"><span style="color:blue;">if</span>(OpenKey==<span style="color:blue;">null</span>)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:blue;">string</span>[] names = ShellKey.GetSubKeyNames();</p>
<p style="margin:0;"><span style="color:blue;">if</span>(names.Length&gt;0)</p>
<p style="margin:0;">{</p>
<p style="margin:0;">OpenKey = ShellKey.OpenSubKey(names[0]);</p>
<p style="margin:0;">}</p>
<p style="margin:0;">}</p>
<p style="margin:0;"><span style="color:blue;">if</span> (OpenKey != <span style="color:blue;">null</span>)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#2b91af;">RegistryKey</span> CommandKey = OpenKey.OpenSubKey(<span style="color:#a31515;">&#8220;Command&#8221;</span>);</p>
<p style="margin:0;"><span style="color:blue;">if</span> (CommandKey != <span style="color:blue;">null</span>)</p>
<p style="margin:0;">{</p>
<p style="margin:0;">Value= (<span style="color:blue;">string</span>) CommandKey.GetValue(<span style="color:#a31515;">&#8220;&#8221;</span>);</p>
<p style="margin:0;">CommandKey.Close();</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">}</p>
<p style="margin:0;">OpenKey.Close();</p>
<p style="margin:0;">}</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;"><span style="color:blue;">return</span> Value;</p>
<p style="margin:0;">}</p>
<p style="margin:0;">}</p>
<p style="margin:0;">}</p>
<p style="margin:0;">The program produce output as</p>
<p style="margin:0;">Extension:<br />
.msi<br />
G:\WINDOWS\System32\msiexec.exe<br />
Extension:<br />
.dll<br />
E:\Reverse engineering\Software\Olly Engines\odbg110 Shadow\Shadow.exe<br />
Extension:<br />
.rar<br />
G:\Program Files\WinRAR\WinRAR.exe<br />
Extension:<br />
.dfaff</p>
<p>Extension:<br />
.txt<br />
G:\WINDOWS\system32\NOTEPAD.EXE<br />
Extension:<br />
.docx<br />
G:\Program Files\Microsoft Office\Office12\WINWORD.EXE<br />
Extension:<br />
.doc<br />
G:\Program Files\Microsoft Office\Office12\WINWORD.EXE<br />
Extension:<br />
.elx</p>
<p>Extension:<br />
.msg<br />
G:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE<br />
Extension:<br />
.rar<br />
G:\Program Files\WinRAR\WinRAR.exe<br />
Extension:<br />
.7z<br />
G:\Program Files\WinRAR\WinRAR.exe<br />
Extension:</p>
</div>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fsecretbytes.wordpress.com%2f2008%2f12%2f16%2ffinding-registred-application-for-an-extension%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fsecretbytes.wordpress.com%2f2008%2f12%2f16%2ffinding-registred-application-for-an-extension%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/secretbytes.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/secretbytes.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/secretbytes.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/secretbytes.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/secretbytes.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/secretbytes.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/secretbytes.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/secretbytes.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/secretbytes.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/secretbytes.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/secretbytes.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/secretbytes.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/secretbytes.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/secretbytes.wordpress.com/70/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=secretbytes.wordpress.com&amp;blog=3612912&amp;post=70&amp;subd=secretbytes&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://secretbytes.wordpress.com/2008/12/16/finding-registred-application-for-an-extension/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/57f465bd3cfe1961e45b3b950a9b9de3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">secretbytes</media:title>
		</media:content>

		<media:content url="http://secretbytes.files.wordpress.com/2008/12/tst.jpg" medium="image">
			<media:title type="html">Flowchart</media:title>
		</media:content>

		<media:content url="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fsecretbytes.wordpress.com%2f2008%2f12%2f16%2ffinding-registred-application-for-an-extension%2f" medium="image">
			<media:title type="html">kick it on DotNetKicks.com</media:title>
		</media:content>
	</item>
		<item>
		<title>Different ways to cut the current line(VS 2008)</title>
		<link>http://secretbytes.wordpress.com/2008/10/27/different-ways-to-cut-the-current-linevs-2008/</link>
		<comments>http://secretbytes.wordpress.com/2008/10/27/different-ways-to-cut-the-current-linevs-2008/#comments</comments>
		<pubDate>Mon, 27 Oct 2008 17:23:02 +0000</pubDate>
		<dc:creator>secretbytes</dc:creator>
				<category><![CDATA[Visual studio]]></category>
		<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://secretbytes.wordpress.com/?p=65</guid>
		<description><![CDATA[In earlier days if I had to cut the current line from the visual studio I used to select all the line, keeping Cursor at the beginning and pressing Shift+End key to select the whole line and Cut the line using Ctrl+X, later I knew I could only use Ctrl+X without selecting anything from the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=secretbytes.wordpress.com&amp;blog=3612912&amp;post=65&amp;subd=secretbytes&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In earlier days if I had to cut the current line from the visual studio I used to select all the line, keeping Cursor at the beginning and pressing Shift+End key to select the whole line and Cut the line using Ctrl+X, later I knew I could only use <span style="color:#0000ff;">Ctrl+X</span> without selecting anything from the line.Again later I knew there was  another way to do the same job; keeping cursor at the desired line and pressing <span style="color:#0000ff;">Shift+Delete</span>. Again later I found <span style="color:#0000ff;">Ctrl+L</span> would also perform the same job. So there are 4 ways I know choose whatever suits you best.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/secretbytes.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/secretbytes.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/secretbytes.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/secretbytes.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/secretbytes.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/secretbytes.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/secretbytes.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/secretbytes.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/secretbytes.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/secretbytes.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/secretbytes.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/secretbytes.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/secretbytes.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/secretbytes.wordpress.com/65/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=secretbytes.wordpress.com&amp;blog=3612912&amp;post=65&amp;subd=secretbytes&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://secretbytes.wordpress.com/2008/10/27/different-ways-to-cut-the-current-linevs-2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/57f465bd3cfe1961e45b3b950a9b9de3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">secretbytes</media:title>
		</media:content>
	</item>
		<item>
		<title>Copying Text From MessageBox</title>
		<link>http://secretbytes.wordpress.com/2008/10/16/copying-text-from-messagebox/</link>
		<comments>http://secretbytes.wordpress.com/2008/10/16/copying-text-from-messagebox/#comments</comments>
		<pubDate>Thu, 16 Oct 2008 05:20:03 +0000</pubDate>
		<dc:creator>secretbytes</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://secretbytes.wordpress.com/?p=60</guid>
		<description><![CDATA[Ever wondered you could actually copy text from a MessageBox. I  found this great gem in one blog(sorry I forgot the name). Press Ctrl+C while MessageBox has a focus. This produces output as: &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; Error &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; Some Error Code: 0x0123456F &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; OK &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;. This really helps your frustrating minutes to write those Error code manually [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=secretbytes.wordpress.com&amp;blog=3612912&amp;post=60&amp;subd=secretbytes&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal">Ever wondered you could actually copy text from a MessageBox. I  found this great gem in one blog(sorry I forgot the name).</p>
<p class="MsoNormal">Press Ctrl+C while MessageBox has a focus.</p>
<p class="MsoNormal"><!--[if gte vml 1]&gt;                    &lt;![endif]--><!--[if !vml]--><!--[endif]--></p>
<p class="MsoNormal"><a href="http://secretbytes.files.wordpress.com/2008/10/untitled.jpg"><img class="alignnone size-full wp-image-61" title="MessageBox" src="http://secretbytes.files.wordpress.com/2008/10/untitled.jpg?w=468" alt=""   /></a></p>
<p class="MsoNormal">This produces output as:</p>
<p class="MsoNormal">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p class="MsoNormal">Error</p>
<p class="MsoNormal">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p class="MsoNormal">Some Error Code: 0x0123456F</p>
<p class="MsoNormal">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p class="MsoNormal">OK<span> </span></p>
<p class="MsoNormal">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;.</p>
<p class="MsoNormal">
<p class="MsoNormal">This really helps your frustrating minutes to write those Error code manually to a text editor.</p>
<p class="MsoNormal">Isn’t it a great tip?</p>
<p class="MsoNormal"><span> </span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/secretbytes.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/secretbytes.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/secretbytes.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/secretbytes.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/secretbytes.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/secretbytes.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/secretbytes.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/secretbytes.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/secretbytes.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/secretbytes.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/secretbytes.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/secretbytes.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/secretbytes.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/secretbytes.wordpress.com/60/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=secretbytes.wordpress.com&amp;blog=3612912&amp;post=60&amp;subd=secretbytes&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://secretbytes.wordpress.com/2008/10/16/copying-text-from-messagebox/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/57f465bd3cfe1961e45b3b950a9b9de3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">secretbytes</media:title>
		</media:content>

		<media:content url="http://secretbytes.files.wordpress.com/2008/10/untitled.jpg" medium="image">
			<media:title type="html">MessageBox</media:title>
		</media:content>
	</item>
		<item>
		<title>LinQ!!Getting the associated file icons</title>
		<link>http://secretbytes.wordpress.com/2008/09/12/linqgetting-the-associated-file-icons/</link>
		<comments>http://secretbytes.wordpress.com/2008/09/12/linqgetting-the-associated-file-icons/#comments</comments>
		<pubDate>Fri, 12 Sep 2008 06:01:35 +0000</pubDate>
		<dc:creator>secretbytes</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://secretbytes.wordpress.com/?p=56</guid>
		<description><![CDATA[LinQ has always fascinated me ever since it was first released and I have been learning it ever since. The following snippet could act as a tutorial, especially to the beginners thriving to learn LinQ. Before writing this, I did a bit of browsing on how to get the associated icon for the file extension. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=secretbytes.wordpress.com&amp;blog=3612912&amp;post=56&amp;subd=secretbytes&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal">LinQ has always fascinated me ever since it was first released and I have been learning it ever since. The following snippet could act as a tutorial, especially to the beginners thriving to learn LinQ. Before writing this, I did a bit of browsing on how to get the associated icon for the file extension. I found many likely hits using primitive techniques but none using LinQ. So I decided to write one myself. Even though the code isn’t optimized, it does what it is meant to do and more, it is quite simple to read and understand. Here goes:</p>
<p class="MsoNormal">
<p><!-- {\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red1\green0\blue1;\red43\green145\blue175;\red163\green21\blue21;}??\fs20 \cf1 var\cf0  \cf4 x\cf0  = \cf1 from\cf0  \cf4 A\cf0  \cf1 in\par ??\cf0                  \cf1 from\cf0  \cf4 B\cf0  \cf1 in\par ??\cf0                      \cf1 from\cf0  \cf4 C\cf0  \cf1 in\par ??\cf0                          \cf1 from\cf0  \cf4 D\cf0  \cf1 in\par ??\cf0                              (\cf1 from\cf0  \cf4 E\cf0  \cf1 in\cf0  \cf5 Registry\cf0 .\cf4 ClassesRoot\cf0 .\cf4 GetSubKeyNames\cf0 ()\par ??                              \cf1 where\par ??\cf0                                   \cf4 E\cf0 .\cf4 StartsWith\cf0 (\cf6 "."\cf0 )\par ??                              \cf1 select\par ??\cf0                                   \cf1 new\par ??\cf0                                       \{   \cf4 Extension\cf0  = \cf4 E\cf0 ,\par ??                                          \cf4 Key\cf0  =\par ??                                  \cf5 Convert\cf0 .\cf4 ToString\cf0 (\cf5 Registry\cf0 .\cf4 ClassesRoot\cf0 .\cf4 OpenSubKey\cf0 (\cf4 E\cf0 ).\cf4 GetValue\cf0 (\cf6 ""\cf0 ))\par ??                                      \})\par ??                         \cf1 where\cf0  \cf4 D\cf0  != \cf1 null\par ??\cf0                          \cf1 select\cf0  \cf1 new\cf0  \{\cf4 D\cf0 .\cf4 Extension\cf0 , \cf4 Ico\cf0  = \cf5 Registry\cf0 .\cf4 ClassesRoot\cf0 .\cf4 OpenSubKey\cf0 (\cf4 D\cf0 .\cf4 Key\cf0 )\}\par ??                     \cf1 where\cf0  \cf4 C\cf0 .\cf4 Ico\cf0  != \cf1 null\par ??\cf0                      \cf1 select\cf0  \cf1 new\cf0  \{\cf4 C\cf0 .\cf4 Extension\cf0 , \cf4 Val\cf0  = \cf4 C\cf0 .\cf4 Ico\cf0 .\cf4 OpenSubKey\cf0 (\cf6 "DefaultIcon"\cf0 )\}\par ??                 \cf1 where\cf0  \cf4 B\cf0 .\cf4 Val\cf0  != \cf1 null\par ??\cf0                  \cf1 select\cf0  \cf1 new\cf0  \{\cf4 B\cf0 .\cf4 Extension\cf0 , \cf4 FilePath\cf0  = \cf4 B\cf0 .\cf4 Val\cf0 .\cf4 GetValue\cf0 (\cf6 ""\cf0 ) \cf1 as\cf0  \cf5 String\cf0 \}\par ??             \cf1 where\cf0  \cf4 A\cf0  != \cf1 null\cf0  &amp;&amp; \cf4 A\cf0 .\cf4 FilePath\cf0  != \cf1 null\cf0  &amp;&amp; \cf4 A\cf0 .\cf4 FilePath\cf0 .\cf4 Split\cf0 (\cf6 ','\cf0 ).\cf4 Length\cf0  &gt; 1\par ??             \cf1 select\par ??\cf0                  \cf1 new\par ??\cf0                      \{\par ??                         \cf4 A\cf0 .\cf4 FilePath\cf0 ,\par ??                         \cf4 A\cf0 .\cf4 Extension\cf0 ,\par ??                         \cf4 Icon\cf0  =\par ??                 \cf4 Arjuns\cf0 .\cf4 Utilities\cf0 .\cf5 IconExtractor\cf0 .\cf4 GetIcon\cf0 (\cf4 A\cf0 .\cf4 FilePath\cf0 .\cf4 Split\cf0 (\cf6 ','\cf0 ).\cf4 ToArray\cf0 ()[0],\par ??                                               \cf5 Convert\cf0 .\cf4 ToInt32\cf0 (\cf4 A\cf0 .\cf4 FilePath\cf0 .\cf4 Split\cf0 (\cf6 ','\cf0 ).\cf4 ToArray\cf0 ()[1]))\par ??                     \};} --></p>
<div style="border:1px dashed #b3c8db;background:#f7fcfe none repeat scroll 0;font-family:Courier New;font-size:10pt;color:black;padding:0 0 0 10px;">
<p style="margin:0;"><span style="color:blue;">var</span> <span style="color:#010001;">x</span> = <span style="color:blue;">from</span> <span style="color:#010001;">A</span> <span style="color:blue;">in</span></p>
<p style="margin:0;"><span style="color:blue;">from</span> <span style="color:#010001;">B</span> <span style="color:blue;">in</span></p>
<p style="margin:0;"><span style="color:blue;">from</span> <span style="color:#010001;">C</span> <span style="color:blue;">in</span></p>
<p style="margin:0;"><span style="color:blue;">from</span> <span style="color:#010001;">D</span> <span style="color:blue;">in</span></p>
<p style="margin:0;">(<span style="color:blue;">from</span> <span style="color:#010001;">E</span> <span style="color:blue;">in</span> <span style="color:#2b91af;">Registry</span>.<span style="color:#010001;">ClassesRoot</span>.<span style="color:#010001;">GetSubKeyNames</span>()</p>
<p style="margin:0;"><span style="color:blue;">where</span></p>
<p style="margin:0;"><span style="color:#010001;">E</span>.<span style="color:#010001;">StartsWith</span>(<span style="color:#a31515;">&#8220;.&#8221;</span>)</p>
<p style="margin:0;"><span style="color:blue;">select</span></p>
<p style="margin:0;"><span style="color:blue;">new</span></p>
<p style="margin:0;">{   <span style="color:#010001;">Extension</span> = <span style="color:#010001;">E</span>,</p>
<p style="margin:0;"><span style="color:#010001;">Key</span> =</p>
<p style="margin:0;"><span style="color:#2b91af;">Convert</span>.<span style="color:#010001;">ToString</span>(<span style="color:#2b91af;">Registry</span>.<span style="color:#010001;">ClassesRoot</span>.<span style="color:#010001;">OpenSubKey</span>(<span style="color:#010001;">E</span>).<span style="color:#010001;">GetValue</span>(<span style="color:#a31515;">&#8220;&#8221;</span>))</p>
<p style="margin:0;">})</p>
<p style="margin:0;"><span style="color:blue;">where</span> <span style="color:#010001;">D</span> != <span style="color:blue;">null</span></p>
<p style="margin:0;"><span style="color:blue;">select</span> <span style="color:blue;">new</span> {<span style="color:#010001;">D</span>.<span style="color:#010001;">Extension</span>, <span style="color:#010001;">Ico</span> = <span style="color:#2b91af;">Registry</span>.<span style="color:#010001;">ClassesRoot</span>.<span style="color:#010001;">OpenSubKey</span>(<span style="color:#010001;">D</span>.<span style="color:#010001;">Key</span>)}</p>
<p style="margin:0;"><span style="color:blue;">where</span> <span style="color:#010001;">C</span>.<span style="color:#010001;">Ico</span> != <span style="color:blue;">null</span></p>
<p style="margin:0;"><span style="color:blue;">select</span> <span style="color:blue;">new</span> {<span style="color:#010001;">C</span>.<span style="color:#010001;">Extension</span>, <span style="color:#010001;">Val</span> = <span style="color:#010001;">C</span>.<span style="color:#010001;">Ico</span>.<span style="color:#010001;">OpenSubKey</span>(<span style="color:#a31515;">&#8220;DefaultIcon&#8221;</span>)}</p>
<p style="margin:0;"><span style="color:blue;">where</span> <span style="color:#010001;">B</span>.<span style="color:#010001;">Val</span> != <span style="color:blue;">null</span></p>
<p style="margin:0;"><span style="color:blue;">select</span> <span style="color:blue;">new</span> {<span style="color:#010001;">B</span>.<span style="color:#010001;">Extension</span>, <span style="color:#010001;">FilePath</span> = <span style="color:#010001;">B</span>.<span style="color:#010001;">Val</span>.<span style="color:#010001;">GetValue</span>(<span style="color:#a31515;">&#8220;&#8221;</span>) <span style="color:blue;">as</span> <span style="color:#2b91af;">String</span>}</p>
<p style="margin:0;"><span style="color:blue;">where</span> <span style="color:#010001;">A</span> != <span style="color:blue;">null</span> &amp;&amp; <span style="color:#010001;">A</span>.<span style="color:#010001;">FilePath</span> != <span style="color:blue;">null</span> &amp;&amp; <span style="color:#010001;">A</span>.<span style="color:#010001;">FilePath</span>.<span style="color:#010001;">Split</span>(<span style="color:#a31515;">&#8216;,&#8217;</span>).<span style="color:#010001;">Length</span> &gt; 1</p>
<p style="margin:0;"><span style="color:blue;">select</span></p>
<p style="margin:0;"><span style="color:blue;">new</span></p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#010001;">A</span>.<span style="color:#010001;">FilePath</span>,</p>
<p style="margin:0;"><span style="color:#010001;">A</span>.<span style="color:#010001;">Extension</span>,</p>
<p style="margin:0;"><span style="color:#010001;">Icon</span> =</p>
<p style="margin:0;"><span style="color:#010001;">My</span>.<span style="color:#010001;">Utilities</span>.<span style="color:#2b91af;">IconExtractor</span>.<span style="color:#010001;">GetIcon</span>(<span style="color:#010001;">A</span>.<span style="color:#010001;">FilePath</span>.<span style="color:#010001;">Split</span>(<span style="color:#a31515;">&#8216;,&#8217;</span>).<span style="color:#010001;">ToArray</span>()[0],</p>
<p style="margin:0;"><span style="color:#2b91af;">Convert</span>.<span style="color:#010001;">ToInt32</span>(<span style="color:#010001;">A</span>.<span style="color:#010001;">FilePath</span>.<span style="color:#010001;">Split</span>(<span style="color:#a31515;">&#8216;,&#8217;</span>).<span style="color:#010001;">ToArray</span>()[1]))</p>
<p style="margin:0;">};</p>
</div>
<p class="MsoNormal">
<p class="MsoNormal">And another utility class to extract icon from file.</p>
<p><!-- {\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red1\green0\blue1;\red43\green145\blue175;\red163\green21\blue21;}??\fs20 \cf1 namespace\cf0  \cf4 Arjuns\cf0 .\cf4 Utilities\par ??\cf0 \{\par ??    \cf1 using\cf0  \cf4 System\cf0 ;\par ??    \cf1 using\cf0  \cf4 System\cf0 .\cf4 Runtime\cf0 .\cf4 InteropServices\cf0 ;\par ??    \cf1 using\cf0  \cf4 System\cf0 .\cf4 Drawing\cf0 ;\par ??    \par ??\par ??    \cf1 public\cf0  \cf1 class\cf0  \cf5 IconExtractor\par ??\cf0     \{\par ??        [\cf5 DllImport\cf0 (\cf6 "Kernel32.dll"\cf0 )]\par ??        \cf1 static\cf0  \cf1 extern\cf0  \cf1 int\cf0  \cf4 GetModuleHandle\cf0 (\cf1 string\cf0  \cf4 lpModuleName\cf0 );\par ??\par ??        [\cf5 DllImport\cf0 (\cf6 "Shell32.dll"\cf0 )]\par ??        \cf1 static\cf0  \cf1 extern\cf0  \cf5 IntPtr\cf0  \cf4 ExtractIcon\cf0 (\cf1 int\cf0  \cf4 Hinst\cf0 , \cf1 string\cf0  \cf4 FileName\cf0 , \cf1 int\cf0  \cf4 IconIndex\cf0 );\par ??\par ??        [\cf5 DllImport\cf0 (\cf6 "User32.dll"\cf0 )]\par ??         \cf1 static\cf0  \cf1 extern\cf0  \cf1 int\cf0  \cf4 DestroyIcon\cf0 (\cf5 IntPtr\cf0  \cf4 hIcon\cf0 );\par ??\par ??        \cf1 public\cf0  \cf1 static\cf0  \cf5 Icon\cf0  \cf4 GetIcon\cf0 (\cf1 string\cf0  \cf4 fileName\cf0 ,\cf1 int\cf0  \cf4 index\cf0 )\par ??        \{\par ??            \cf5 IntPtr\cf0  \cf4 HIcon\cf0 =\cf5 IntPtr\cf0 .\cf4 Zero\cf0 ;\par ??            \cf1 try\par ??\cf0             \{\par ??                \cf4 HIcon\cf0  = \cf4 ExtractIcon\cf0 (\cf4 GetModuleHandle\cf0 (\cf5 String\cf0 .\cf4 Empty\cf0 ), \cf4 fileName\cf0 , \cf4 index\cf0 );\par ??                \cf1 if\cf0  (\cf4 HIcon\cf0  == \cf5 IntPtr\cf0 .\cf4 Zero\cf0 ) \cf1 return\cf0  \cf1 null\cf0 ;\par ??                \cf1 return\cf0  \cf5 Icon\cf0 .\cf4 FromHandle\cf0 (\cf4 HIcon\cf0 ).\cf4 Clone\cf0 () \cf1 as\cf0  \cf5 Icon\cf0 ;\par ??            \}\par ??            \cf1 finally\par ??\cf0             \{\par ??                \cf4 DestroyIcon\cf0 (\cf4 HIcon\cf0 );\par ??            \}\par ??\par ??\par ??        \}\par ??\par ??        \par ??    \}\par ??\}} --></p>
<div style="border:1px dashed #b3c8db;background:#f7fcfe none repeat scroll 0;font-family:Courier New;font-size:10pt;color:black;padding:0 0 0 10px;">
<p style="margin:0;"><span style="color:blue;">namespace</span> My.<span style="color:#010001;">Utilities</span></p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:blue;">using</span> <span style="color:#010001;">System</span>;</p>
<p style="margin:0;"><span style="color:blue;">using</span> <span style="color:#010001;">System</span>.<span style="color:#010001;">Runtime</span>.<span style="color:#010001;">InteropServices</span>;</p>
<p style="margin:0;"><span style="color:blue;">using</span> <span style="color:#010001;">System</span>.<span style="color:#010001;">Drawing</span>;</p>
<p style="margin:0;">
<p style="margin:0;">
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">IconExtractor</span></p>
<p style="margin:0;">{</p>
<p style="margin:0;">[<span style="color:#2b91af;">DllImport</span>(<span style="color:#a31515;">"Kernel32.dll"</span>)]</p>
<p style="margin:0;"><span style="color:blue;">static</span> <span style="color:blue;">extern</span> <span style="color:blue;">int</span> <span style="color:#010001;">GetModuleHandle</span>(<span style="color:blue;">string</span> <span style="color:#010001;">lpModuleName</span>);</p>
<p style="margin:0;">
<p style="margin:0;">[<span style="color:#2b91af;">DllImport</span>(<span style="color:#a31515;">"Shell32.dll"</span>)]</p>
<p style="margin:0;"><span style="color:blue;">static</span> <span style="color:blue;">extern</span> <span style="color:#2b91af;">IntPtr</span> <span style="color:#010001;">ExtractIcon</span>(<span style="color:blue;">int</span> <span style="color:#010001;">Hinst</span>, <span style="color:blue;">string</span> <span style="color:#010001;">FileName</span>, <span style="color:blue;">int</span> <span style="color:#010001;">IconIndex</span>);</p>
<p style="margin:0;">
<p style="margin:0;">[<span style="color:#2b91af;">DllImport</span>(<span style="color:#a31515;">"User32.dll"</span>)]</p>
<p style="margin:0;"><span style="color:blue;">static</span> <span style="color:blue;">extern</span> <span style="color:blue;">int</span> <span style="color:#010001;">DestroyIcon</span>(<span style="color:#2b91af;">IntPtr</span> <span style="color:#010001;">hIcon</span>);</p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:blue;">static</span> <span style="color:#2b91af;">Icon</span> <span style="color:#010001;">GetIcon</span>(<span style="color:blue;">string</span> <span style="color:#010001;">fileName</span>,<span style="color:blue;">int</span> <span style="color:#010001;">index</span>)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#2b91af;">IntPtr</span> <span style="color:#010001;">HIcon</span>=<span style="color:#2b91af;">IntPtr</span>.<span style="color:#010001;">Zero</span>;</p>
<p style="margin:0;"><span style="color:blue;">try</span></p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#010001;">HIcon</span> = <span style="color:#010001;">ExtractIcon</span>(<span style="color:#010001;">GetModuleHandle</span>(<span style="color:#2b91af;">String</span>.<span style="color:#010001;">Empty</span>), <span style="color:#010001;">fileName</span>, <span style="color:#010001;">index</span>);</p>
<p style="margin:0;"><span style="color:blue;">if</span> (<span style="color:#010001;">HIcon</span> == <span style="color:#2b91af;">IntPtr</span>.<span style="color:#010001;">Zero</span>) <span style="color:blue;">return</span> <span style="color:blue;">null</span>;</p>
<p style="margin:0;"><span style="color:blue;">return</span> <span style="color:#2b91af;">Icon</span>.<span style="color:#010001;">FromHandle</span>(<span style="color:#010001;">HIcon</span>).<span style="color:#010001;">Clone</span>() <span style="color:blue;">as</span> <span style="color:#2b91af;">Icon</span>;</p>
<p style="margin:0;">}</p>
<p style="margin:0;"><span style="color:blue;">finally</span></p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#010001;">DestroyIcon</span>(<span style="color:#010001;">HIcon</span>);</p>
<p style="margin:0;">}</p>
<p style="margin:0;">
<p style="margin:0;">
<p style="margin:0;">}</p>
<p style="margin:0;">
<p style="margin:0;">
<p style="margin:0;">}</p>
<p style="margin:0;">}</p>
</div>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/secretbytes.wordpress.com/56/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/secretbytes.wordpress.com/56/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/secretbytes.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/secretbytes.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/secretbytes.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/secretbytes.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/secretbytes.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/secretbytes.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/secretbytes.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/secretbytes.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/secretbytes.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/secretbytes.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/secretbytes.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/secretbytes.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/secretbytes.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/secretbytes.wordpress.com/56/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=secretbytes.wordpress.com&amp;blog=3612912&amp;post=56&amp;subd=secretbytes&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://secretbytes.wordpress.com/2008/09/12/linqgetting-the-associated-file-icons/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/57f465bd3cfe1961e45b3b950a9b9de3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">secretbytes</media:title>
		</media:content>
	</item>
		<item>
		<title>RichTextBox without Image</title>
		<link>http://secretbytes.wordpress.com/2008/07/25/richtextbox-without-image/</link>
		<comments>http://secretbytes.wordpress.com/2008/07/25/richtextbox-without-image/#comments</comments>
		<pubDate>Fri, 25 Jul 2008 06:54:13 +0000</pubDate>
		<dc:creator>secretbytes</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Controls]]></category>

		<guid isPermaLink="false">http://secretbytes.wordpress.com/?p=50</guid>
		<description><![CDATA[One of my friend asked me if there is a way that could prevent Images being pasted in the RichTextBox control, so I did a little code that allows RichTextBox control not to include Images. The solution to this problem is very simple just override the OnKeyDown event and check if the clipboard contains data [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=secretbytes.wordpress.com&amp;blog=3612912&amp;post=50&amp;subd=secretbytes&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One of my friend asked me if there is a way that could prevent Images being pasted in the RichTextBox control, so I did a little code that allows RichTextBox control not to include Images.<br />
The solution to this problem is very simple just override the OnKeyDown event and check if the clipboard contains data of  Bitmap Type.</p>
<div style="font-family:Courier New;font-size:10pt;color:black;background:#F7FCFE;border:1px dashed #B3C8DB;padding:0 0 0 10px;">
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">RichTextBoxWithoutImage</span>:<span style="color:#2b91af;">RichTextBox</span></p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:blue;">protected</span> <span style="color:blue;">override</span> <span style="color:blue;">void</span> <span style="color:#010001;">OnKeyDown</span>(<span style="color:#2b91af;">KeyEventArgs</span> <span style="color:#010001;">e</span>)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:blue;">base</span>.<span style="color:#010001;">OnKeyDown</span>(<span style="color:#010001;">e</span>);</p>
<p style="margin:0;"><span style="color:green;">/*check for Ctrl+V*/</span></p>
<p style="margin:0;"><span style="color:blue;">if</span> (<span style="color:#010001;">e</span>.<span style="color:#010001;">Control</span> &amp;&amp; <span style="color:#010001;">e</span>.<span style="color:#010001;">KeyCode</span> == <span style="color:#2b91af;">Keys</span>.<span style="color:#010001;">V</span>)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#2b91af;">IDataObject</span> <span style="color:#010001;">obj</span> = <span style="color:#2b91af;">Clipboard</span>.<span style="color:#010001;">GetDataObject</span>();</p>
<p style="margin:0;"><span style="color:blue;">if</span> (<span style="color:#010001;">obj</span>.<span style="color:#010001;">GetDataPresent</span>(<span style="color:blue;">typeof</span>(<span style="color:#2b91af;">Bitmap</span>)))</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#010001;">e</span>.<span style="color:#010001;">Handled</span> = <span style="color:blue;">true</span>;</p>
<p style="margin:0;">}</p>
<p style="margin:0;">}</p>
<p style="margin:0;">}</p>
<p style="margin:0;">}</p>
</div>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/secretbytes.wordpress.com/50/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/secretbytes.wordpress.com/50/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/secretbytes.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/secretbytes.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/secretbytes.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/secretbytes.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/secretbytes.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/secretbytes.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/secretbytes.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/secretbytes.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/secretbytes.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/secretbytes.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/secretbytes.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/secretbytes.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/secretbytes.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/secretbytes.wordpress.com/50/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=secretbytes.wordpress.com&amp;blog=3612912&amp;post=50&amp;subd=secretbytes&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://secretbytes.wordpress.com/2008/07/25/richtextbox-without-image/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/57f465bd3cfe1961e45b3b950a9b9de3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">secretbytes</media:title>
		</media:content>
	</item>
		<item>
		<title>Getting information string from enum</title>
		<link>http://secretbytes.wordpress.com/2008/07/18/getting-information-string-from-enum/</link>
		<comments>http://secretbytes.wordpress.com/2008/07/18/getting-information-string-from-enum/#comments</comments>
		<pubDate>Fri, 18 Jul 2008 07:24:17 +0000</pubDate>
		<dc:creator>secretbytes</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Extension Method]]></category>
		<category><![CDATA[Reflection]]></category>

		<guid isPermaLink="false">http://secretbytes.wordpress.com/?p=36</guid>
		<description><![CDATA[The Idea came while I was writing a wrapper for PE file structure early this year that was even before I ever started writing bog. Loads of Enum has to be provided with their information. The solution was simple, attach a custom attribute to each member of the Enum and later retrieve them using reflection. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=secretbytes.wordpress.com&amp;blog=3612912&amp;post=36&amp;subd=secretbytes&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal">The Idea came while I was writing a wrapper for PE file structure early this year that was even before I ever started writing bog. Loads of Enum has to be provided with their information. The solution was simple, attach a custom attribute to each member of the Enum and later retrieve them using reflection.</p>
<p><!--Read more--></p>
<p class="MsoNormal">Here is how I did it all,<span id="more-36"></span></p>
<p class="MsoNormal">Create Attribute class i.e., <span style="font-size:10pt;font-family:&quot;color:#2b91af;">Info</span><span style="font-size:10pt;font-family:&quot;color:black;"> </span>,</p>
<div style="font-family:Courier New;font-size:10pt;color:black;background:#F7FCFE;border:1px dashed #B3C8DB;padding:0 0 0 10px;">
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">Info</span> : <span style="color:#2b91af;">Attribute</span></p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:blue;">string</span> <span style="color:#010001;">_name</span>;</p>
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:blue;">string</span> <span style="color:#010001;">Name</span></p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:blue;">get</span> { <span style="color:blue;">return</span> <span style="color:#010001;">_name</span>; }</p>
<p style="margin:0;"><span style="color:blue;">set</span> { <span style="color:#010001;">_name</span> = <span style="color:blue;">value</span>; }</p>
<p style="margin:0;">}</p>
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:#010001;">Info</span>(<span style="color:blue;">string</span> <span style="color:#010001;">name</span>)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:blue;">this</span>.<span style="color:#010001;">_name</span> = <span style="color:#010001;">name</span>;</p>
<p style="margin:0;">}</p>
<p style="margin:0;">}</p>
</div>
<p>Secondly the meat of all is a function that retrieves the info from the Enum member</p>
<div style="font-family:Courier New;font-size:10pt;color:black;background:#F7FCFE;border:1px dashed #B3C8DB;padding:0 0 0 10px;">
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:blue;">string</span> <span style="color:#010001;">GetInfo</span>&lt;<span style="color:#010001;">T</span>&gt;(<span style="color:#010001;">T</span> <span style="color:#010001;">c</span>)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#2b91af;">Type</span> <span style="color:#010001;">t</span> = <span style="color:#010001;">c</span>.<span style="color:#010001;">GetType</span>();</p>
<p style="margin:0;"><span style="color:blue;">if</span> (<span style="color:#010001;">t</span>.<span style="color:#010001;">BaseType</span>.<span style="color:#010001;">Equals</span>(<span style="color:blue;">typeof</span>(<span style="color:#2b91af;">Enum</span>)))</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#2b91af;">FieldInfo</span> <span style="color:#010001;">fn</span> = <span style="color:#010001;">t</span>.<span style="color:#010001;">GetField</span>(<span style="color:#010001;">c</span>.<span style="color:#010001;">ToString</span>());</p>
<p style="margin:0;"><span style="color:#2b91af;">Info</span>[] <span style="color:#010001;">values</span> = (<span style="color:#2b91af;">Info</span>[])<span style="color:#010001;">fn</span>.<span style="color:#010001;">GetCustomAttributes</span>(<span style="color:blue;">typeof</span>(<span style="color:#2b91af;">Info</span>), <span style="color:blue;">false</span>);</p>
<p style="margin:0;"><span style="color:blue;">if</span>(<span style="color:#010001;">values</span>.<span style="color:#010001;">Length</span>&gt;0)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:blue;">return</span> <span style="color:#010001;">values</span>[0].<span style="color:#010001;">Name</span>;</p>
<p style="margin:0;">}</p>
<p style="margin:0;">}</p>
<p style="margin:0;"><span style="color:blue;">return</span> <span style="color:#a31515;">&#8220;&#8221;</span>;</p>
<p style="margin:0;">
<p style="margin:0;">}</p>
</div>
<p>Remember the function is made generic and used to retrieve info from any Enum type.</p>
<p>For LinQ nerd one extension method.</p>
<div style="font-family:Courier New;font-size:10pt;color:black;background:#F7FCFE;border:1px dashed #B3C8DB;padding:0 0 0 10px;">
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:blue;">static</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">Extensions</span></p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:blue;">static</span> <span style="color:blue;">string</span> <span style="color:#010001;">GetInfo</span>(<span style="color:blue;">this</span> <span style="color:#2b91af;">Enum</span> <span style="color:#010001;">c</span>)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#2b91af;">Type</span> <span style="color:#010001;">t</span> = <span style="color:#010001;">c</span>.<span style="color:#010001;">GetType</span>();</p>
<p style="margin:0;"><span style="color:green;">/*if (t.BaseType.Equals(typeof(Enum)))</span></p>
<p style="margin:0;"><span style="color:green;"> {*/</span></p>
<p style="margin:0;"><span style="color:#2b91af;">FieldInfo</span> <span style="color:#010001;">fn</span> = <span style="color:#010001;">t</span>.<span style="color:#010001;">GetField</span>(<span style="color:#010001;">c</span>.<span style="color:#010001;">ToString</span>());</p>
<p style="margin:0;"><span style="color:#2b91af;">Form1</span>.<span style="color:#2b91af;">Info</span>[] <span style="color:#010001;">values</span> = (<span style="color:#2b91af;">Form1</span>.<span style="color:#2b91af;">Info</span>[])<span style="color:#010001;">fn</span>.<span style="color:#010001;">GetCustomAttributes</span>(<span style="color:blue;">typeof</span>(<span style="color:#2b91af;">Form1</span>.<span style="color:#2b91af;">Info</span>), <span style="color:blue;">false</span>);</p>
<p style="margin:0;"><span style="color:blue;">if</span> (<span style="color:#010001;">values</span>.<span style="color:#010001;">Length</span> &gt; 0)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:green;">/*Only top value*/</span></p>
<p style="margin:0;"><span style="color:blue;">return</span> <span style="color:#010001;">values</span>[0].<span style="color:#010001;">Name</span>;</p>
<p style="margin:0;">}</p>
<p style="margin:0;"><span style="color:green;">/*}*/</span></p>
<p style="margin:0;"><span style="color:blue;">return</span> <span style="color:#a31515;">&#8220;&#8221;</span>;</p>
<p style="margin:0;">}</p>
<p style="margin:0;">}</p>
</div>
<p>Sample:</p>
<div style="font-family:Courier New;font-size:10pt;color:black;background:#F7FCFE;border:1px dashed #B3C8DB;padding:0 0 0 10px;">
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:blue;">enum</span> <span style="color:#2b91af;">Car</span></p>
<p style="margin:0;">{</p>
<p style="margin:0;">[<span style="color:#2b91af;">Info</span>(<span style="color:#a31515;">"I am ferrary"</span>)]</p>
<p style="margin:0;"><span style="color:#010001;">Ferrary</span>,</p>
<p style="margin:0;">[<span style="color:#2b91af;">Info</span>(<span style="color:#a31515;">"I am BMW"</span>)]</p>
<p style="margin:0;"><span style="color:#010001;">BMW</span>,</p>
<p style="margin:0;">
<p style="margin:0;">}</p>
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:blue;">enum</span> <span style="color:#2b91af;">Direction</span></p>
<p style="margin:0;">{</p>
<p style="margin:0;">[<span style="color:#2b91af;">Info</span>(<span style="color:#a31515;">"I am North"</span>)]</p>
<p style="margin:0;"><span style="color:#010001;">North</span>,</p>
<p style="margin:0;">[<span style="color:#2b91af;">Info</span>(<span style="color:#a31515;">"I am East"</span>)]</p>
<p style="margin:0;"><span style="color:#010001;">East</span>,</p>
<p style="margin:0;">[<span style="color:#2b91af;">Info</span>(<span style="color:#a31515;">"I am West"</span>)]</p>
<p style="margin:0;"><span style="color:#010001;">West</span>,</p>
<p style="margin:0;">[<span style="color:#2b91af;">Info</span>(<span style="color:#a31515;">"I am South"</span>)]</p>
<p style="margin:0;"><span style="color:#010001;">South</span>,</p>
<p style="margin:0;">
<p style="margin:0;">}</p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:blue;">private</span> <span style="color:blue;">void</span> <span style="color:#010001;">DisplayInfo</span>()</p>
<p style="margin:0;">{</p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:#2b91af;">Console</span>.<span style="color:#010001;">WriteLine</span>(<span style="color:#010001;">GetInfo</span>(<span style="color:#2b91af;">Car</span>.<span style="color:#010001;">Ferrary</span>));</p>
<p style="margin:0;"><span style="color:#2b91af;">Console</span>.<span style="color:#010001;">WriteLine</span>(<span style="color:#010001;">GetInfo</span>(<span style="color:#2b91af;">Direction</span>.<span style="color:#010001;">West</span>));</p>
<p style="margin:0;"><span style="color:green;">/*using Extension Method*/</span></p>
<p style="margin:0;"><span style="color:#2b91af;">Console</span>.<span style="color:#010001;">WriteLine</span>(<span style="color:#2b91af;">Direction</span>.<span style="color:#010001;">North</span>.<span style="color:#010001;">GetInfo</span>());</p>
<p style="margin:0;">
<p style="margin:0;">
<p style="margin:0;">}</p>
</div>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/secretbytes.wordpress.com/36/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/secretbytes.wordpress.com/36/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/secretbytes.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/secretbytes.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/secretbytes.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/secretbytes.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/secretbytes.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/secretbytes.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/secretbytes.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/secretbytes.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/secretbytes.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/secretbytes.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/secretbytes.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/secretbytes.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/secretbytes.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/secretbytes.wordpress.com/36/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=secretbytes.wordpress.com&amp;blog=3612912&amp;post=36&amp;subd=secretbytes&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://secretbytes.wordpress.com/2008/07/18/getting-information-string-from-enum/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/57f465bd3cfe1961e45b3b950a9b9de3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">secretbytes</media:title>
		</media:content>
	</item>
		<item>
		<title>7-zip wrapper, Extracting password protected file</title>
		<link>http://secretbytes.wordpress.com/2008/07/10/7-zip-wrapper-handeling-password-protected-file/</link>
		<comments>http://secretbytes.wordpress.com/2008/07/10/7-zip-wrapper-handeling-password-protected-file/#comments</comments>
		<pubDate>Thu, 10 Jul 2008 05:37:17 +0000</pubDate>
		<dc:creator>secretbytes</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://secretbytes.wordpress.com/2008/07/10/7-zip-wrapper-handeling-password-protected-file/</guid>
		<description><![CDATA[Recently there has been a 7-zip C# wrapper library in codeproject.com written by Eugene Sichkar. The author has done a tremendously great job he deserves a thank. By default user can not simply use the native 7z.dll directly into the C# project this is because of the incomplete COM interfaces implementations in 7-Zip code. So [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=secretbytes.wordpress.com&amp;blog=3612912&amp;post=34&amp;subd=secretbytes&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal">Recently there has been a <a href="http://www.codeproject.com/KB/DLL/cs_interface_7zip.aspx">7-zip C# wrapper </a>library in <a href="http://www.codeproject.com/" target="_blank">codeproject.com</a> written by  <span style="color:#993300;">Eugene Sichkar</span>. <span> </span>The author has done a tremendously great job he deserves a thank.</p>
<p class="MsoNormal">By default user can not simply use the native 7z.dll directly into the C# project this is because of the incomplete COM interfaces implementations in <a href="http://www.7-zip.org/" target="_blank">7-Zip</a> code. So his wrapper comes to a rescue but author says the wrapper is incomplete in fact it lacks everything (I don&#8217;t think he is true). What I found is  Currently wrapper doesn’t support extract feature for password protected files.I tweak his wrapper class to make it work for password protected files<span id="more-34"></span><!--Read More--></p>
<p class="MsoNormal">
<p class="MsoNormal">Looking in to the 7zip original source code. When user calls the extract method first it tries to Query for ICryptoGetTextPassword in the IArchiveExtractCallback .</p>
<p class="MsoNormal">Line no: 634 (7z457\CPP\7zip\Archive\Rar\RarHandler.cpp)</p>
<div style="border:1px dashed #b3c8db;background:#f7fcfe none repeat scroll 0;font-family:Courier New;font-size:10pt;color:black;padding:0 0 0 10px;">
<p style="margin:0;"><span style="color:blue;">if</span> (!getTextPassword)</p>
<p style="margin:0;">extractCallback.QueryInterface(IID_ICryptoGetTextPassword,</p>
<p style="margin:0;">&amp;getTextPassword);</p>
</div>
<p class="MsoNormal">
<p class="MsoNormal">I am now tweaking the wrapper for IArchiveExtractCallback interface by inheriting it from the ICryptoGetTextPassword. As</p>
<p class="MsoNormal">
<div style="border:1px dashed #b3c8db;background:#f7fcfe none repeat scroll 0;font-family:Courier New;font-size:10pt;color:black;padding:0 0 0 10px;">
<p style="margin:0;">[<span style="color:teal;">ComImport</span>]</p>
<p style="margin:0;">[<span style="color:teal;">Guid</span>(<span style="color:maroon;">"23170F69-40C1-278A-0000-000600200000"</span>)]</p>
<p style="margin:0;">[<span style="color:teal;">InterfaceType</span>(<span style="color:teal;">ComInterfaceType</span>.InterfaceIsIUnknown)]</p>
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:blue;">interface</span> <span style="color:teal;">IArchiveExtractCallback</span>:<span style="color:teal;">ICryptoGetTextPassword</span></p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:blue;">void</span> SetTotal(<span style="color:blue;">ulong</span> total);</p>
<p style="margin:0;"><span style="color:blue;">void</span> SetCompleted([<span style="color:teal;">In</span>] <span style="color:blue;">ref</span> <span style="color:blue;">ulong</span> completeValue);</p>
<p style="margin:0;">
<p style="margin:0;">[<span style="color:teal;">PreserveSig</span>]</p>
<p style="margin:0;"><span style="color:blue;">int</span> GetStream(</p>
<p style="margin:0;"><span style="color:blue;">uint</span> index,</p>
<p style="margin:0;">[<span style="color:teal;">MarshalAs</span>(<span style="color:teal;">UnmanagedType</span>.Interface)] <span style="color:blue;">out</span> <span style="color:teal;">ISequentialOutStream</span> outStream,</p>
<p style="margin:0;"><span style="color:teal;">AskMode</span> askExtractMode);</p>
<p style="margin:0;"><span style="color:green;">// GetStream OUT: S_OK &#8211; OK, S_FALSE &#8211; skeep this file</span></p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:blue;">void</span> PrepareOperation(<span style="color:teal;">AskMode</span> askExtractMode);</p>
<p style="margin:0;"><span style="color:blue;">void</span> SetOperationResult(<span style="color:teal;">OperationResult</span> resultEOperationResult);</p>
<p style="margin:0;">}</p>
</div>
<p class="MsoNormal">
<p class="MsoNormal">
<p class="MsoNormal">Thus, our callback ,to get the password ,is now invoked from native 7zip as</p>
<p class="MsoNormal">Line: 640 (7z457\CPP\7zip\Archive\Rar\RarHandler.cpp)</p>
<p class="MsoNormal">
<div style="border:1px dashed #b3c8db;background:#f7fcfe none repeat scroll 0;font-family:Courier New;font-size:10pt;color:black;padding:0 0 0 10px;">
<p style="margin:0;">RINOK(getTextPassword-&gt;CryptoGetTextPassword(&amp;password));</p>
</div>
<p class="MsoNormal">The callback return 0 if success and 1 if error.</p>
<p class="MsoNormal">
<p class="MsoNormal">So now  <span style="color:#0000ff;">ArchiveCallback </span>class looks like</p>
<p class="MsoNormal">
<div style="border:1px dashed #b3c8db;background:#f7fcfe none repeat scroll 0;font-family:Courier New;font-size:10pt;color:black;padding:0 0 0 10px;">
<p style="margin:0;"><span style="color:blue;">class</span> <span style="color:teal;">ArchiveCallback</span> : <span style="color:teal;">IArchiveExtractCallback</span></p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:blue;">private</span> <span style="color:blue;">uint</span> FileNumber;</p>
<p style="margin:0;"><span style="color:blue;">private</span> <span style="color:blue;">string</span> FileName;</p>
<p style="margin:0;"><span style="color:blue;">private</span> <span style="color:teal;">OutStreamWrapper</span> FileStream;</p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:blue;">public</span> ArchiveCallback(<span style="color:blue;">uint</span> fileNumber, <span style="color:blue;">string</span> fileName)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:blue;">this</span>.FileNumber = fileNumber;</p>
<p style="margin:0;"><span style="color:blue;">this</span>.FileName = fileName;</p>
<p style="margin:0;">}</p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:blue;"> #region</span> IArchiveExtractCallback Members</p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:blue;">void</span> SetTotal(<span style="color:blue;">ulong</span> total)</p>
<p style="margin:0;">{</p>
<p style="margin:0;">}</p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:blue;">void</span> SetCompleted(<span style="color:blue;">ref</span> <span style="color:blue;">ulong</span> completeValue)</p>
<p style="margin:0;">{</p>
<p style="margin:0;">}</p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:blue;">int</span> GetStream(<span style="color:blue;">uint</span> index, <span style="color:blue;">out</span> <span style="color:teal;">ISequentialOutStream</span> outStream, <span style="color:teal;">AskMode</span> askExtractMode)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:blue;">if</span> ((index == FileNumber) &amp;&amp; (askExtractMode == <span style="color:teal;">AskMode</span>.kExtract))</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:blue;">string</span> FileDir = <span style="color:teal;">Path</span>.GetDirectoryName(FileName);</p>
<p style="margin:0;"><span style="color:blue;">if</span> (!<span style="color:blue;">string</span>.IsNullOrEmpty(FileDir))</p>
<p style="margin:0;"><span style="color:teal;">Directory</span>.CreateDirectory(FileDir);</p>
<p style="margin:0;">FileStream = <span style="color:blue;">new</span> <span style="color:teal;">OutStreamWrapper</span>(<span style="color:teal;">File</span>.Create(FileName));</p>
<p style="margin:0;">
<p style="margin:0;">outStream = FileStream;</p>
<p style="margin:0;">}</p>
<p style="margin:0;"><span style="color:blue;">else</span></p>
<p style="margin:0;">outStream = <span style="color:blue;">null</span>;</p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:blue;">return</span> 0;</p>
<p style="margin:0;">}</p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:blue;">void</span> PrepareOperation(<span style="color:teal;">AskMode</span> askExtractMode)</p>
<p style="margin:0;">{</p>
<p style="margin:0;">}</p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:blue;">void</span> SetOperationResult(<span style="color:teal;">OperationResult</span> resultEOperationResult)</p>
<p style="margin:0;">{</p>
<p style="margin:0;">FileStream.Dispose();</p>
<p style="margin:0;"><span style="color:teal;">Console</span>.WriteLine(resultEOperationResult);</p>
<p style="margin:0;">}</p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:blue;"> #endregion</span></p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:blue;"> #region</span> ICryptoGetTextPassword Members</p>
<p style="margin:0;">
<p style="margin:0;">
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:blue;">int</span> CryptoGetTextPassword(<span style="color:blue;">out</span> <span style="color:blue;">string</span> password)</p>
<p style="margin:0;">{</p>
<p style="margin:0;">
<p style="margin:0;">password = <span style="color:maroon;">&#8220;secretbytes.wordpress.com&#8221;</span>;</p>
<p style="margin:0;"><span style="color:blue;">return</span> 0;</p>
<p style="margin:0;">}</p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:blue;"> #endregion</span></p>
<p style="margin:0;">}</p>
</div>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/secretbytes.wordpress.com/34/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/secretbytes.wordpress.com/34/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/secretbytes.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/secretbytes.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/secretbytes.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/secretbytes.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/secretbytes.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/secretbytes.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/secretbytes.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/secretbytes.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/secretbytes.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/secretbytes.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/secretbytes.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/secretbytes.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/secretbytes.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/secretbytes.wordpress.com/34/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=secretbytes.wordpress.com&amp;blog=3612912&amp;post=34&amp;subd=secretbytes&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://secretbytes.wordpress.com/2008/07/10/7-zip-wrapper-handeling-password-protected-file/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/57f465bd3cfe1961e45b3b950a9b9de3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">secretbytes</media:title>
		</media:content>
	</item>
		<item>
		<title>Switch Builder</title>
		<link>http://secretbytes.wordpress.com/2008/06/20/switch-builder-2/</link>
		<comments>http://secretbytes.wordpress.com/2008/06/20/switch-builder-2/#comments</comments>
		<pubDate>Fri, 20 Jun 2008 06:32:18 +0000</pubDate>
		<dc:creator>secretbytes</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Reflection]]></category>

		<guid isPermaLink="false">http://secretbytes.wordpress.com/2008/06/20/switch-builder-2/</guid>
		<description><![CDATA[I had to write a switch case for an Enum that contains huge amount of members. Writing each case with hitting the keyword is frustrating and time consuming. So I wrote a little code that builds a switch case for every member of Enum in an Assembly. The Logic behind the scene is extremely simple. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=secretbytes.wordpress.com&amp;blog=3612912&amp;post=31&amp;subd=secretbytes&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I had to write a switch case for an Enum that contains huge amount of members. Writing each case with hitting the keyword is frustrating and time consuming. So I wrote a little code that builds a switch case for every member of Enum in an Assembly.</p>
<p class="MsoNormal">The Logic behind the scene is extremely simple. What one need to do is.</p>
<ul style="margin-top:0;" type="disc">
<li class="MsoNormal">
<div>load <span> </span>an assembly</div>
</li>
<li class="MsoNormal">Enumerate     all Enum types from the loaded assembly.</li>
<li class="MsoNormal">Build the     switch case</li>
</ul>
<p>Load and Enumerat all Enums from an assembly and store it in a combo box<span id="more-31"></span></p>
<div style="border:1px dashed #b3c8db;background:#f7fcfe none repeat scroll 0 50%;font-family:Courier New;font-size:10pt;color:black;padding:0 0 0 10px;">
<p style="margin:0;"><span style="color:blue;">private</span> <span style="color:blue;">void</span> LoadAsm(<span style="color:teal;">String</span> Path)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:green;">/*Load an Assembly*/</span></p>
<p style="margin:0;"><span style="color:teal;">Assembly</span> asm = <span style="color:teal;">Assembly</span>.LoadFile(Path);</p>
<p style="margin:0;"><span style="color:blue;">if</span> (asm != <span style="color:blue;">null</span>)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:teal;">Type</span>[] tp = asm.GetTypes();</p>
<p style="margin:0;"><span style="color:blue;">foreach</span> (<span style="color:teal;">Type</span> t <span style="color:blue;">in</span> tp)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:green;">/*If type is Enum add it to tne combobox*/</span></p>
<p style="margin:0;"><span style="color:blue;">if</span> (t.IsEnum &amp;&amp; t.BaseType == <span style="color:blue;">typeof</span>(<span style="color:teal;">Enum</span>))</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:blue;">this</span>.comboBox1.Items.Add(t);</p>
<p style="margin:0;">}</p>
<p style="margin:0;">}</p>
<p style="margin:0;">}</p>
<p style="margin:0;">}</p>
</div>
<p>Now, All enums are loaded into combobox. Time to build the switch case</p>
<div style="border:1px dashed #b3c8db;background:#f7fcfe none repeat scroll 0 50%;font-family:Courier New;font-size:10pt;color:black;padding:0 0 0 10px;">
<p style="margin:0;"><span style="color:blue;">private</span> <span style="color:blue;">void</span> BuildSwitch()</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:teal;">Type</span> t = <span style="color:blue;">this</span>.comboBox1.SelectedItem <span style="color:blue;">as</span> <span style="color:teal;">Type</span>;</p>
<p style="margin:0;"><span style="color:teal;">StringBuilder</span> sb = <span style="color:blue;">new</span> <span style="color:teal;">StringBuilder</span>();</p>
<p style="margin:0;">sb.AppendLine(<span style="color:teal;">String</span>.Format(<span style="color:maroon;">&#8220;{0} Enm;&#8221;</span>, t.Name));</p>
<p style="margin:0;">sb.AppendLine(<span style="color:maroon;">&#8220;switch(Enm)&#8221;</span>);</p>
<p style="margin:0;">sb.AppendLine(<span style="color:maroon;">&#8220;{&#8220;</span>);</p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:green;">/*Prepare case for each name of the enum*/</span></p>
<p style="margin:0;"><span style="color:blue;">foreach</span> (<span style="color:blue;">string</span> str <span style="color:blue;">in</span> <span style="color:teal;">Enum</span>.GetNames(t))</p>
<p style="margin:0;">{</p>
<p style="margin:0;">sb.AppendLine(<span style="color:blue;">string</span>.Format(<span style="color:maroon;">&#8220;case {0}.{1}:&#8221;</span>, t.Name,str));</p>
<p style="margin:0;">sb.AppendLine(<span style="color:maroon;">&#8220;break;&#8221;</span>);</p>
<p style="margin:0;">
<p style="margin:0;">}</p>
<p style="margin:0;">sb.AppendLine(<span style="color:maroon;">&#8220;}&#8221;</span>);</p>
<p style="margin:0;"><span style="color:blue;">this</span>.richTextBox1.Text = sb.ToString();</p>
<p style="margin:0;">}</p>
</div>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/secretbytes.wordpress.com/31/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/secretbytes.wordpress.com/31/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/secretbytes.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/secretbytes.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/secretbytes.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/secretbytes.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/secretbytes.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/secretbytes.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/secretbytes.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/secretbytes.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/secretbytes.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/secretbytes.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/secretbytes.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/secretbytes.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/secretbytes.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/secretbytes.wordpress.com/31/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=secretbytes.wordpress.com&amp;blog=3612912&amp;post=31&amp;subd=secretbytes&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://secretbytes.wordpress.com/2008/06/20/switch-builder-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/57f465bd3cfe1961e45b3b950a9b9de3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">secretbytes</media:title>
		</media:content>
	</item>
		<item>
		<title>Glassy Control</title>
		<link>http://secretbytes.wordpress.com/2008/06/01/glassy-control/</link>
		<comments>http://secretbytes.wordpress.com/2008/06/01/glassy-control/#comments</comments>
		<pubDate>Sun, 01 Jun 2008 13:56:53 +0000</pubDate>
		<dc:creator>secretbytes</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Glassy Effect]]></category>

		<guid isPermaLink="false">http://secretbytes.wordpress.com/?p=20</guid>
		<description><![CDATA[I was fiddling with panel appearance as I wanted it to have a Glassy effect. I don&#8217;t know if I got it exactly what I wanted but the result somehow looks appealing. You can also play with it especially into Rectangles for better results (well, don&#8217;t know if it makes). code goes: protected override void [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=secretbytes.wordpress.com&amp;blog=3612912&amp;post=20&amp;subd=secretbytes&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was fiddling with panel appearance as I wanted it to have a  Glassy effect. I don&#8217;t know if I got it exactly what I wanted but the result somehow looks appealing. You can also play with it especially into Rectangles for better results (well, don&#8217;t know if it makes).<span id="more-20"></span></p>
<p>code goes:</p>
<div style="border:1px dashed #b3c8db;background:#f7fcfe none repeat scroll 0;font-family:Courier New;font-size:10pt;color:black;padding:0 0 0 10px;">
<p style="margin:0;"><span style="color:blue;">protected</span> <span style="color:blue;">override</span> <span style="color:blue;">void</span> <span style="color:#010001;">OnPaint</span>(<span style="color:#2b91af;">PaintEventArgs</span> <span style="color:#010001;">e</span>)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#010001;">e</span>.<span style="color:#010001;">Graphics</span>.<span style="color:#010001;">SmoothingMode</span> = <span style="color:#2b91af;">SmoothingMode</span>.<span style="color:#010001;">HighQuality</span>;</p>
<p style="margin:0;"><span style="color:#2b91af;">Rectangle</span> <span style="color:#010001;">FullRectangle</span> = <span style="color:blue;">new</span> <span style="color:#2b91af;">Rectangle</span>(0, 0, <span style="color:blue;">this</span>.<span style="color:#010001;">Width</span>, <span style="color:blue;">this</span>.<span style="color:#010001;">Height</span>);</p>
<p style="margin:0;"><span style="color:#2b91af;">Rectangle</span> <span style="color:#010001;">HalfRectangle</span> = <span style="color:blue;">new</span> <span style="color:#2b91af;">Rectangle</span>(0, <span style="color:blue;">this</span>.<span style="color:#010001;">Height</span>/2, <span style="color:blue;">this</span>.<span style="color:#010001;">Width</span>, <span style="color:blue;">this</span>.<span style="color:#010001;">Height</span>);</p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:#2b91af;">Point</span> <span style="color:#010001;">StartPoint</span> = <span style="color:blue;">new</span> <span style="color:#2b91af;">Point</span>(0, <span style="color:#010001;">FullRectangle</span>.<span style="color:#010001;">Top</span>);</p>
<p style="margin:0;"><span style="color:#2b91af;">Point</span> <span style="color:#010001;">EndPoint</span> = <span style="color:blue;">new</span> <span style="color:#2b91af;">Point</span>(0, <span style="color:#010001;">FullRectangle</span>.<span style="color:#010001;">Bottom</span>);</p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:#2b91af;">LinearGradientBrush</span> <span style="color:#010001;">Painter</span> = <span style="color:blue;">new</span> <span style="color:#2b91af;">LinearGradientBrush</span>(<span style="color:#010001;">StartPoint</span>,<span style="color:#010001;">EndPoint</span>, <span style="color:#2b91af;">Color</span>.<span style="color:#010001;">White</span>, <span style="color:blue;">this</span>.<span style="color:#010001;">BackColor</span>);</p>
<p style="margin:0;"><span style="color:#010001;">e</span>.<span style="color:#010001;">Graphics</span>.<span style="color:#010001;">FillRectangle</span>(<span style="color:#010001;">Painter</span>, <span style="color:#010001;">FullRectangle</span>);</p>
<p style="margin:0;"><span style="color:#010001;">EndPoint</span> = <span style="color:blue;">new</span> <span style="color:#2b91af;">Point</span>(0, <span style="color:#010001;">HalfRectangle</span>.<span style="color:#010001;">Top</span>);</p>
<p style="margin:0;"><span style="color:#010001;">StartPoint</span> = <span style="color:blue;">new</span> <span style="color:#2b91af;">Point</span>(0, <span style="color:#010001;">HalfRectangle</span>.<span style="color:#010001;">Bottom</span>);</p>
<p style="margin:0;"><span style="color:#010001;">Painter</span> = <span style="color:blue;">new</span> <span style="color:#2b91af;">LinearGradientBrush</span>(<span style="color:#010001;">EndPoint</span>, <span style="color:#010001;">StartPoint</span>, <span style="color:blue;">this</span>.<span style="color:#010001;">BackColor</span>, <span style="color:#2b91af;">Color</span>.<span style="color:#010001;">White</span>);</p>
<p style="margin:0;"><span style="color:#010001;">e</span>.<span style="color:#010001;">Graphics</span>.<span style="color:#010001;">FillRectangle</span>(<span style="color:#010001;">Painter</span>, <span style="color:#010001;">HalfRectangle</span>);</p>
<p style="margin:0;">
<p style="margin:0;">}</p>
</div>
<p>And Output looks,</p>
<p><a href="http://secretbytes.files.wordpress.com/2008/06/glassycontrols.jpg"><img class="alignnone size-full wp-image-22" src="http://secretbytes.files.wordpress.com/2008/06/glassycontrols.jpg?w=468" alt=""   /></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/secretbytes.wordpress.com/20/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/secretbytes.wordpress.com/20/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/secretbytes.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/secretbytes.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/secretbytes.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/secretbytes.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/secretbytes.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/secretbytes.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/secretbytes.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/secretbytes.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/secretbytes.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/secretbytes.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/secretbytes.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/secretbytes.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/secretbytes.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/secretbytes.wordpress.com/20/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=secretbytes.wordpress.com&amp;blog=3612912&amp;post=20&amp;subd=secretbytes&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://secretbytes.wordpress.com/2008/06/01/glassy-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/57f465bd3cfe1961e45b3b950a9b9de3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">secretbytes</media:title>
		</media:content>

		<media:content url="http://secretbytes.files.wordpress.com/2008/06/glassycontrols.jpg" medium="image" />
	</item>
		<item>
		<title>IComparer How to</title>
		<link>http://secretbytes.wordpress.com/2008/05/08/icomparer/</link>
		<comments>http://secretbytes.wordpress.com/2008/05/08/icomparer/#comments</comments>
		<pubDate>Thu, 08 May 2008 07:09:23 +0000</pubDate>
		<dc:creator>secretbytes</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[IComparer]]></category>

		<guid isPermaLink="false">http://secretbytes.wordpress.com/?p=13</guid>
		<description><![CDATA[Sometimes, when sorting real object life no longer remains easier as it is whilst making sort operation in simple data types. Consider a following example, you are about the sort cars from its collection. How do you do this? There is in fact no operator like &#60;, &#62;, == that meets your all requirements unless [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=secretbytes.wordpress.com&amp;blog=3612912&amp;post=13&amp;subd=secretbytes&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Sometimes, when sorting real object life no longer remains easier as it is whilst making sort operation in simple data types. Consider a following example, you are about the sort cars from its collection. How do you do this? There is in fact no operator like &lt;, &gt;, == that meets your all requirements unless you code them explicitly.<br />
As everyone has already known about ArrayList class, that contains a public method Sort(), Luckily user can also feed parameter about how sorting method will proceed.<br />
Parameter I am talking about is IComparer interface that provides only one method.<br />
The implementation is self-explanatory. <span id="more-13"></span></p>
<div style="border:1px dashed #b3c8db;background:#f7fcfe none repeat scroll 0;font-family:Courier New;font-size:10pt;color:black;padding:0 0 0 10px;">
<p style="margin:0;"><span style="color:#0000ff;">using</span> System;</p>
<p style="margin:0;"><span style="color:#0000ff;">using</span> System.Collections.Generic;</p>
<p style="margin:0;"><span style="color:#0000ff;">using</span> System.Text;</p>
<p style="margin:0;"><span style="color:#0000ff;">using</span> System.Collections;</p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:#0000ff;">namespace</span> IcomparableTest</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#008080;">Car</span>:<span style="color:#008080;">IComparable</span></p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#0000ff;">string</span> _modelName;</p>
<p style="margin:0;"><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;summary&gt;</span></p>
<p style="margin:0;"><span style="color:#808080;">///</span><span style="color:#008000;"> Modle Name of the car</span></p>
<p style="margin:0;"><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;/summary&gt;</span></p>
<p style="margin:0;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> ModelName</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#0000ff;">get</span> { <span style="color:#0000ff;">return</span> _modelName; }</p>
<p style="margin:0;"><span style="color:#0000ff;">set</span> { _modelName = <span style="color:#0000ff;">value</span>; }</p>
<p style="margin:0;">}</p>
<p style="margin:0;">
<p style="margin:0;">
<p style="margin:0;"><span style="color:#008080;">DateTime</span> _manufactureDate;</p>
<p style="margin:0;"><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;summary&gt;</span></p>
<p style="margin:0;"><span style="color:#808080;">///</span><span style="color:#008000;"> Manufacture Date</span></p>
<p style="margin:0;"><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;/summary&gt;</span></p>
<p style="margin:0;"><span style="color:#0000ff;">public</span> <span style="color:#008080;">DateTime</span> ManufactureDate</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#0000ff;">get</span> { <span style="color:#0000ff;">return</span> _manufactureDate; }</p>
<p style="margin:0;"><span style="color:#0000ff;">set</span> { _manufactureDate = <span style="color:#0000ff;">value</span>; }</p>
<p style="margin:0;">}</p>
<p style="margin:0;"><span style="color:#0000ff;">int</span> _modleno;</p>
<p style="margin:0;"><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;summary&gt;</span></p>
<p style="margin:0;"><span style="color:#808080;">///</span><span style="color:#008000;"> Model Number</span></p>
<p style="margin:0;"><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;/summary&gt;</span></p>
<p style="margin:0;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">int</span> ModelNumber</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#0000ff;">get</span> { <span style="color:#0000ff;">return</span> _modleno; }</p>
<p style="margin:0;"><span style="color:#0000ff;">set</span> { _modleno = <span style="color:#0000ff;">value</span>; }</p>
<p style="margin:0;">}</p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:#0000ff;">public</span> Car(<span style="color:#0000ff;">string</span> modlename,<span style="color:#008080;">DateTime</span> manufacturedate,<span style="color:#0000ff;">int</span> modleno)</p>
<p style="margin:0;">{</p>
<p style="margin:0;">_modleno = modleno;</p>
<p style="margin:0;">_modelName = modlename;</p>
<p style="margin:0;">_manufactureDate = manufacturedate;</p>
<p style="margin:0;">}</p>
<p style="margin:0;">
<p style="margin:0;">
<p style="margin:0;"><span style="color:#0000ff;">#region</span> IComparable Members</p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;summary&gt;</span></p>
<p style="margin:0;"><span style="color:#808080;">///</span><span style="color:#008000;"> Default comprision, Generates compresion from ModleName</span></p>
<p style="margin:0;"><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;/summary&gt;</span></p>
<p style="margin:0;"><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;param name=&#8221;obj&#8221;&gt;</span><span style="color:#008000;">object to compare to</span><span style="color:#808080;">&lt;/param&gt;</span></p>
<p style="margin:0;"><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;returns&gt;&lt;/returns&gt;</span></p>
<p style="margin:0;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">int</span> CompareTo(<span style="color:#0000ff;">object</span> obj)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#008080;">Car</span> temp = <span style="color:#0000ff;">null</span>;</p>
<p style="margin:0;"><span style="color:#0000ff;">if</span>(obj <span style="color:#0000ff;">is</span> <span style="color:#008080;">Car</span>)</p>
<p style="margin:0;">{</p>
<p style="margin:0;">temp = obj <span style="color:#0000ff;">as</span> <span style="color:#008080;">Car</span>;</p>
<p style="margin:0;"><span style="color:#0000ff;">return</span> temp._modelName.CompareTo(<span style="color:#0000ff;">this</span>._modelName);</p>
<p style="margin:0;">}</p>
<p style="margin:0;"><span style="color:#0000ff;">throw</span> <span style="color:#0000ff;">new</span> <span style="color:#008080;">Exception</span>(<span style="color:#800000;">&#8220;Object should be of Car type&#8221;</span>);</p>
<p style="margin:0;">}</p>
<p style="margin:0;"><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;summary&gt;</span></p>
<p style="margin:0;"><span style="color:#808080;">///</span><span style="color:#008000;"> Compare object</span></p>
<p style="margin:0;"><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;/summary&gt;</span></p>
<p style="margin:0;"><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;param name=&#8221;obj&#8221;&gt;</span><span style="color:#008000;">object to comparet to</span><span style="color:#808080;">&lt;/param&gt;</span></p>
<p style="margin:0;"><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;param name=&#8221;ComparisionType&#8221;&gt;&lt;/param&gt;</span></p>
<p style="margin:0;"><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;returns&gt;&lt;/returns&gt;</span></p>
<p style="margin:0;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">int</span> CompareTo(<span style="color:#008080;">Object</span> obj,<span style="color:#008080;">CarComparer</span>.<span style="color:#008080;">ComparisonType</span> ComparisionType)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#008080;">Car</span> obj1 = obj <span style="color:#0000ff;">as</span> <span style="color:#008080;">Car</span>;</p>
<p style="margin:0;"><span style="color:#0000ff;">if</span> (obj != <span style="color:#0000ff;">null</span>)</p>
<p style="margin:0;">{</p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:#0000ff;">switch</span> (ComparisionType)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#0000ff;">case</span> <span style="color:#008080;">CarComparer</span>.<span style="color:#008080;">ComparisonType</span>.ManufactureDate:</p>
<p style="margin:0;"><span style="color:#0000ff;">return</span> _manufactureDate.CompareTo(obj1._manufactureDate);</p>
<p style="margin:0;"><span style="color:#0000ff;">case</span> <span style="color:#008080;">CarComparer</span>.<span style="color:#008080;">ComparisonType</span>.ModleName:</p>
<p style="margin:0;"><span style="color:#0000ff;">return</span> _modelName.CompareTo(obj1._modelName);</p>
<p style="margin:0;"><span style="color:#0000ff;">case</span> <span style="color:#008080;">CarComparer</span>.<span style="color:#008080;">ComparisonType</span>.ModleNo:</p>
<p style="margin:0;"><span style="color:#0000ff;">default</span>:</p>
<p style="margin:0;"><span style="color:#0000ff;">return</span> _modleno.CompareTo(obj1._modleno);</p>
<p style="margin:0;">
<p style="margin:0;">}</p>
<p style="margin:0;">}</p>
<p style="margin:0;"><span style="color:#0000ff;">throw</span> <span style="color:#0000ff;">new</span> <span style="color:#008080;">Exception</span>(<span style="color:#800000;">&#8220;Object should be of Car type&#8221;</span>);</p>
<p style="margin:0;">
<p style="margin:0;">
<p style="margin:0;">}</p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:#0000ff;">#endregion</span></p>
<p style="margin:0;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">string</span> ToString()</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#0000ff;">return</span> (<span style="color:#0000ff;">string</span>.Format(<span style="color:#800000;">&#8220;Model Name: {0}, Modle Number: {1}, Manufacture Date: {2}&#8221;</span>,</p>
<p style="margin:0;"><span style="color:#0000ff;">this</span>._modelName,</p>
<p style="margin:0;"><span style="color:#0000ff;">this</span>._modleno,</p>
<p style="margin:0;"><span style="color:#0000ff;">this</span>._manufactureDate.ToLongDateString()));</p>
<p style="margin:0;">}</p>
<p style="margin:0;">}</p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#008080;">CarComparer</span>:<span style="color:#008080;">IComparer</span></p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">enum</span> <span style="color:#008080;">ComparisonType</span></p>
<p style="margin:0;">{</p>
<p style="margin:0;">ModleName,</p>
<p style="margin:0;">ManufactureDate,</p>
<p style="margin:0;">ModleNo,</p>
<p style="margin:0;">}</p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:#0000ff;">private</span> <span style="color:#008080;">ComparisonType</span> _cmpType;</p>
<p style="margin:0;"><span style="color:#0000ff;">public</span> <span style="color:#008080;">ComparisonType</span> ComparisonWay</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#0000ff;">get</span> { <span style="color:#0000ff;">return</span> _cmpType; }</p>
<p style="margin:0;"><span style="color:#0000ff;">set</span> { _cmpType = <span style="color:#0000ff;">value</span>; }</p>
<p style="margin:0;">}</p>
<p style="margin:0;"><span style="color:#0000ff;">public</span> CarComparer(<span style="color:#008080;">ComparisonType</span> CompType)</p>
<p style="margin:0;">{</p>
<p style="margin:0;">_cmpType = CompType;</p>
<p style="margin:0;">}</p>
<p style="margin:0;"><span style="color:#0000ff;">public</span> CarComparer():<span style="color:#0000ff;">this</span>(<span style="color:#008080;">ComparisonType</span>.ModleName)</p>
<p style="margin:0;">{</p>
<p style="margin:0;">
<p style="margin:0;">}</p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:#0000ff;">#region</span> IComparer Members</p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">int</span> Compare(<span style="color:#0000ff;">object</span> x, <span style="color:#0000ff;">object</span> y)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#0000ff;">if</span>((x <span style="color:#0000ff;">is</span> <span style="color:#008080;">Car</span>) &amp;&amp; (y <span style="color:#0000ff;">is</span> <span style="color:#008080;">Car</span>) )</p>
<p style="margin:0;">{</p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:#0000ff;">return</span> (x <span style="color:#0000ff;">as</span> <span style="color:#008080;">Car</span>).CompareTo((y <span style="color:#0000ff;">as</span> <span style="color:#008080;">Car</span>), <span style="color:#0000ff;">this</span>._cmpType);</p>
<p style="margin:0;">
<p style="margin:0;">}</p>
<p style="margin:0;"><span style="color:#0000ff;">throw</span> <span style="color:#0000ff;">new</span> <span style="color:#008080;">Exception</span>(<span style="color:#800000;">&#8220;Object should be of Car type&#8221;</span>);</p>
<p style="margin:0;">
<p style="margin:0;">
<p style="margin:0;">
<p style="margin:0;">
<p style="margin:0;">
<p style="margin:0;">}</p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:#0000ff;">#endregion</span></p>
<p style="margin:0;">}</p>
<p style="margin:0;">}</p>
</div>
<p>And Here is the Sample application source.</p>
<div style="font-family:Courier New;font-size:10pt;color:black;background:#F7FCFE;border:1px dashed #B3C8DB;padding:0 0 0 10px;">
<p style="margin:0;"><span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> button1_Click(<span style="color:#0000ff;">object</span> sender, <span style="color:#008080;">EventArgs</span> e)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#008080;">Car</span> c = <span style="color:#0000ff;">new</span> <span style="color:#008080;">Car</span>(<span style="color:#800000;">&#8220;Mercedes&#8221;</span>, <span style="color:#008080;">DateTime</span>.Today, 101);</p>
<p style="margin:0;"><span style="color:#008080;">Car</span> c1 = <span style="color:#0000ff;">new</span> <span style="color:#008080;">Car</span>(<span style="color:#800000;">&#8220;Ferrary&#8221;</span>,c.ManufactureDate.Subtract(<span style="color:#0000ff;">new</span> <span style="color:#008080;">TimeSpan</span>(1,0,0,0,0)), 20);</p>
<p style="margin:0;"><span style="color:#008080;">Car</span> c2 = <span style="color:#0000ff;">new</span> <span style="color:#008080;">Car</span>(<span style="color:#800000;">&#8220;Mitsubishi&#8221;</span>, c1.ManufactureDate.Subtract(<span style="color:#0000ff;">new</span> <span style="color:#008080;">TimeSpan</span>(1, 0, 0, 0, 0)), 40);</p>
<p style="margin:0;"><span style="color:#008080;">Car</span> c3 = <span style="color:#0000ff;">new</span> <span style="color:#008080;">Car</span>(<span style="color:#800000;">&#8220;Roles-Royce &#8220;</span>, c2.ManufactureDate.Subtract(<span style="color:#0000ff;">new</span> <span style="color:#008080;">TimeSpan</span>(1, 0, 0, 0, 0)), 31);</p>
<p style="margin:0;">
<p style="margin:0;">
<p style="margin:0;">
<p style="margin:0;"><span style="color:#008080;">ArrayList</span> _list = <span style="color:#0000ff;">new</span> <span style="color:#008080;">ArrayList</span>();</p>
<p style="margin:0;">_list.Add(c);</p>
<p style="margin:0;">_list.Add(c1);</p>
<p style="margin:0;">_list.Add(c2);</p>
<p style="margin:0;">_list.Add(c3);</p>
<p style="margin:0;">
<p style="margin:0;">
<p style="margin:0;">
<p style="margin:0;"><span style="color:#0000ff;">this</span>.listBox1.Items.Add(<span style="color:#800000;">&#8220;Original placment:&#8221;</span>);</p>
<p style="margin:0;"><span style="color:#0000ff;">foreach</span> (<span style="color:#008080;">Car</span> x <span style="color:#0000ff;">in</span> _list)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#0000ff;">this</span>.listBox1.Items.Add(x);</p>
<p style="margin:0;">}</p>
<p style="margin:0;"><span style="color:#0000ff;">this</span>.listBox1.Items.Add(<span style="color:#0000ff;">string</span>.Empty);</p>
<p style="margin:0;"><span style="color:#0000ff;">this</span>.listBox1.Items.Add(<span style="color:#800000;">&#8220;Sorting by Model Number&#8221;</span>);</p>
<p style="margin:0;">_list.Sort(<span style="color:#0000ff;">new</span> <span style="color:#008080;">CarComparer</span>(<span style="color:#008080;">CarComparer</span>.<span style="color:#008080;">ComparisonType</span>.ModleNo));</p>
<p style="margin:0;"><span style="color:#0000ff;">foreach</span> (<span style="color:#008080;">Car</span> x <span style="color:#0000ff;">in</span> _list)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#0000ff;">this</span>.listBox1.Items.Add(x);</p>
<p style="margin:0;">}</p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:#0000ff;">this</span>.listBox1.Items.Add(<span style="color:#0000ff;">string</span>.Empty);</p>
<p style="margin:0;"><span style="color:#0000ff;">this</span>.listBox1.Items.Add(<span style="color:#800000;">&#8220;Sorting by Manufacture Date&#8221;</span>);</p>
<p style="margin:0;">_list.Sort(<span style="color:#0000ff;">new</span> <span style="color:#008080;">CarComparer</span>(<span style="color:#008080;">CarComparer</span>.<span style="color:#008080;">ComparisonType</span>.ManufactureDate));</p>
<p style="margin:0;"><span style="color:#0000ff;">foreach</span> (<span style="color:#008080;">Car</span> x <span style="color:#0000ff;">in</span> _list)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#0000ff;">this</span>.listBox1.Items.Add(x);</p>
<p style="margin:0;">}</p>
<p style="margin:0;">
<p style="margin:0;"><span style="color:#0000ff;">this</span>.listBox1.Items.Add(<span style="color:#0000ff;">string</span>.Empty);</p>
<p style="margin:0;"><span style="color:#0000ff;">this</span>.listBox1.Items.Add(<span style="color:#800000;">&#8220;Sorting by Model Name(default sort)&#8221;</span>);</p>
<p style="margin:0;">_list.Sort(<span style="color:#0000ff;">new</span> <span style="color:#008080;">CarComparer</span>());</p>
<p style="margin:0;"><span style="color:#0000ff;">foreach</span> (<span style="color:#008080;">Car</span> x <span style="color:#0000ff;">in</span> _list)</p>
<p style="margin:0;">{</p>
<p style="margin:0;"><span style="color:#0000ff;">this</span>.listBox1.Items.Add(x);</p>
<p style="margin:0;">}</p>
<p style="margin:0;">
<p style="margin:0;">}</p>
</div>
<p>Sample Output:<br />
<a href="http://secretbytes.files.wordpress.com/2008/06/test.jpg"><img class="alignnone size-full wp-image-24" src="http://secretbytes.files.wordpress.com/2008/06/test.jpg?w=468&#038;h=375" alt="" width="468" height="375" /></a><a href="http://secretbytes.files.wordpress.com/2008/06/test.jpg"><br />
</a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/secretbytes.wordpress.com/13/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/secretbytes.wordpress.com/13/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/secretbytes.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/secretbytes.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/secretbytes.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/secretbytes.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/secretbytes.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/secretbytes.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/secretbytes.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/secretbytes.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/secretbytes.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/secretbytes.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/secretbytes.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/secretbytes.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/secretbytes.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/secretbytes.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=secretbytes.wordpress.com&amp;blog=3612912&amp;post=13&amp;subd=secretbytes&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://secretbytes.wordpress.com/2008/05/08/icomparer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/57f465bd3cfe1961e45b3b950a9b9de3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">secretbytes</media:title>
		</media:content>

		<media:content url="http://secretbytes.files.wordpress.com/2008/06/test.jpg" medium="image" />
	</item>
	</channel>
</rss>
