﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>博客园-柠檬的...</title><link>http://www.cnblogs.com/lemony/</link><description /><language>zh-cn</language><lastBuildDate>Wed, 10 Feb 2010 07:20:05 GMT</lastBuildDate><pubDate>Wed, 10 Feb 2010 07:20:05 GMT</pubDate><ttl>60</ttl><item><title>(C#)Windows Shell 外壳编程系列9 - QueryInfo 扩展提示</title><link>http://www.cnblogs.com/lemony/archive/2008/09/03/1283128.html</link><dc:creator>柠檬的</dc:creator><author>柠檬的</author><pubDate>Wed, 03 Sep 2008 08:35:00 GMT</pubDate><guid>http://www.cnblogs.com/lemony/archive/2008/09/03/1283128.html</guid><description><![CDATA[<p>阅读: 2150 评论: 5 作者: <a href="http://www.cnblogs.com/lemony/" target="_blank">柠檬的</a> 发表于 2008-09-03 16:35 <a href="http://www.cnblogs.com/lemony/archive/2008/09/03/1283128.html" target="_blank">原文链接</a></p><p><span style="color: red">（本系列文章由柠檬的(lc_mtt)原创，转载请注明出处，谢谢～）</span></p>
<p>&nbsp;</p>
<p><span style="color: red">接上一节：<a class="postTitle2" id="AjaxHolder_ctl01_TitleUrl" href="http://www.cnblogs.com/lemony/archive/2008/09/01/1280925.html">(C#)Windows Shell 外壳编程系列8 - 同后缀名不同图标？</a> </span></p>
<p>&nbsp;</p>
<p><span style="color: black"><font size="2"><strong><font color="#ff9933">QueryInfo扩展</font></strong></font> <br />
活动桌面引入一项新特性，当你在某些特定对象上旋停鼠标时，工具提示将显示它们的描述。<span style="color: black">我们可以使用 <font color="#ff3333">QueryInfo </font>扩展为Shell中的其它对象提供自定义的工具提示。如下图：</span></span><span style="color: black"><br />
<img height="323" alt="" src="http://images.cnblogs.com/cnblogs_com/lemony/shell7-3.GIF" width="480" border="0" /></span><span style="color: black"><br />
<br />
事实上，这个功能实现比前两个 Shell 扩展更简单，它仅仅是实现 <font color="#ff3333">IQueryInfo</font>&nbsp;接口：</span></p>
<p><span style="color: black"></p>
<div class="cnblogs_code"><img id="Code_Closed_Image_162354" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_162354').style.display='none'; document.getElementById('Code_Open_Image_162354').style.display='inline'; document.getElementById('Code_Open_Text_162354').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_162354" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_162354').style.display='none'; getElementById('Code_Closed_Image_162354').style.display='inline'; getElementById('Code_Closed_Text_162354').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_162354">IQueryInfo 接口定义</span><span id="Code_Open_Text_162354" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">[ComImport(),&nbsp;ComVisible(</span><span style="color: #0000ff">true</span><span style="color: #000000">),&nbsp;InterfaceType(ComInterfaceType.InterfaceIsIUnknown),&nbsp;GuidAttribute(</span><span style="color: #800000">"</span><span style="color: #800000">00021500-0000-0000-c000-000000000046</span><span style="color: #800000">"</span><span style="color: #000000">)]<br />
</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">interface</span><span style="color: #000000">&nbsp;IQueryInfo<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;[PreserveSig]<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;GetInfoTip(</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;dwFlags,&nbsp;</span><span style="color: #0000ff">out</span><span style="color: #000000">&nbsp;IntPtr&nbsp;pszInfoTip);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;[PreserveSig]<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;GetInfoFlags(</span><span style="color: #0000ff">out</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;dwFlags);<br />
}&nbsp;</span></span></div>
<p>&nbsp;</p>
<p><font size="-1"><font color="#ff3333">IQueryInfo</font>&nbsp;接口只包含两个函数,其中 <font color="#c60a00">GetInfoFlags </font>目前还不被支持并且必须返回 0。</font></p>
<p><font color="#ff3333">GetInfoTip()</font> 让我们返回工具提示文本 字符串。其参数：</p>
<p><font color="#ff3333">dwFlags</font> 当前并不被使用。</p>
<p><font color="#ff3333">pszInfoTip</font> 是个Unicode 字符串指针变量的指针，我们要将其赋值为我们所分配的字符串缓冲区的指针。</p>
<p>&nbsp;</p>
<p>还记得之前使用 <font face="Verdana">IPersistFile</font> 接口获取单个文件路径保存在 <font face="Verdana">szFileName</font> 变量中吗？现在也可以使用：</p>
<div class="cnblogs_code"><img id="Code_Closed_Image_162832" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_162832').style.display='none'; document.getElementById('Code_Open_Image_162832').style.display='inline'; document.getElementById('Code_Open_Text_162832').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_162832" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_162832').style.display='none'; getElementById('Code_Closed_Image_162832').style.display='inline'; getElementById('Code_Closed_Text_162832').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_162832">GetInfoTip</span><span id="Code_Open_Text_162832" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;GetInfoTip(</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;dwFlags,&nbsp;</span><span style="color: #0000ff">out</span><span style="color: #000000">&nbsp;IntPtr&nbsp;pszInfoTip)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;StreamReader&nbsp;sr&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;StreamReader(szFileName,&nbsp;Encoding.GetEncoding(</span><span style="color: #800000">"</span><span style="color: #800000">gb2312</span><span style="color: #800000">"</span><span style="color: #000000">));<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;text&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;sr.ReadToEnd();<br />
&nbsp;&nbsp;&nbsp;&nbsp;sr.Close();<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(text.Length&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">256</span><span style="color: #000000">)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;text.Substring(</span><span style="color: #800080">0</span><span style="color: #000000">,&nbsp;</span><span style="color: #800080">256</span><span style="color: #000000">)&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000"><img src="http://www.cnblogs.com/Images/dot.gif"  alt="" /></span><span style="color: #800000">"</span><span style="color: #000000">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;tip&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">-------------&nbsp;内容预览&nbsp;-------------\r\n\r\n</span><span style="color: #800000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;text;<br />
<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;pszInfoTip&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Marshal.StringToCoTaskMemUni(tip);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;S_OK;<br />
}&nbsp;</span></span></div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>代码：<a href="http://files.cnblogs.com/lemony/MyContextMenu.rar">http://files.cnblogs.com/lemony/MyContextMenu.rar</a></p>
<p>&nbsp;</p>
<p>这一章似乎过于简单。下一章将简述如何使用 <font face="Verdana">IShellPropSheetExt</font> 接口为文件/文件夹增加属性页，如下：</p>
<p><img height="529" alt="" src="http://images.cnblogs.com/cnblogs_com/lemony/shell9-1.GIF" width="462" border="0" /></p>
</span>
<img src="http://www.cnblogs.com/lemony/aggbug/1283128.html?type=1" width="1" height="1" alt=""/><p>评论: 5　<a href="http://www.cnblogs.com/lemony/archive/2008/09/03/1283128.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/lemony/archive/2008/09/03/1283128.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56845/" target="_blank">奇虎新注资两家知名软件公司 投资项目达10笔</a><span style="color:gray">(2010-02-10 15:14)</span><br/>· <a href="http://news.cnblogs.com/n/56844/" target="_blank">网友对Google的9大期待</a><span style="color:gray">(2010-02-10 15:07)</span><br/>· <a href="http://news.cnblogs.com/n/56843/" target="_blank">分析称Google Buzz有十大特点：将改变搜索</a><span style="color:gray">(2010-02-10 15:06)</span><br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>(C#)Windows Shell 外壳编程系列8 - 同后缀名不同图标？</title><link>http://www.cnblogs.com/lemony/archive/2008/09/01/1280925.html</link><dc:creator>柠檬的</dc:creator><author>柠檬的</author><pubDate>Mon, 01 Sep 2008 01:38:00 GMT</pubDate><guid>http://www.cnblogs.com/lemony/archive/2008/09/01/1280925.html</guid><description><![CDATA[<p>阅读: 3377 评论: 16 作者: <a href="http://www.cnblogs.com/lemony/" target="_blank">柠檬的</a> 发表于 2008-09-01 09:38 <a href="http://www.cnblogs.com/lemony/archive/2008/09/01/1280925.html" target="_blank">原文链接</a></p><p><span style="color: red">（本系列文章由柠檬的(lc_mtt)原创，转载请注明出处，谢谢～）</span></p>
<p>&nbsp;</p>
<p><span style="color: red">接上一节：<a class="postTitle2" id="AjaxHolder_ctl01_TitleUrl" href="http://www.cnblogs.com/lemony/archive/2008/08/29/1279588.html">(C#)Windows Shell 外壳编程系列7 - ContextMenu 注册文件右键菜单</a> </span></p>
<p>&nbsp;</p>
<p><span style="color: #000000"><strong><font color="#ff9933" size="2">关于注册</font></strong></span></p>
<p><span style="color: red"><font color="#000000">动态库必须注册才能使用。除了使用 <font face="Verdana">regasm</font> 来注册 DLL 以外，还应该在代码中增加 <font face="Verdana">RegisterServer</font> 和 <font face="Verdana">UnregisterServer</font> 方法，以指导 DLL 注册时，在 Windows 注册表中增加什么键。关于具体键以下做简单说明：</font></span></p>
<p><span style="color: red"><font color="#000000"><strong>1) 注册 DLL 的 <font face="Verdana">Shell Extensions</font>。</strong>具体位置是 <font face="Verdana">HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved，增加以 GUID 为名称的键，值则是动态库说明。（此位置里面全是 Shell 扩展的动态库注册，许多相关软件就是从里面获取信息，例如 <font face="Verdana">ShexView</font>。</font></font></span></p>
<p><span style="color: red"><font color="#000000"><strong>2) 关联文件。</strong>Shell 扩展一般是针对文件或者文件夹的，因此必须关联。许多人都熟知&#8220;<font face="Verdana">HKEY_CLASSES_ROOT\*</font>&#8221;的作用，就是用来关联所有文件。而文件夹则是&#8220;<font face="Verdana">HKEY_CLASSES_ROOT\<font face="Verdana">Folder</font></font>&#8221;。然而如果具体到某种文件类型。可能会稍微复杂一点。我们可以从代码中看到一些启示：</font></span></p>
<p><span style="color: red"><font color="#000000"></font>&nbsp;</p>
<div class="cnblogs_code"><img id="Code_Closed_Image_090555" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_090555').style.display='none'; document.getElementById('Code_Open_Image_090555').style.display='inline'; document.getElementById('Code_Open_Text_090555').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_090555" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_090555').style.display='none'; getElementById('Code_Closed_Image_090555').style.display='inline'; getElementById('Code_Closed_Text_090555').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_090555">RegTXT</span><span id="Code_Open_Text_090555" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000ff">private</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;RegTXT()<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;RegistryKey&nbsp;root;<br />
&nbsp;&nbsp;&nbsp;&nbsp;RegistryKey&nbsp;rk;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;root&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Registry.ClassesRoot;<br />
&nbsp;&nbsp;&nbsp;&nbsp;rk&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;root.OpenSubKey(</span><span style="color: #800000">"</span><span style="color: #800000">.txt</span><span style="color: #800000">"</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;txtclass&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">string</span><span style="color: #000000">)rk.GetValue(</span><span style="color: #800000">""</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">string</span><span style="color: #000000">.IsNullOrEmpty(txtclass))<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;txtclass&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">TXT</span><span style="color: #800000">"</span><span style="color: #000000">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rk.SetValue(</span><span style="color: #800000">""</span><span style="color: #000000">,&nbsp;txtclass);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;rk.Close();<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;rk&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;root.CreateSubKey(txtclass&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">\\shellex\\ContextMenuHandlers\\</span><span style="color: #800000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;KEYNAME);<br />
&nbsp;&nbsp;&nbsp;&nbsp;rk.SetValue(</span><span style="color: #800000">""</span><span style="color: #000000">,&nbsp;GUID);<br />
&nbsp;&nbsp;&nbsp;&nbsp;rk.Close();<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;rk&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;root.CreateSubKey(txtclass&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">\\shellex\\IconHandler</span><span style="color: #800000">"</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;rk.SetValue(</span><span style="color: #800000">""</span><span style="color: #000000">,&nbsp;GUID);<br />
&nbsp;&nbsp;&nbsp;&nbsp;rk.Close();<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;rk&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;root.CreateSubKey(txtclass&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">\\shellex\\{00021500-0000-0000-C000-000000000046}</span><span style="color: #800000">"</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;rk.SetValue(</span><span style="color: #800000">""</span><span style="color: #000000">,&nbsp;GUID);<br />
&nbsp;&nbsp;&nbsp;&nbsp;rk.Close();<br />
}</span></span></div>
<p style="color: #000000">对于关联 .TXT，首先应该找寻&#8220;<font face="Verdana">HKEY_CLASSES_ROOT\.txt</font>&#8221;，但事情远远没那么简单，因为相当多的文本编辑工具，都会把改键重定向，例如EMEditor会把改键的默认值改为&#8220;<font face="Verdana">emeditor.txt</font>&#8221;。被重定向后，我们为了不破坏原有关联，应该到新的地方去注册（如果没有，我们就修改重定向至 TXT)。</p>
<p style="color: #000000">&nbsp;</p>
<p style="color: #000000">无论是 *、文件夹还是具体文件类型，都会有 ShellEx 的键，为 Shell 扩展专用。具体不同的扩展，应该注册不同的键。例如 <font face="Verdana">ContextMenuHandlers、<font face="Verdana">IconHandler</font>、或者<font face="Verdana">{00021500-0000-0000-C000-000000000046}</font>（其实这就是QueryInfo）。注册的方法很简单，把默认值改为 GUID 即可。</font></p>
<p style="color: #000000">&nbsp;</p>
<p style="color: #000000"><span style="color: red"><strong><font color="#ff9933" size="2">相同文件类型不同图标？</font></strong></span></p>
<p style="color: #000000"><span style="color: red"><font color="#000000">如果是以前，我会对这句话十分吃惊。但现在这种现象比比皆是。除了我们的例子外，.NET 程序员最熟悉的莫过于 Sln 解决方案文件了。不同版本的 Sln 图标不同，上面有个小版本号提示。</font></span></p>
<p></p>
<p>&nbsp;</p>
<p><span style="color: #000000"><img height="70" alt="" src="http://images.cnblogs.com/cnblogs_com/lemony/shell8-1.GIF" width="160" border="0" /></span></p>
<p><span style="color: #000000">不过后来我了解到，原来不同 Exe 显示不同的图标，也是这种原理，我晕。。。</span></p>
<p>&nbsp;</p>
<p><strong><font color="#ff9900" size="2">扩展接口</font></strong><br />
<span style="color: #000000">图标扩展处理器实现两个接口 <font color="#ff0000">IPersistFile</font> 和<font color="#ff0000"> IExtractIcon</font>.&nbsp;<br />
记得 <font color="#ff0000">IShellExtInit</font> 接口用于一次有多个选择文件时的处理，而&nbsp;<font color="#ff0000">IPersistFile</font> 则用于初始化只涉及一个选择文件时的处理。</span></p>
<p><span style="color: #000000">&nbsp;</p>
<div class="cnblogs_code"><img id="Code_Closed_Image_092020" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_092020').style.display='none'; document.getElementById('Code_Open_Image_092020').style.display='inline'; document.getElementById('Code_Open_Text_092020').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_092020" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_092020').style.display='none'; getElementById('Code_Closed_Image_092020').style.display='inline'; getElementById('Code_Closed_Text_092020').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_092020">IPersistFile 原型</span><span id="Code_Open_Text_092020" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">[ComImport(),&nbsp;ComVisible(</span><span style="color: #0000ff">true</span><span style="color: #000000">),&nbsp;InterfaceType(ComInterfaceType.InterfaceIsIUnknown),&nbsp;GuidAttribute(</span><span style="color: #800000">"</span><span style="color: #800000">0000010b-0000-0000-C000-000000000046</span><span style="color: #800000">"</span><span style="color: #000000">)]<br />
</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">interface</span><span style="color: #000000">&nbsp;IPersistFile<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;[PreserveSig]<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;GetClassID(</span><span style="color: #0000ff">out</span><span style="color: #000000">&nbsp;Guid&nbsp;pClassID);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;[PreserveSig]<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;IsDirty();<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;[PreserveSig]<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;Load([In,&nbsp;MarshalAs(UnmanagedType.LPWStr)]&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;pszFileName,&nbsp;[In]&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;dwMode);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;[PreserveSig]<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;Save([In,&nbsp;MarshalAs(UnmanagedType.LPWStr)]&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;pszFileName,&nbsp;[In]&nbsp;</span><span style="color: #0000ff">bool</span><span style="color: #000000">&nbsp;fRemember);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;[PreserveSig]<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;SaveCompleted([In,&nbsp;MarshalAs(UnmanagedType.LPWStr)]&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;pszFileName);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;[PreserveSig]<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;GetCurFile([MarshalAs(UnmanagedType.LPWStr)]&nbsp;</span><span style="color: #0000ff">out</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;ppszFileName);<br />
}</span></span></div>
<p>&nbsp;</p>
<p>对于这个接口，我们只需要用到 Load 方法</p>
<p></span>&nbsp;</p>
<div class="cnblogs_code"><img id="Code_Closed_Image_094022" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_094022').style.display='none'; document.getElementById('Code_Open_Image_094022').style.display='inline'; document.getElementById('Code_Open_Text_094022').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_094022" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_094022').style.display='none'; getElementById('Code_Closed_Image_094022').style.display='inline'; getElementById('Code_Closed_Text_094022').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_094022">Load</span><span id="Code_Open_Text_094022" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;Load(</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;pszFileName,&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;dwMode)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;szFileName&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;pszFileName;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;S_OK;<br />
}</span></span></div>
<p>&nbsp;</p>
<p><span style="color: #000000"><span style="color: #000000">szFileName 是全局变量，用来记住当前操作的文件路径。</span></span></p>
<p>&nbsp;</p>
<p><span style="color: #000000"><font color="#ff0000"><font color="#ff0000"></font><font color="#ff0000"></font><font color="#ff0000">IExtractIcon</font> <span style="color: #000000"><font style="color: #000000" color="#ff0000">接口图标扩展处理器实现 <font color="#ff0000">IExtractIcon</font> 接口，当浏览器需要为文件显示一个图标时将调用该接口。<br />
因为我们的扩展用于文本文件，浏览器将在每次显示文本文件对象时调用 <font color="#ff0000">IExtractIcon</font> 的方法。</font></span></font></span></p>
<p><span style="color: #000000"><font color="#ff0000"></font></span><span style="color: #000000"><font color="#ff0000">IExtractIcon </font>有两个方法，它们的作用是告诉浏览器所使用的图标。记住：浏览器为显示的每一个文件都将创建一个COM 对象。<br />
这就是说每一个文件都将有一个COM C++类对象对应. 因此在你的扩展中应该避免费时的操作以防止浏览界面反应迟滞。<br />
</p>
<div class="cnblogs_code"><img id="Code_Closed_Image_092329" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_092329').style.display='none'; document.getElementById('Code_Open_Image_092329').style.display='inline'; document.getElementById('Code_Open_Text_092329').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_092329" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_092329').style.display='none'; getElementById('Code_Closed_Image_092329').style.display='inline'; getElementById('Code_Closed_Text_092329').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_092329">IExtractIcon 原型</span><span id="Code_Open_Text_092329" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">[ComVisible(</span><span style="color: #0000ff">true</span><span style="color: #000000">),&nbsp;ComImport,&nbsp;Guid(</span><span style="color: #800000">"</span><span style="color: #800000">000214eb-0000-0000-c000-000000000046</span><span style="color: #800000">"</span><span style="color: #000000">),&nbsp;InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]<br />
</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">interface</span><span style="color: #000000">&nbsp;IExtractIcon<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;[PreserveSig]<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;GetIconLocation([In]&nbsp;ExtractIconOptions&nbsp;uFlags,&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[In]&nbsp;IntPtr&nbsp;szIconFile,&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[In]&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;cchMax,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[Out]&nbsp;</span><span style="color: #0000ff">out</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;piIndex,&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[Out]&nbsp;</span><span style="color: #0000ff">out</span><span style="color: #000000">&nbsp;ExtractIconFlags&nbsp;pwFlags);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;[PreserveSig]<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;Extract([In,&nbsp;MarshalAs(UnmanagedType.LPWStr)]&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;pszFile,&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;nIconIndex,&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[Out,&nbsp;MarshalAs(UnmanagedType.CustomMarshaler,&nbsp;MarshalTypeRef</span><span style="color: #000000">=</span><span style="color: #0000ff">typeof</span><span style="color: #000000">(IconMarshaler))]&nbsp;</span><span style="color: #0000ff">out</span><span style="color: #000000">&nbsp;Icon&nbsp;phiconLarge,&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[Out,&nbsp;MarshalAs(UnmanagedType.CustomMarshaler,&nbsp;MarshalTypeRef</span><span style="color: #000000">=</span><span style="color: #0000ff">typeof</span><span style="color: #000000">(IconMarshaler))]&nbsp;</span><span style="color: #0000ff">out</span><span style="color: #000000">&nbsp;Icon&nbsp;phiconSmall,&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[In]&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;nIconSize);<br />
}&nbsp;</span></span></div>
<p>&nbsp;</p>
<p>和许多教程上面说的一样，有两种方法可将图标返回给浏览器。但我在尝试第一种方式的时候，未能成功，十分奇怪。不过我还是应该把这种方法简单说明。</p>
<p>&nbsp;</p>
<p>第一种是 <font color="#ff0000">GetIconLocation()</font> 可以返回文件名/索引对以指出包含图标的文件,和图标在该文件中索引位置（以0为基）。<font color="#ff0000">Extract()</font> 只需返回 <font color="#ff0000">S_FALSE</font> 给浏览器让它自己来解析图标。该方法的特别之处在于浏览器在 <font color="#ff0000">GetIconLocation()</font> 返回之后不一定会调用 <font color="#ff0000">Extract()</font>.。浏览器会保持一个图标缓存以存储最近使用的图标。<br />
如果 <font color="#ff0000">GetIconLocation()</font> 返回最近已使用的文件名/索引对，而且图标仍然在缓存中，浏览器就可以直接使用缓存中的图标而不会去调用<font color="#ff0000">Extract()<span style="color: #000000"><font color="#ff0000">。</font><br />
<br />
</span></font>第二种方法是从<font color="#ff0000">GetIconLocation()</font> 中返回不要查看缓冲的标志，这样会使浏览器去调用<font color="#ff0000">Extract()<span style="color: #000000">，</span></font><font color="#ff0000">Extract()</font> 则负责加载图标资源并将其句柄返回给浏览器。<br />
</p>
<p>&nbsp;</p>
<p>这里具体介绍第二种方法。在这方法中，<font color="#ff0000">GetIconLocation()</font> 作用仅仅是设置一些标志位，以及获取文件大小。</p>
<p>&nbsp;</p>
<div class="cnblogs_code"><img id="Code_Closed_Image_092930" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_092930').style.display='none'; document.getElementById('Code_Open_Image_092930').style.display='inline'; document.getElementById('Code_Open_Text_092930').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_092930" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_092930').style.display='none'; getElementById('Code_Closed_Image_092930').style.display='inline'; getElementById('Code_Closed_Text_092930').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_092930">GetIconLocation</span><span id="Code_Open_Text_092930" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;IExtractIcon.GetIconLocation(ExtractIconOptions&nbsp;uFlags,&nbsp;IntPtr&nbsp;szIconFile,&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;cchMax,&nbsp;</span><span style="color: #0000ff">out</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;piIndex,&nbsp;</span><span style="color: #0000ff">out</span><span style="color: #000000">&nbsp;ExtractIconFlags&nbsp;pwFlags)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;piIndex&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">-</span><span style="color: #800080">1</span><span style="color: #000000">;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">try</span><span style="color: #000000"><br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileInfo&nbsp;f&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;FileInfo(szFileName);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lngFileSize&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;f.Length;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pwFlags&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;ExtractIconFlags.DontCache&nbsp;</span><span style="color: #000000">|</span><span style="color: #000000">&nbsp;ExtractIconFlags.NotFilename;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;S_OK;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">catch</span><span style="color: #000000">&nbsp;{&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;pwFlags&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;ExtractIconFlags.None;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;S_FALSE;<br />
}</span></span></div>
<p><font face="Verdana">其参数为: uFlags 改变扩展行为的标志。<br />
<font color="#ff0000">ExtractIconFlags.DONTCACHE</font> 告诉浏览器不要检查图标缓冲而去使用最近的<font color="#ff0000"> szIconFile/piIndex</font> 对。其结果是<font color="#ff0000">IExtractIcon::Extract()</font> 将被调用.。<br />
<font color="#ff0000"><font color="#ff0000">ExtractIconFlags.</font>NOTFILENAME</font> 根据 MSDN，该标志告诉浏览器当<font color="#ff0000">GetIconLocation()</font>返回时忽略 <font color="#ff0000">szIconFile/piIndex</font> 的内容。<br />
szIconFile 是由shell 提供的一个缓冲要求我们填入包含所使用的图标的文件名.<br />
cchMax 是该缓冲区的大小。<br />
piIndex int 的指针，要求我们添入图标在文件中的索引。<br />
pwFlags UINT 的指针，要求我们返回影响浏览器行为的标志。</font></p>
<p>&nbsp;</p>
<p>使用第二种方法，我们并不需要填写 piIndex 和 szIconFile，而<font face="Verdana"> IExtractIcon.Extract() 总被调用,并负责加载图标并返回两个图标句柄 HICON 给浏览器 &#8211; 一个是大图标, 一个是小图标。该方法的好处是你不必考虑你的图标资源在文件中的顺序位置。其缺陷在于它忽略了浏览器的图标缓冲,这会使显示速度减慢，特别是在有浏览有无数个文件的目录时。</font></p>
<p>&nbsp;</p>
<div class="cnblogs_code"><img id="Code_Closed_Image_093340" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_093340').style.display='none'; document.getElementById('Code_Open_Image_093340').style.display='inline'; document.getElementById('Code_Open_Text_093340').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_093340" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_093340').style.display='none'; getElementById('Code_Closed_Image_093340').style.display='inline'; getElementById('Code_Closed_Text_093340').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_093340">IExtractIcon.Extract</span><span id="Code_Open_Text_093340" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;IExtractIcon.Extract(</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;pszFile,&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;nIconIndex,&nbsp;</span><span style="color: #0000ff">out</span><span style="color: #000000">&nbsp;Icon&nbsp;phiconLarge,&nbsp;</span><span style="color: #0000ff">out</span><span style="color: #000000">&nbsp;Icon&nbsp;phiconSmall,&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;nIconSize)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;phiconLarge&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;phiconSmall&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">try</span><span style="color: #000000"><br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(lngFileSize&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">16</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">1024</span><span style="color: #000000">)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;phiconLarge&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Resource1._2;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;phiconSmall&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Icon(Resource1._2,&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Size(</span><span style="color: #800080">16</span><span style="color: #000000">,&nbsp;</span><span style="color: #800080">16</span><span style="color: #000000">));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(lngFileSize&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;phiconLarge&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Resource1._1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;phiconSmall&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Icon(Resource1._1,&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Size(</span><span style="color: #800080">16</span><span style="color: #000000">,&nbsp;</span><span style="color: #800080">16</span><span style="color: #000000">));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;phiconLarge&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Resource1._0;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;phiconSmall&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Icon(Resource1._0,&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Size(</span><span style="color: #800080">16</span><span style="color: #000000">,&nbsp;</span><span style="color: #800080">16</span><span style="color: #000000">));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;S_OK;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">catch</span><span style="color: #000000">&nbsp;{&nbsp;}<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;S_FALSE;<br />
}<br />
</span></span></div>
<p><font face="Verdana">其参数为: </font></p>
<p><font face="Verdana">pszFile/nIconIndex 文件名和索引指定图标位置。其值与从 GetIconLocation() 返回的一样。<br />
phiconSmall HICON 的指针，由 Extract() 返回指向大图标和小图标的句柄数组。<br />
nIconSize 指定要求的图标大小。高字为小图标的长度 (长宽一致)，低字为大图标的长度。在一般情况下, 其值为0x00100020 (高字16, 低字 32) 表示小图标应该是 16x16，大图标为 32x32。在我们的扩展中, 我们并没有在 GetIconLocation() 里填写 pszFile 和 nIconIndex 所以在这忽略，我们只加载图标并返回给浏览器。</font></p>
<p>&nbsp;</p>
<p>从代码可以看到，根据文件大小的不同，加载了相应的图标资源返回给浏览器。效果如下：</p>
<p><img height="220" alt="" src="http://images.cnblogs.com/cnblogs_com/lemony/shell7-2.GIF" width="345" border="0" /></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>代码：<a href="http://files.cnblogs.com/lemony/MyContextMenu.rar">http://files.cnblogs.com/lemony/MyContextMenu.rar</a></p>
<p>&nbsp;</p>
<p>关于代码：代码里面还包括了提示扩展的代码，如果有兴趣，可自行阅读。</p>
<p>&nbsp;</p>
<p>题外话：还有相当多的关于 Shell 扩展的内容无法一一说明，如果有机会，以后会尽量补上。或大家查阅网上的&#8220;<font face="Verdana">Windows Shell扩展编程完全指南&#8221;（虽然是VC版的，但内容相当丰富）</font></p>
</span></span>
<img src="http://www.cnblogs.com/lemony/aggbug/1280925.html?type=1" width="1" height="1" alt=""/><p>评论: 16　<a href="http://www.cnblogs.com/lemony/archive/2008/09/01/1280925.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/lemony/archive/2008/09/01/1280925.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56845/" target="_blank">奇虎新注资两家知名软件公司 投资项目达10笔</a><span style="color:gray">(2010-02-10 15:14)</span><br/>· <a href="http://news.cnblogs.com/n/56844/" target="_blank">网友对Google的9大期待</a><span style="color:gray">(2010-02-10 15:07)</span><br/>· <a href="http://news.cnblogs.com/n/56843/" target="_blank">分析称Google Buzz有十大特点：将改变搜索</a><span style="color:gray">(2010-02-10 15:06)</span><br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>(C#)Windows Shell 外壳编程系列7 - ContextMenu 注册文件右键菜单</title><link>http://www.cnblogs.com/lemony/archive/2008/08/29/1279588.html</link><dc:creator>柠檬的</dc:creator><author>柠檬的</author><pubDate>Fri, 29 Aug 2008 09:17:00 GMT</pubDate><guid>http://www.cnblogs.com/lemony/archive/2008/08/29/1279588.html</guid><description><![CDATA[<p>阅读: 3811 评论: 8 作者: <a href="http://www.cnblogs.com/lemony/" target="_blank">柠檬的</a> 发表于 2008-08-29 17:17 <a href="http://www.cnblogs.com/lemony/archive/2008/08/29/1279588.html" target="_blank">原文链接</a></p><p><span style="color: red">（本系列文章由柠檬的(lc_mtt)原创，转载请注明出处，谢谢～）</span></p>
<p>&nbsp;</p>
<p>接上一节：<a class="postTitle2" id="AjaxHolder_ctl01_TitleUrl" href="http://www.cnblogs.com/lemony/archive/2007/04/27/729606.html">(C#)Windows Shell 外壳编程系列6 - 执行</a> </p>
<p>&nbsp;</p>
<p>从本节起，我所要讲述的是对 Windows 系统的&#8220;Shell 扩展&#8221;。&#8220;Shell 扩展&#8221;从字面上分两个部分：Shell 与 Extension。Shell 指 Windows Explorer，而Extension 则指由你编写的当某一预先约定好的事件（如在以. doc 为后缀的文件图标上单击右键）发生时由 Explorer 调用执行的代码。因此一个&#8220;Shell 扩展&#8221;就是一个为 Explorer 添加功能的 COM 对象。&nbsp;</p>
<font face="Verdana">
<p><br />
&#8220;Shell 扩展&#8221;有很多种类型，每种类型都在各自不同的事件发生时被调用运行，但也有一些扩展的类型和调用情形是非常相似的。<br />
</font>&nbsp;</p>
<p>
<table width="75%" border="1">
    <tr>
            <td><span style="font-family: SimSun"><font face="Arial" size="2">类型</font></span><span lang="EN-US"><font face="Arial" size="2"><O:P></O:P></font></span></td>
            <td><span style="font-family: SimSun"><font face="Arial" size="2">何时被调用</font></span></td>
            <td><span style="font-family: SimSun"><font face="Arial" size="2">应该作些什么</font></span><span lang="EN-US"><font face="Arial" size="2"><O:P> </O:P></font></span></td>
        </tr>
        <tr>
            <td><span style="font-family: SimSun"><font face="Arial" size="2">Context menu <br />
            扩展处理器</font></span><span lang="EN-US" style="font-family: Verdana"><font face="Arial" size="2"><O:P> </O:P></font></span></td>
            <td><span style="font-family: SimSun"><font face="Arial" size="2">用户右键单击文件或文件夹对象时，<br />
            或在一个文件夹窗口中的背景处单击右键时（要求</font></span><span lang="EN-US" style="font-family: Verdana"><font face="Arial" size="2">shell</font></span><span style="font-family: SimSun"><font face="Arial" size="2">版本为</font></span><span lang="EN-US" style="font-family: Verdana"><font face="Arial" size="2">4.71+</font></span><span style="font-family: SimSun"><font face="Arial" size="2">）</font></span></td>
            <td><span style="font-family: SimSun"><font face="Arial" size="2">添加菜单项到上下文菜单中</font></span></td>
        </tr>
        <tr>
            <td><span style="font-family: SimSun"><font face="Arial" size="2">Property sheet<br />
            扩展处理器</font></span><span lang="EN-US" style="font-family: Verdana"><font face="Arial" size="2"><O:P> </O:P></font></span></td>
            <td><span style="font-family: SimSun"><font face="Arial" size="2">要显示一个文件对象的属性框时</font></span></td>
            <td><span style="font-family: SimSun"><font face="Arial" size="2">添加定制属性页到属性表中</font></span></td>
        </tr>
        <tr>
            <td><span style="font-family: SimSun"><font face="Arial" size="2">Drag and drop <br />
            扩展处理器</font></span><span lang="EN-US" style="font-family: Verdana"><font face="Arial" size="2"><O:P> </O:P></font></span></td>
            <td><span style="font-family: SimSun"><font face="Arial" size="2">用户用右键拖放文件对象到文件夹窗口或桌面时</font></span></td>
            <td><span style="font-family: SimSun"><font face="Arial" size="2">添加菜单项到上下文菜单中</font></span></td>
        </tr>
        <tr>
            <td height="2"><span style="font-family: SimSun"><font face="Arial" size="2">Drop 扩展处理器</font></span><span lang="EN-US" style="font-family: Verdana"><font face="Arial" size="2"><O:P> </O:P></font></span></td>
            <td height="2"><span style="font-family: SimSun"><font face="Arial" size="2">用户拖动</font></span><span lang="EN-US" style="font-family: Verdana"><font face="Arial" size="2">Shell</font></span><span style="font-family: SimSun"><font face="Arial" size="2">对象并将它放到一个文件对象上时</font></span></td>
            <td height="2"><span style="font-family: SimSun"><font face="Arial" size="2">任何想要的操作</font></span></td>
        </tr>
        <tr>
            <td height="2"><span style="font-family: SimSun"><font face="Arial" size="2">QueryInfo扩展处理器</font></span><span lang="EN-US" style="font-family: Verdana"><font face="Arial" size="2"> (</font></span><span style="font-family: SimSun"><font face="Arial" size="2">需要</font></span><span lang="EN-US" style="font-family: Verdana"><font face="Arial" size="2">shell</font></span><span style="font-family: SimSun"><font face="Arial" size="2">版本</font></span><span lang="EN-US" style="font-family: Verdana"><font face="Arial" size="2"> 4.71+)<O:P> </O:P></font></span></td>
            <td height="2"><span style="font-family: SimSun"><font face="Arial" size="2">用户将鼠标盘旋于文件或其他</font></span><span lang="EN-US" style="font-family: Verdana"><font face="Arial" size="2">Shell</font></span><span style="font-family: SimSun"><font face="Arial" size="2">对象的图标上时</font></span><span lang="EN-US" style="font-family: Verdana"><font face="Arial" size="2"><O:P></O:P></font></span></td>
            <td height="2"><span style="font-family: SimSun"><font face="Arial" size="2">返回一个浏览器用于显示在提示框中的字符串</font></span></td>
        </tr>
    </table>
</p>
<p>&nbsp;</p>
<p>现在你可能想知道&#8220;Shell 扩展&#8221;到底是什么样的，不过我还是乐意把我后面所实现的技术效果直接展示出来。以下三副图片分别代表了三种&#8220;Shell 扩展&#8221;：</p>
<p>&nbsp;</p>
<p>（1）实现类似 WinRAR 的右键菜单</p>
<p><span style="color: red"><img height="414" alt="" src="http://www.cnblogs.com/images/cnblogs_com/lemony/shell7-1.GIF" width="519" border="0" /></span></p>
<p>&nbsp;</p>
<p>（2）根据文本大小，显示不同的 TXT 文件图标</p>
<p><span style="color: red"><img height="220" alt="" src="http://www.cnblogs.com/images/cnblogs_com/lemony/shell7-2.GIF" width="345" border="0" /></span></p>
<p>&nbsp;</p>
<p>（3）当鼠标移动到 TXT 文件图标上的时候，显示内容预览。</p>
<p><span style="color: red"><img height="323" alt="" src="http://www.cnblogs.com/images/cnblogs_com/lemony/shell7-3.GIF" width="480" border="0" /></span></p>
<p>&nbsp;</p>
<p><strong>好，废话不多说了，赶紧进入今天要讲述的内容：<font face="Verdana">&nbsp;ContextMenu 注册文件右键菜单。</font></strong></p>
<p>&nbsp;</p>
<p>对于 WinRAR 所实现的效果，其实叫做上下文菜单。例如我们把扩展关联到 .TXT 文件，当用户右键单击文本文件对象时扩展就会被调用，然后向系统菜单增加菜单项，并响应相应的命令。由此可见，基本上每种 Shell 扩展，都需要做一些几乎一样的事情。</p>
<p>&nbsp;</p>
<strong><font color="#ff9933" size="2">初始化接口 </font></strong><br />
当我们的shell扩展被加载时，Explorer 将调用我们所实现的COM对象的 <font color="#ff3333">QueryInterface()</font> 函数以取得一个<font color="#ff3333"> IShellExtInit</font> 接口指针。该接口仅有一个方法<font color="#ff3333"> Initialize()</font>，其函数原型为：&nbsp;&nbsp;
<p>&nbsp;</p>
<div class="cnblogs_code"><img id="Code_Closed_Image_164437" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_164437').style.display='none'; document.getElementById('Code_Open_Image_164437').style.display='inline'; document.getElementById('Code_Open_Text_164437').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_164437" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_164437').style.display='none'; getElementById('Code_Closed_Image_164437').style.display='inline'; getElementById('Code_Closed_Text_164437').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_164437">IShellExtInit原型</span><span id="Code_Open_Text_164437" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">[ComImport(),&nbsp;InterfaceType(ComInterfaceType.InterfaceIsIUnknown),&nbsp;GuidAttribute(</span><span style="color: #800000">"</span><span style="color: #800000">000214e8-0000-0000-c000-000000000046</span><span style="color: #800000">"</span><span style="color: #000000">)]<br />
</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">interface</span><span style="color: #000000">&nbsp;IShellExtInit<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;[PreserveSig()]<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;Initialize(IntPtr&nbsp;pidlFolder,&nbsp;IntPtr&nbsp;lpdobj,&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">hKeyProgID);<br />
}</span></span></div>
<p>&nbsp;</p>
<p>Explorer 使用该方法传递给我们各种各样的信息.<br />
<font color="#ff3333">pidlFolder </font>是用户所选择操作的文件所在的文件夹的 PIDL 变量. (一个 PIDL [指向ID 列表的指针] 是一个数据结构，它唯一地标识了在Shell命名空间的任何对象, 一个Shell命名空间中的对象可以是也可以不是真实的文件系统中的对象。)<br />
<font color="#ff3333">lpdobj</font>&nbsp;是一个 <font color="#ff3333">IDataObject </font>接口指针，通过它我们可以获取用户所选择操作的文件名。<br />
<font color="#ff3333">hKeyProgID</font> 是一个<font color="#ff3333">HKEY </font>注册表键变量，可以用它获取我们的DLL的注册数据。</p>
<p>&nbsp;</p>
<p>因此我们可以在这个方法中，获取到被右击选择的一个或多个文件/文件夹名。</p>
<p>&nbsp;</p>
<div class="cnblogs_code"><img id="Code_Closed_Image_165605" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_165605').style.display='none'; document.getElementById('Code_Open_Image_165605').style.display='inline'; document.getElementById('Code_Open_Text_165605').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_165605" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_165605').style.display='none'; getElementById('Code_Closed_Image_165605').style.display='inline'; getElementById('Code_Closed_Text_165605').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_165605">IShellExtInit.Initialize</span><span id="Code_Open_Text_165605" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000ff">protected</span><span style="color: #000000">&nbsp;ShellLib.IDataObject&nbsp;m_dataObject&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">;<br />
</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;m_hDrop&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">;<br />
<br />
</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;IShellExtInit.Initialize(IntPtr&nbsp;pidlFolder,&nbsp;IntPtr&nbsp;lpdobj,&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;hKeyProgID)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">try</span><span style="color: #000000"><br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_dataObject&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(lpdobj&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;(IntPtr)</span><span style="color: #800080">0</span><span style="color: #000000">)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_dataObject&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(ShellLib.IDataObject)Marshal.GetObjectForIUnknown(lpdobj);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FORMATETC&nbsp;fmt&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;FORMATETC();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fmt.cfFormat&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;CLIPFORMAT.CF_HDROP;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fmt.ptd&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fmt.dwAspect&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;DVASPECT.DVASPECT_CONTENT;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fmt.lindex&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">-</span><span style="color: #800080">1</span><span style="color: #000000">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fmt.tymed&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;TYMED.TYMED_HGLOBAL;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;STGMEDIUM&nbsp;medium&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;STGMEDIUM();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_dataObject.GetData(</span><span style="color: #0000ff">ref</span><span style="color: #000000">&nbsp;fmt,&nbsp;</span><span style="color: #0000ff">ref</span><span style="color: #000000">&nbsp;medium);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_hDrop&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;medium.hGlobal;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">catch</span><span style="color: #000000">&nbsp;(Exception)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;S_OK;<br />
}</span></span></div>
<p>&nbsp;</p>
<p><font face="Verdana">IDataObject</font> 是一个接口，包含了一些获取文件名的方法，后面可以用到。</p>
<p>&nbsp;</p>
<p><font color="#ff9966"><strong><font size="2">与上下文菜单交互的接口 <br />
<br />
</font></strong></font>一旦 Explorer 初始化了扩展,它就会接着调用 <font color="#ff3333">IContextMenu</font> 的方法让我们添加菜单项, 提供状态栏上的提示, 并响应执行用户的选择。<font color="#ff3333">IContextMenu </font>接口定义了以下几个方法：<br />
</p>
<div class="cnblogs_code"><img id="Code_Closed_Image_165946" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_165946').style.display='none'; document.getElementById('Code_Open_Image_165946').style.display='inline'; document.getElementById('Code_Open_Text_165946').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_165946" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_165946').style.display='none'; getElementById('Code_Closed_Image_165946').style.display='inline'; getElementById('Code_Closed_Text_165946').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_165946">IContextMenu原型</span><span id="Code_Open_Text_165946" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">[ComImport(),&nbsp;InterfaceType(ComInterfaceType.InterfaceIsIUnknown),&nbsp;GuidAttribute(</span><span style="color: #800000">"</span><span style="color: #800000">000214e4-0000-0000-c000-000000000046</span><span style="color: #800000">"</span><span style="color: #000000">)]<br />
</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">interface</span><span style="color: #000000">&nbsp;IContextMenu<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;[PreserveSig()]<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;QueryContextMenu(HMenu&nbsp;hmenu,&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;iMenu,&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;idCmdFirst,&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;idCmdLast,&nbsp;CMF&nbsp;uFlags);<br />
&nbsp;&nbsp;&nbsp;&nbsp;[PreserveSig()]<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;InvokeCommand(IntPtr&nbsp;pici);<br />
&nbsp;&nbsp;&nbsp;&nbsp;[PreserveSig()]<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;GetCommandString(</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;idcmd,&nbsp;GCS&nbsp;uflags,&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;reserved,&nbsp;IntPtr&nbsp;commandstring,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;cchMax);<br />
}</span></span></div>
<p>&nbsp;</p>
<p>第一个是 <font color="#ff3333">QueryContextMenu()</font>, 它让我们可以修改上下文菜单。其参数：</p>
<p><font color="#ff3333">hmenu </font>上下文菜单句柄。<br />
<font color="#ff3333">uMenuIndex</font> 是我们应该添加菜单项的起始位置。<br />
<font color="#ff3333">uidFirstCmd</font> 和 <font color="#ff3333">uidLastCmd</font> 是我们可以使用的菜单命令ID值的范围。<br />
<font color="#ff3333">uFlags</font> 标识了Explorer 调用 <font color="#ff3333">QueryContextMenu() </font>的原因。</p>
<p>&nbsp;</p>
<p>我们调用该方法，为上下文菜单增加几个菜单项：</p>
<p>&nbsp;</p>
<div class="cnblogs_code"><img id="Code_Closed_Image_170241" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_170241').style.display='none'; document.getElementById('Code_Open_Image_170241').style.display='inline'; document.getElementById('Code_Open_Text_170241').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_170241" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_170241').style.display='none'; getElementById('Code_Closed_Image_170241').style.display='inline'; getElementById('Code_Closed_Text_170241').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_170241">IContextMenu.QueryContextMenu</span><span id="Code_Open_Text_170241" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;IContextMenu.QueryContextMenu(HMenu&nbsp;hMenu,&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;iMenu,&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;idCmdFirst,&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;idCmdLast,&nbsp;CMF&nbsp;uFlags)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;id&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;((uFlags&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;(CMF.CMF_VERBSONLY&nbsp;</span><span style="color: #000000">|</span><span style="color: #000000">&nbsp;CMF.CMF_DEFAULTONLY&nbsp;</span><span style="color: #000000">|</span><span style="color: #000000">&nbsp;CMF.CMF_NOVERBS))&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">||</span><span style="color: #000000"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(uFlags&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;CMF.CMF_EXPLORE)&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">创建子菜单</span><span style="color: #008000"><br />
</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HMenu&nbsp;submenu&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;ShellLib.Helpers.CreatePopupMenu();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Helpers.AppendMenu(submenu,&nbsp;MFMENU.MF_STRING,&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;IntPtr(idCmdFirst&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;id</span><span style="color: #000000">++</span><span style="color: #000000">),&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">复制路径(&amp;C)</span><span style="color: #800000">"</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Helpers.AppendMenu(submenu,&nbsp;MFMENU.MF_STRING,&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;IntPtr(idCmdFirst&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;id</span><span style="color: #000000">++</span><span style="color: #000000">),&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">复制文本内容(&amp;T)</span><span style="color: #800000">"</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Helpers.AppendMenu(submenu,&nbsp;MFMENU.MF_STRING,&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;IntPtr(idCmdFirst&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;id</span><span style="color: #000000">++</span><span style="color: #000000">),&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">柠檬的博客(&amp;L)<img alt="" src="http://www.cnblogs.com/Images/dot.gif" /></span><span style="color: #800000">"</span><span style="color: #000000">);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">将子菜单插入到上下文菜单中</span><span style="color: #008000"><br />
</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Helpers.InsertMenu(hMenu,&nbsp;</span><span style="color: #800080">1</span><span style="color: #000000">,&nbsp;MFMENU.MF_BYPOSITION&nbsp;</span><span style="color: #000000">|</span><span style="color: #000000">&nbsp;MFMENU.MF_POPUP,&nbsp;submenu.handle,&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">MyContextMenu(&amp;Y)</span><span style="color: #800000">"</span><span style="color: #000000">);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">为菜单增加图标</span><span style="color: #008000"><br />
</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bitmap&nbsp;bpCopy&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Resource1.copy;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Helpers.SetMenuItemBitmaps(submenu,&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">,&nbsp;MFMENU.MF_BYPOSITION,&nbsp;bpCopy.GetHbitmap(),&nbsp;bpCopy.GetHbitmap());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Helpers.SetMenuItemBitmaps(submenu,&nbsp;</span><span style="color: #800080">1</span><span style="color: #000000">,&nbsp;MFMENU.MF_BYPOSITION,&nbsp;bpCopy.GetHbitmap(),&nbsp;bpCopy.GetHbitmap());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bitmap&nbsp;bpHome&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Resource1.home;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Helpers.SetMenuItemBitmaps(submenu,&nbsp;</span><span style="color: #800080">2</span><span style="color: #000000">,&nbsp;MFMENU.MF_BYPOSITION,&nbsp;bpHome.GetHbitmap(),&nbsp;bpHome.GetHbitmap());<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;id;<br />
}</span></span></div>
<p>&nbsp;</p>
<p><font color="#ff9966" size="2"><strong>在状态栏上显示提示帮助</strong></font><br />
<br />
下一个要被调用的<font color="#ff3333">IContextMenu</font> 方法是 <font color="#ff3333">GetCommandString().。</font>如果用户是在浏览器窗口中右击文本文件，或选中一个文本文件后单击文件菜单时,状态栏会显示提示帮助。我们的 <font color="#ff3333">GetCommandString()</font> 函数将返回一个帮助字符串供浏览器显示。</p>
<p>&nbsp;</p>
<div class="cnblogs_code"><img id="Code_Closed_Image_170453" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_170453').style.display='none'; document.getElementById('Code_Open_Image_170453').style.display='inline'; document.getElementById('Code_Open_Text_170453').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_170453" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_170453').style.display='none'; getElementById('Code_Closed_Image_170453').style.display='inline'; getElementById('Code_Closed_Text_170453').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_170453">IContextMenu.GetCommandString</span><span id="Code_Open_Text_170453" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;IContextMenu.GetCommandString(</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;idcmd,&nbsp;GCS&nbsp;uflags,&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;reserved,&nbsp;IntPtr&nbsp;commandstring,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;cchMax)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;tip&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">""</span><span style="color: #000000">;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">switch</span><span style="color: #000000">&nbsp;(uflags)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;GCS.VERB:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;GCS.HELPTEXTW:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">switch</span><span style="color: #000000">&nbsp;(idcmd)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tip&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">把选中的文件/文件夹的全路径复制到剪切板</span><span style="color: #800000">"</span><span style="color: #000000">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">1</span><span style="color: #000000">:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tip&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">把选中的&nbsp;TXT&nbsp;文本内容复制到剪切板</span><span style="color: #800000">"</span><span style="color: #000000">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">2</span><span style="color: #000000">:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tip&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">访问柠檬的博客&nbsp;http://lemony.cnblogs.com</span><span style="color: #800000">"</span><span style="color: #000000">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">default</span><span style="color: #000000">:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(</span><span style="color: #000000">!</span><span style="color: #0000ff">string</span><span style="color: #000000">.IsNullOrEmpty(tip))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">byte</span><span style="color: #000000">[]&nbsp;data&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">byte</span><span style="color: #000000">[cchMax&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">2</span><span style="color: #000000">];<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Encoding.Unicode.GetBytes(tip,&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">,&nbsp;tip.Length,&nbsp;data,&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Marshal.Copy(data,&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">,&nbsp;commandstring,&nbsp;data.Length);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</span></span></div>
<p>&nbsp;</p>
<p><font color="#ff9966" size="2"><strong>执行用户的选择 </strong></font><br />
<br />
<font color="#ff3333">IContextMenu</font> 接口的最后一个方法是<font color="#ff3333"> InvokeCommand()</font>。当用户点击我们添加的菜单项时该方法将被调用。其参数：</p>
<p><font color="#ff3333">CMINVOKECOMMANDINFO</font> 结构带有大量的信息, 但我们只关心 <font color="#ff3333">lpVerb</font> 和 <font color="#ff3333">hwnd</font> 这两个成员。<br />
<font color="#ff3333">lpVerb</font>参数有两个作用 &#8211; 它或是可被激发的verb(动作)名, 或是被点击的菜单项的索引值。</p>
<p><font color="#ff3333">hwnd</font> 是用户激活我们的菜单扩展时所在的浏览器窗口的句柄。</p>
<p>&nbsp;</p>
<p>我们可以根据被点击的菜单项索引，来执行相应的操作。</p>
<p>&nbsp;</p>
<div class="cnblogs_code"><img id="Code_Closed_Image_170701" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_170701').style.display='none'; document.getElementById('Code_Open_Image_170701').style.display='inline'; document.getElementById('Code_Open_Text_170701').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_170701" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_170701').style.display='none'; getElementById('Code_Closed_Image_170701').style.display='inline'; getElementById('Code_Closed_Text_170701').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_170701">IContextMenu.InvokeCommand</span><span id="Code_Open_Text_170701" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;IContextMenu.InvokeCommand(IntPtr&nbsp;pici)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;INVOKECOMMANDINFO&nbsp;ici&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(INVOKECOMMANDINFO)Marshal.PtrToStructure(pici,&nbsp;</span><span style="color: #0000ff">typeof</span><span style="color: #000000">(ShellLib.INVOKECOMMANDINFO));<br />
&nbsp;&nbsp;&nbsp;&nbsp;StringBuilder&nbsp;sb&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;StringBuilder(</span><span style="color: #800080">1024</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;StringBuilder&nbsp;sbAll&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;StringBuilder();<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;nselected;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">switch</span><span style="color: #000000">&nbsp;(ici.verb)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">复制文件名</span><span style="color: #008000"><br />
</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nselected&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Helpers.DragQueryFile(m_hDrop,&nbsp;</span><span style="color: #800080">0xffffffff</span><span style="color: #000000">,&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">,&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;nselected;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ShellLib.Helpers.DragQueryFile(m_hDrop,&nbsp;i,&nbsp;sb,&nbsp;sb.Capacity&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">1</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sbAll.Append(sb.ToString()&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">\n</span><span style="color: #800000">"</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Clipboard.Clear();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Clipboard.SetDataObject(sbAll.ToString(),&nbsp;</span><span style="color: #0000ff">true</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">1</span><span style="color: #000000">:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">复制文件内容</span><span style="color: #008000"><br />
</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nselected&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Helpers.DragQueryFile(m_hDrop,&nbsp;</span><span style="color: #800080">0xffffffff</span><span style="color: #000000">,&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">,&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">uint</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;nselected;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ShellLib.Helpers.DragQueryFile(m_hDrop,&nbsp;i,&nbsp;sb,&nbsp;sb.Capacity&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">1</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;StreamReader&nbsp;sr&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;StreamReader(sb.ToString(),&nbsp;Encoding.GetEncoding(</span><span style="color: #800000">"</span><span style="color: #800000">gb2312</span><span style="color: #800000">"</span><span style="color: #000000">));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sbAll.Append(sr.ReadToEnd());<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sr.Close();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Clipboard.Clear();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Clipboard.SetDataObject(sbAll.ToString(),&nbsp;</span><span style="color: #0000ff">true</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">case</span><span style="color: #000000">&nbsp;</span><span style="color: #800080">2</span><span style="color: #000000">:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">调用浏览器，打开网页</span><span style="color: #008000"><br />
</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Process&nbsp;proc&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;Process();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proc.StartInfo.FileName&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">IExplore.exe</span><span style="color: #800000">"</span><span style="color: #000000">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proc.StartInfo.Arguments&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">http://lemony.cnblogs.com</span><span style="color: #800000">"</span><span style="color: #000000">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proc.Start();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">default</span><span style="color: #000000">:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">break</span><span style="color: #000000">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</span></span></div>
<p>&nbsp;</p>
<p><font color="#ff9966" size="2"><strong>注册Shell扩展</strong></font><br />
现在我们已经实现了所有需要的COM接口. 可是我们怎样才能让浏览器使用我们的扩展呢？首先，我们要注册动态库。但仅仅这样是不够的，为了告诉浏览器使用我们的扩展, 我们需要在文本文件类型的注册表键下注册扩展。</p>
<p>(请原谅我未能抽出时间对注册扩展做详细的说明（如果以后有机会会补上），大家可以自行研究)</p>
<p>&nbsp;</p>
<div class="cnblogs_code"><img id="Code_Closed_Image_170910" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_170910').style.display='none'; document.getElementById('Code_Open_Image_170910').style.display='inline'; document.getElementById('Code_Open_Text_170910').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_170910" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_170910').style.display='none'; getElementById('Code_Closed_Image_170910').style.display='inline'; getElementById('Code_Closed_Text_170910').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_170910">注册扩展</span><span id="Code_Open_Text_170910" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">[System.Runtime.InteropServices.ComRegisterFunctionAttribute()]<br />
</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;RegisterServer(String&nbsp;str1)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">try</span><span style="color: #000000"><br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">注册&nbsp;DLL</span><span style="color: #008000"><br />
</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RegistryKey&nbsp;root;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RegistryKey&nbsp;rk;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;root&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Registry.LocalMachine;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rk&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;root.OpenSubKey(</span><span style="color: #800000">"</span><span style="color: #800000">Software\\Microsoft\\Windows\\CurrentVersion\\Shell&nbsp;Extensions\\Approved</span><span style="color: #800000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #0000ff">true</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rk.SetValue(GUID,&nbsp;KEYNAME);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rk.Close();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;root.Close();<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">注册文件</span><span style="color: #008000"><br />
</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RegTXT();<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">catch</span><span style="color: #000000">{<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}<br />
<br />
[System.Runtime.InteropServices.ComUnregisterFunctionAttribute()]<br />
</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;UnregisterServer(String&nbsp;str1)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">try</span><span style="color: #000000"><br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">注销动态库</span><span style="color: #008000"><br />
</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RegistryKey&nbsp;root;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RegistryKey&nbsp;rk;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;root&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Registry.LocalMachine;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rk&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;root.OpenSubKey(</span><span style="color: #800000">"</span><span style="color: #800000">Software\\Microsoft\\Windows\\CurrentVersion\\Shell&nbsp;Extensions\\Approved</span><span style="color: #800000">"</span><span style="color: #000000">,&nbsp;</span><span style="color: #0000ff">true</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rk.DeleteValue(GUID);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rk.Close();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;root.Close();<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">注销文件</span><span style="color: #008000"><br />
</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UnRegTXT();<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">catch</span><span style="color: #000000"><br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}<br />
<br />
</span><span style="color: #0000ff">private</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;RegTXT()<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;RegistryKey&nbsp;root;<br />
&nbsp;&nbsp;&nbsp;&nbsp;RegistryKey&nbsp;rk;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;root&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Registry.ClassesRoot;<br />
&nbsp;&nbsp;&nbsp;&nbsp;rk&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;root.OpenSubKey(</span><span style="color: #800000">"</span><span style="color: #800000">.txt</span><span style="color: #800000">"</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;txtclass&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">string</span><span style="color: #000000">)rk.GetValue(</span><span style="color: #800000">""</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">string</span><span style="color: #000000">.IsNullOrEmpty(txtclass))<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;txtclass&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">TXT</span><span style="color: #800000">"</span><span style="color: #000000">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rk.SetValue(</span><span style="color: #800000">""</span><span style="color: #000000">,&nbsp;txtclass);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;rk.Close();<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;rk&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;root.CreateSubKey(txtclass&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">\\shellex\\ContextMenuHandlers\\</span><span style="color: #800000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;KEYNAME);<br />
&nbsp;&nbsp;&nbsp;&nbsp;rk.SetValue(</span><span style="color: #800000">""</span><span style="color: #000000">,&nbsp;GUID);<br />
&nbsp;&nbsp;&nbsp;&nbsp;rk.Close();<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;rk&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;root.CreateSubKey(txtclass&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">\\shellex\\IconHandler</span><span style="color: #800000">"</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;rk.SetValue(</span><span style="color: #800000">""</span><span style="color: #000000">,&nbsp;GUID);<br />
&nbsp;&nbsp;&nbsp;&nbsp;rk.Close();<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;rk&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;root.CreateSubKey(txtclass&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">\\shellex\\{00021500-0000-0000-C000-000000000046}</span><span style="color: #800000">"</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;rk.SetValue(</span><span style="color: #800000">""</span><span style="color: #000000">,&nbsp;GUID);<br />
&nbsp;&nbsp;&nbsp;&nbsp;rk.Close();<br />
}<br />
<br />
</span><span style="color: #0000ff">private</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;UnRegTXT()<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;RegistryKey&nbsp;root;<br />
&nbsp;&nbsp;&nbsp;&nbsp;RegistryKey&nbsp;rk;<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;root&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;Registry.ClassesRoot;<br />
&nbsp;&nbsp;&nbsp;&nbsp;rk&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;root.OpenSubKey(</span><span style="color: #800000">"</span><span style="color: #800000">.txt</span><span style="color: #800000">"</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;rk.Close();<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;txtclass&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">string</span><span style="color: #000000">)rk.GetValue(</span><span style="color: #800000">""</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(</span><span style="color: #000000">!</span><span style="color: #0000ff">string</span><span style="color: #000000">.IsNullOrEmpty(txtclass))<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;root.DeleteSubKey(txtclass&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">\\shellex\\ContextMenuHandlers\\</span><span style="color: #800000">"</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;KEYNAME);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;root.DeleteSubKey(txtclass&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">\\shellex\\IconHandler</span><span style="color: #800000">"</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;root.DeleteSubKey(txtclass&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #800000">"</span><span style="color: #800000">\\shellex\\{00021500-0000-0000-C000-000000000046}</span><span style="color: #800000">"</span><span style="color: #000000">);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</span></span></div>
<p><br />
<font color="#ff9966" size="2"><strong>注册动态库</strong></font></p>
<p><font face="Verdana">.NET 开发的动态库有些特别，需要在 .NET SDK 中注册</font></p>
<p><font face="Verdana">regasm MyContextMenu.dll /CodeBase</font><br />
反注册则是：<font face="Verdana">regasm /unregister MyContextMenu.dll /CodeBase</font></p>
<p>&nbsp;</p>
<p>代码：<a href="http://files.cnblogs.com/lemony/MyContextMenu.rar">http://files.cnblogs.com/lemony/MyContextMenu.rar</a></p>
<p>&nbsp;</p>
<p>关于代码：代码里面还包括了图标扩展和提示扩展的代码，如果有兴趣，可自行阅读。</p>
<p>&nbsp;</p>
<p>题外话：还有相当多的关于 Shell 扩展的内容无法一一说明，如果有机会，以后会尽量补上。或大家查阅网上的&#8220;<font face="Verdana">Windows Shell扩展编程完全指南&#8221;（虽然是VC版的，但内容相当丰富）</font></p>
<p>&nbsp;</p>
  <img src="http://www.cnblogs.com/lemony/aggbug/1279588.html?type=1" width="1" height="1" alt=""/><p>评论: 8　<a href="http://www.cnblogs.com/lemony/archive/2008/08/29/1279588.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/lemony/archive/2008/08/29/1279588.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56845/" target="_blank">奇虎新注资两家知名软件公司 投资项目达10笔</a><span style="color:gray">(2010-02-10 15:14)</span><br/>· <a href="http://news.cnblogs.com/n/56844/" target="_blank">网友对Google的9大期待</a><span style="color:gray">(2010-02-10 15:07)</span><br/>· <a href="http://news.cnblogs.com/n/56843/" target="_blank">分析称Google Buzz有十大特点：将改变搜索</a><span style="color:gray">(2010-02-10 15:06)</span><br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>.NET 异常处理</title><link>http://www.cnblogs.com/lemony/archive/2008/07/22/1248625.html</link><dc:creator>柠檬的</dc:creator><author>柠檬的</author><pubDate>Tue, 22 Jul 2008 04:50:00 GMT</pubDate><guid>http://www.cnblogs.com/lemony/archive/2008/07/22/1248625.html</guid><description><![CDATA[<p>阅读: 1111 评论: 3 作者: <a href="http://www.cnblogs.com/lemony/" target="_blank">柠檬的</a> 发表于 2008-07-22 12:50 <a href="http://www.cnblogs.com/lemony/archive/2008/07/22/1248625.html" target="_blank">原文链接</a></p><p>&nbsp;<span style="color: red">(好久没写过技术文章了，之前遭受了严重的打击，曾经沮丧不已；现已慢慢恢复过来^_^，因此不能荒废了自己的技术。)</span></p>
<p>&nbsp;</p>
<h2><span style="font-family: 黑体; mso-ascii-font-family: Arial">没有不出错的软件</span></h2>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">从不出错的软件从某种程度上讲是不可能的！</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和普通人的观念相反，创造可信赖的，健壮的软件并不是一件不可能的事情。大部分的商业软件，在长时间可以无重大故障的工作，但它们并非没有任何的错误，只是拥有低出错率，你可以迅速理解出错原因然后快速搞定它，并且，它不会因为外部错误而毁坏数据。软件中有错误是可以原谅的，甚至是可以预料到的；不可原谅的是您无法解决一个复发的错误，仅仅是因为您没用足够的信息。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">另外，如果希望成功避免发生错误，就必须要求开发人员正确对待错误。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<h3 style="text-indent: 21pt"><span style="font-size: 14pt; line-height: 173%; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">做好最坏的打算</span><span lang="EN-US" style="font-size: 14pt; line-height: 173%"><o:p></o:p></span></h3>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所有代码的书写，你应该认为，它是会发生错误的。如果太过于相信自己，往往会导致错误没有被处理，因此也就无法或者非常困难得去获得错误的详细信息。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><o:p>&nbsp;</o:p></span></p>
<h3 style="text-indent: 21pt"><span style="font-size: 14pt; line-height: 173%; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">不要相信外部数据</span><span lang="EN-US" style="font-size: 14pt; line-height: 173%"><o:p></o:p></span></h3>
<p class="MsoNormal" style="text-indent: 24pt"><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">外部数据是不可相信的。不管这些数据是来自寄存器、数据库、硬盘、</span><span lang="EN-US" style="font-size: 12pt">socket</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、文件或者是键盘，它们都必须被检查，只有这样你才可以去使用它们。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 24pt"><span lang="EN-US" style="font-size: 12pt"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt"><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">唯一可信赖的外部设施是：显示器、鼠标和键盘。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<h3 style="text-indent: 21pt"><span style="font-size: 14pt; line-height: 173%; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">不要理所当然</span><span lang="EN-US" style="font-size: 14pt; line-height: 173%"><o:p></o:p></span></h3>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">举个例子，你打开一个</span><span lang="EN-US" style="font-size: 12pt">TXT</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文件并修改后，希望原地保存，因此往往理所当然地认为，能打开即能保存。然而，该文件可能是只读的，又或者所在驱动器只读，甚至磁盘空间不够。如果你理所当然，那程序也就理所当然地出错了。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><o:p>&nbsp;</o:p></span></p>
<h2><span style="font-family: 黑体; mso-ascii-font-family: Arial">合理使用</span><span lang="EN-US">.NET</span><span style="font-family: 黑体; mso-ascii-font-family: Arial">异常处理机制</span></h2>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">当你摆正观念以后，就可以使用</span><span lang="EN-US" style="font-size: 12pt">.NET</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">完善的异常处理机制，来抒写安全的代码。事实上，并非掌握了</span><span lang="EN-US" style="font-size: 12pt">try{}catch{}</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">语法后，就能抒写安全的代码。其中非常多需要注意的事项。什么时候</span><span lang="EN-US" style="font-size: 12pt">try</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">？怎么</span><span lang="EN-US" style="font-size: 12pt">try</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">？怎么</span><span lang="EN-US" style="font-size: 12pt">catch</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，都是可以商酌的。我这里介绍的仅仅是比较好的方法。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<h3 style="text-indent: 21pt"><span style="font-size: 14pt; line-height: 173%; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">不要抛出</span><span lang="EN-US" style="font-size: 14pt; line-height: 173%">new Exception()<o:p></o:p></span></h3>
<p class="MsoNormal" style="text-indent: 21pt"><span lang="EN-US" style="font-size: 12pt">Exception</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是一个非常大的类，如果没有</span><span lang="EN-US" style="font-size: 12pt">side-effect(</span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">副作用）</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，很难去捕获。引用你自己的异常类，但是使它继承自</span><span lang="EN-US" style="font-size: 12pt">AppliationException</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。通过这种方法，你可以设计一个专门的异常捕获程序去捕获框架抛出的异常，同时设计另一个异常捕获程序来处理自己抛出的异常。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><o:p>&nbsp;</o:p></span></p>
<h3 style="text-indent: 21pt"><span style="font-size: 14pt; line-height: 173%; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">每个线程要有单独的</span><span lang="EN-US" style="font-size: 14pt; line-height: 173%">catch (Exception ex)</span><span style="font-size: 14pt; line-height: 173%; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">语句</span><span lang="EN-US" style="font-size: 14pt; line-height: 173%"><o:p></o:p></span></h3>
<p class="MsoNormal" style="text-indent: 24pt"><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在你的应用程序中，普通的异常处理应该被集中解决。每个线程需要一个单独的</span><span lang="EN-US" style="font-size: 12pt">try/catch</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">模块，否则，你将会丢失异常导致非常难处理的问题的出现。当一个应用程序启动若干线程去做一些后台处理时，通常你需要创建一个用来存储处理结果的类。不要忘记添加用来存储可能发生的异常的区域，否则在主线程中你将无法与之通信。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<h3 style="text-indent: 21pt"><span style="font-size: 14pt; line-height: 173%; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">要记录</span><span lang="EN-US" style="font-size: 14pt; line-height: 173%">Exception</span><span style="font-size: 14pt; line-height: 173%; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的全部信息</span><span lang="EN-US" style="font-size: 14pt; line-height: 173%"><o:p></o:p></span></h3>
<p class="MsoNormal" style="text-indent: 24pt"><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在捕获错误以后，应该记录的是</span><span lang="EN-US" style="font-size: 12pt">Exception.ToString()</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，而不仅是</span><span lang="EN-US" style="font-size: 12pt">Exception.Message</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</span><span lang="EN-US" style="font-size: 12pt">Exception.ToString()</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">将会给你一个堆栈跟踪内部的异常和信息。通常，这个信息是及其珍贵的，如果你仅记录</span><span lang="EN-US" style="font-size: 12pt">Exception.Message</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，你将会仅仅获得一些没用的信息。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<h3 style="text-indent: 21pt"><span style="font-size: 14pt; line-height: 173%; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">要有清理代码</span><span lang="EN-US" style="font-size: 14pt; line-height: 173%"><o:p></o:p></span></h3>
<p class="MsoNormal" style="text-indent: 24pt"><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">不要忽略的一件事是</span><span lang="EN-US" style="font-size: 12pt">try/finally </span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">模块如何使你的代码变得更加可读与健壮，这是处理代码的巨大作用所在。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 24pt"><span lang="EN-US" style="font-size: 12pt"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="text-indent: 24pt"><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">举个例子，假设你需要从一个临时文件中阅读一些临时信息，然后以字符串的形式返回它。不管发生什么，你都必须删除这一文件。这样的返回处理功能需要</span><span lang="EN-US" style="font-size: 12pt">try/finally</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">模块来完成。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 24pt"><span lang="EN-US" style="font-size: 12pt; font-family: 'Courier New'"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="margin-left: 21pt; text-align: left; mso-para-margin-left: 2.0gd; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; color: blue; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes">try<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 21pt; text-align: left; mso-para-margin-left: 2.0gd; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes">{<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 21pt; text-align: left; mso-para-margin-left: 2.0gd; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: blue">string</span> fileContents;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 21pt; text-align: left; mso-para-margin-left: 2.0gd; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: blue">using</span> (StreamReader sr = <span style="color: blue">new</span> StreamReader(FileName))<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 21pt; text-align: left; mso-para-margin-left: 2.0gd; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 21pt; text-align: left; mso-para-margin-left: 2.0gd; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>fileContents = sr.ReadToEnd();<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 21pt; text-align: left; mso-para-margin-left: 2.0gd; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 21pt; text-align: left; mso-para-margin-left: 2.0gd; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>File.Delete(FileName);<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 21pt; text-align: left; mso-para-margin-left: 2.0gd; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: blue">return</span> fileContents;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 21pt; text-align: left; mso-para-margin-left: 2.0gd; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes">}<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 21pt; text-align: left; mso-para-margin-left: 2.0gd; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; color: blue; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes">catch</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"> (<span style="color: #2b91af">Exception</span> ex)<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 21pt; text-align: left; mso-para-margin-left: 2.0gd; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes">{<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 21pt; text-align: left; mso-para-margin-left: 2.0gd; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: green">//</span></span><span style="font-size: 10pt; color: green; font-family: 'YaHei Consolas Hybrid','sans-serif'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">错误处理</span><span lang="EN-US" style="font-size: 10pt; color: green; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 21pt; text-align: left; mso-para-margin-left: 2.0gd; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes">}<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 21pt; text-align: left; mso-para-margin-left: 2.0gd; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; color: blue; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes">finally<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 21pt; text-align: left; mso-para-margin-left: 2.0gd; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes">{<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 10.5pt; text-align: left; mso-para-margin-left: 1.0gd; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>File.Delete(FileName);<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 10.5pt; text-indent: 10pt; text-align: left; mso-para-margin-left: 1.0gd; mso-layout-grid-align: none; mso-char-indent-count: 1.0" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes">}<o:p></o:p></span></p>
<h3 style="text-indent: 21pt"><span style="font-size: 14pt; line-height: 173%; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">经常使用</span><span lang="EN-US" style="font-size: 14pt; line-height: 173%">using<o:p></o:p></span></h3>
<p class="MsoNormal" style="margin-left: 10.5pt; text-indent: 12pt; text-align: left; mso-para-margin-left: 1.0gd; mso-layout-grid-align: none; mso-char-indent-count: 1.0" align="left"><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">仅仅在一个对象上调用</span><span lang="EN-US" style="font-size: 12pt">Dispose()</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">函数是远远不够的。关键字</span><span lang="EN-US" style="font-size: 12pt">using</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">将会阻止资源泄漏即使在有异常出现的地方。从上面的例子我们也可以看到这个好处。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<h3 style="text-indent: 21pt"><span style="font-size: 14pt; line-height: 173%; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">当再次抛出异常时不要清空堆栈追踪</span><span lang="EN-US" style="font-size: 14pt; line-height: 173%"><o:p></o:p></span></h3>
<p class="MsoNormal" style="text-indent: 21pt; text-align: left; mso-layout-grid-align: none" align="left"><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">堆栈追踪是一个异常携带的最有用的信息之一。经常，我们需要在</span><span lang="EN-US" style="font-size: 12pt">catch</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">模块中，放入一些异常处理代码（如，回滚一个事务）然后再抛出异常。但很多人会犯下以下的错误：</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue">try<o:p></o:p></span></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green">// </span></span><span style="font-size: 10pt; color: green; font-family: 'YaHei Consolas Hybrid','sans-serif'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">一些代码</span><span lang="EN-US" style="font-size: 10pt; color: green; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue">catch</span> (<span style="color: #2b91af">Exception</span> ex)<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green">// </span></span><span style="font-size: 10pt; color: green; font-family: 'YaHei Consolas Hybrid','sans-serif'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">写日志</span><span lang="EN-US" style="font-size: 10pt; color: green; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue">throw</span> ex;<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt; text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>}<br style="mso-special-character: line-break" />
<br style="mso-special-character: line-break" />
<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt; text-align: left; mso-layout-grid-align: none" align="left"><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">为什么这个是错误的呢？因为，当你检查堆栈跟踪时，异常将会运行到&#8220;</span><span lang="EN-US" style="font-size: 12pt; font-family: 'Courier New'">throw ex</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">&#8221;这一行，隐藏了真实的出错位置。你可以试一下。</span><span lang="EN-US" style="font-size: 12pt; font-family: 'Courier New'"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue">try<o:p></o:p></span></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;</span><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green">//&#8230;<o:p></o:p></span></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue">catch</span> (<span style="color: #2b91af">Exception</span> ex)<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green">//&#8230;<o:p></o:p></span></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue">throw</span>;<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt; text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt; text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt; text-align: left; mso-layout-grid-align: none" align="left"><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">观察以上代码什么改变了呢？取代了这个将会抛出新异常同时清空堆栈追踪的</span><span lang="EN-US" style="font-size: 12pt">&#8220;throw ex</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Courier New'">；</span><span lang="EN-US" style="font-size: 12pt">&#8221;</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">语句，我们使用了简单的</span><span lang="EN-US" style="font-size: 12pt">&#8220;throw</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Courier New'">；</span><span lang="EN-US" style="font-size: 12pt">&#8221;</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">语句。如果你没有指定这个异常，</span><span lang="EN-US" style="font-size: 12pt">throw</span><span lang="EN-US" style="font-size: 12pt; font-family: 'Courier New'"> </span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">声明将会仅仅再次抛出</span><span lang="EN-US" style="font-size: 12pt">catch</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">声明捕获的异常。这将会保证你的堆栈追踪完整无缺，但是依然允许你在</span><span lang="EN-US" style="font-size: 12pt">catch</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">模块中放入代码。</span><span lang="EN-US" style="font-size: 12pt; font-family: 'Courier New'"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><o:p>&nbsp;</o:p></span></p>
<h2><span style="font-family: 黑体; mso-ascii-font-family: Arial">全局错误捕获</span></h2>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 12pt; font-family: 'Courier New'"><span style="mso-tab-count: 1">&nbsp;&nbsp; </span></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">尽管你已经在极大部分的代码里面加入</span><span lang="EN-US" style="font-size: 12pt">try{}catch{}</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">错误捕获语句，但依然无法肯定你的代码不会有未捕获的错误。允许未捕获错误的发生，会直接让程序非法操作，并且无法获取该错误的详细信息。</span><span lang="EN-US" style="font-size: 12pt; font-family: 'Courier New'"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 12pt; font-family: 'Courier New'"><span style="mso-tab-count: 1">&nbsp;&nbsp; </span><o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 12pt; font-family: 'Courier New'"><span style="mso-tab-count: 1">&nbsp;&nbsp; </span></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">全</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">局错误</span><span lang="EN-US" style="font-size: 12pt">Application.ThreadException</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的捕获能</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">帮你解决这个问题。首先，我们先建立一个用户错误处理类：</span><span lang="EN-US" style="font-size: 12pt; font-family: 'Courier New'"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 12pt; font-family: 'Courier New'"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;summary&gt;<o:p></o:p></span></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: gray">///</span><span style="color: green"> </span></span><span style="font-size: 10pt; color: green; font-family: 'YaHei Consolas Hybrid','sans-serif'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">用户错误处理类</span><span lang="EN-US" style="font-size: 10pt; color: green; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/summary&gt;<o:p></o:p></span></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: blue">public</span> <span style="color: blue">static</span> <span style="color: blue">class</span> <span style="color: #2b91af">UserException<o:p></o:p></span></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;summary&gt;<o:p></o:p></span></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: gray">///</span><span style="color: green"> </span></span><span style="font-size: 10pt; color: green; font-family: 'YaHei Consolas Hybrid','sans-serif'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">全局未捕获错误处理函数</span><span lang="EN-US" style="font-size: 10pt; color: green; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/summary&gt;<o:p></o:p></span></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue">public</span> <span style="color: blue">static</span> <span style="color: blue">void</span> ThreadException(<span style="color: blue">object</span> sender, <o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>System.Threading.<span style="color: #2b91af">ThreadExceptionEventArgs</span> e)<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #2b91af">Exception</span> ex = e.Exception;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 21pt; text-align: left; mso-para-margin-left: 2.0gd; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; color: green; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>//</span><span style="font-size: 10pt; color: green; font-family: 'YaHei Consolas Hybrid','sans-serif'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">写日志</span><span lang="EN-US" style="font-size: 10pt; color: green; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #2b91af">Application</span>.Exit();<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;summary&gt;<o:p></o:p></span></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: gray">///</span><span style="color: green"> </span></span><span style="font-size: 10pt; color: green; font-family: 'YaHei Consolas Hybrid','sans-serif'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">全局错误处理函数</span><span lang="EN-US" style="font-size: 10pt; color: green; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/summary&gt;<o:p></o:p></span></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue">public</span> <span style="color: blue">static</span> <span style="color: blue">void</span> DoException(<span style="color: #2b91af">Exception</span> ex)<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 21pt; text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp; </span><span style="color: green">//</span></span><span style="font-size: 10pt; color: green; font-family: 'YaHei Consolas Hybrid','sans-serif'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">写日志</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt; text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes">}<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt"><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">然后在应用程序</span><span lang="EN-US" style="font-size: 12pt">Program</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类中，添加事件委托：</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt"><span lang="EN-US" style="font-size: 12pt"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt; text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; color: green; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes">//</span><span style="font-size: 10pt; color: green; font-family: 'YaHei Consolas Hybrid','sans-serif'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">委托错误处理事件</span><span lang="EN-US" style="font-size: 10pt; color: green; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt; text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; color: #2b91af; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes">Application</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes">.ThreadException += <span style="color: blue">new</span> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 21pt; text-indent: 21pt; text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes">System.Threading.<span style="color: #2b91af">ThreadExceptionEventHandler</span>(<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 42pt; text-indent: 21pt; text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; color: #2b91af; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes">UserException</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes">.ThreadException);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt"><span lang="EN-US" style="font-size: 12pt"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt"><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">事实上，错误捕获以后，应用程序应该关闭，而不应该继续运行。但是添加全局错误捕获以后，可以记录下未知错误的详细信息，甚至做更多的事情，例如：错误发送。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt"><span lang="EN-US" style="font-size: 12pt"><o:p>&nbsp;</o:p></span></p>
<h2><span style="font-family: 黑体; mso-ascii-font-family: Arial">应用程序域级别的错误捕获</span></h2>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">事实上，</span><span lang="EN-US" style="font-size: 12pt">Application.ThreadException</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">不是万能的，最重要的一点，它不能捕获线程级的错误。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这里介绍另外一种错误捕获</span><span lang="EN-US" style="font-size: 12pt">AppDomain. UnhandledException</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方法，它是基于应用程序域（一种边界，它由公共语言运行库围绕同一应用程序范围内创建的对象建立。应用程序域有助于将在一个应用程序中创建的对象与在其他应用程序中创建的对象隔离，以使运行时行为可以预知。在一个单独的进程中可以存在多个应用程序域。）级别的。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">然而必须告诉你的是，这个方法并不建议用于捕获线程级的错误。理由有很多，其中一个是，此方法捕获错误后，程序必须退出，因此无法实现某些中断线程而主进程继续允许的需求。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">同样我们需要建立一个应用程序错误处理类：</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 12pt; font-family: 'Courier New'"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;summary&gt;<o:p></o:p></span></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: gray">///</span><span style="color: green"> </span></span><span style="font-size: 10pt; color: green; font-family: 'YaHei Consolas Hybrid','sans-serif'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">应用程序错误处理类</span><span lang="EN-US" style="font-size: 10pt; color: green; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/summary&gt;<o:p></o:p></span></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: blue">public</span> <span style="color: blue">static</span> <span style="color: blue">class</span> <span style="color: #2b91af">AppException<o:p></o:p></span></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;summary&gt;<o:p></o:p></span></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: gray">///</span><span style="color: green"> </span></span><span style="font-size: 10pt; color: green; font-family: 'YaHei Consolas Hybrid','sans-serif'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">整个应用程序域中未捕获错误处理函数</span><span lang="EN-US" style="font-size: 10pt; color: green; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/summary&gt;<o:p></o:p></span></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue">public</span> <span style="color: blue">static</span> <span style="color: blue">void</span> DomainUnhandledException(<span style="color: blue">object</span> sender, <span style="color: #2b91af">UnhandledExceptionEventArgs</span> args)<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #2b91af">Exception</span> ex = (<span style="color: #2b91af">Exception</span>)args.ExceptionObject;<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green">//</span></span><span style="font-size: 10pt; color: green; font-family: 'YaHei Consolas Hybrid','sans-serif'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">应用程序必须关闭，只能提前写写日志了</span><span lang="EN-US" style="font-size: 10pt; color: green; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #2b91af">Application</span>.Exit();<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #2b91af">Environment</span>.Exit(0);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 19.5pt"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes">}<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 19.5pt"><span lang="EN-US" style="font-family: 'Courier New'"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt"><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">然后在应用程序</span><span lang="EN-US" style="font-size: 12pt">Program</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类中，添加事件委托：</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt"><span lang="EN-US" style="font-size: 12pt"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt; text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; color: green; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes">//</span><span style="font-size: 10pt; color: green; font-family: 'YaHei Consolas Hybrid','sans-serif'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">委托错误处理事件</span><span lang="EN-US" style="font-size: 10pt; color: green; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt; text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; color: #2b91af; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes">AppDomain</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes">.CurrentDomain.UnhandledException += <span style="color: blue">new</span> <o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt; text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; color: #2b91af; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </span>UnhandledExceptionEventHandler</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes">(<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 42pt; text-indent: 21pt; text-align: left; mso-para-margin-left: 4.0gd; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; color: #2b91af; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes">AppException</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes">.DomainUnhandledException);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt"><span lang="EN-US" style="font-size: 12pt"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt; mso-char-indent-count: 1.75"><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">必须记住的是，捕获应用程序域的错误以后，程序必须用语句关闭，否则程序依然会发生恐怖非法操作。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt; mso-char-indent-count: 1.75"><span lang="EN-US" style="font-size: 12pt"><o:p>&nbsp;</o:p></span></p>
<h2><span style="font-family: 黑体; mso-ascii-font-family: Arial">线程级的错误捕获</span></h2>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">你会发现，开了多线程的程序，发生错误的几率会大大增加。但是有时候，并不能因为某个线程发生了错误，而必须终止进程。另外，线程中</span><span lang="EN-US" style="font-size: 12pt">try&#8230;catch</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">以后，如果和主进程交互，都是个困难的问题。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt; mso-char-indent-count: 1.75"><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">不管出于怎样的考虑，都建议把每个线程中捕获的错误，放到一个专门的类中去处理。如果需要与主进程交互，这个类还应该有委托函数，把处理交给主进程。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;summary&gt;<o:p></o:p></span></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: gray">///</span><span style="color: green"> </span></span><span style="font-size: 10pt; color: green; font-family: 'YaHei Consolas Hybrid','sans-serif'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">线程错误处理类</span><span lang="EN-US" style="font-size: 10pt; color: green; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/summary&gt;<o:p></o:p></span></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: blue">public</span> <span style="color: blue">class</span> <span style="color: #2b91af">WorkerThreadException<o:p></o:p></span></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue">public</span> WorkerThreadException()<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue">public</span> WorkerThreadException(<span style="color: #2b91af">Exception</span> ex)<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue">new</span> <span style="color: #2b91af">WorkerThreadExceptionHandlerDelegate</span>(<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>WorkerThreadExceptionHandler).BeginInvoke(<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>ex, <span style="color: blue">null</span>, <span style="color: blue">null</span>);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;summary&gt;<o:p></o:p></span></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: gray">///</span><span style="color: green"> </span></span><span style="font-size: 10pt; color: green; font-family: 'YaHei Consolas Hybrid','sans-serif'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">工作线程错误捕获委托</span><span lang="EN-US" style="font-size: 10pt; color: green; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/summary&gt;<o:p></o:p></span></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue">public</span> <span style="color: blue">delegate</span> <span style="color: blue">void</span> <span style="color: #2b91af">WorkerThreadExceptionHandlerDelegate</span>(<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 42pt; text-indent: 21pt; text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; color: #2b91af; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes">Exception</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"> ex);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;summary&gt;<o:p></o:p></span></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: gray">///</span><span style="color: green"> </span></span><span style="font-size: 10pt; color: green; font-family: 'YaHei Consolas Hybrid','sans-serif'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">工作线程错误捕获处理函数</span><span lang="EN-US" style="font-size: 10pt; color: green; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">&lt;/summary&gt;<o:p></o:p></span></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue">public</span> <span style="color: blue">void</span> WorkerThreadExceptionHandler(<span style="color: #2b91af">Exception</span> ex)<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #2b91af">AppException</span>.UnhandledException(<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 63pt; text-indent: 21pt; text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; color: blue; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes">this</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes">, <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 63pt; text-indent: 21pt; text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; color: blue; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes">new</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"> System.Threading.<span style="color: #2b91af">ThreadExceptionEventArgs</span>(ex));<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes">}<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">可以看到，该类把捕获到的错误，引发到</span><span lang="EN-US" style="font-size: 12pt">Application.ThreadException</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中，统一处理。当然，你可以做更多的事情。下面，我们创建一个线程：</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: blue">private</span> <span style="color: blue">void</span> button_Click(<span style="color: blue">object</span> sender, <span style="color: #2b91af">EventArgs</span> e)<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green">//</span></span><span style="font-size: 10pt; color: green; font-family: 'YaHei Consolas Hybrid','sans-serif'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">使用独立线程引发错误</span><span lang="EN-US" style="font-size: 10pt; color: green; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #2b91af">Thread</span> thread = <span style="color: blue">new</span> <span style="color: #2b91af">Thread</span>(<span style="color: blue">new</span> <span style="color: #2b91af">ThreadStart</span>(TestError));<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>thread.Start();<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="color: blue">private</span> <span style="color: blue">void</span> TestError()<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue">try<o:p></o:p></span></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-tab-count: 3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: green">//</span></span><span style="font-size: 10pt; color: green; font-family: 'YaHei Consolas Hybrid','sans-serif'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-font-kerning: 0pt; mso-no-proof: yes">除以零</span><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue">int</span> i = 0;<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>i = 4 / i;<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue">catch</span> (<span style="color: #2b91af">Exception</span> ex)<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;</span>{<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: blue">new</span> <span style="color: #2b91af">WorkerThreadException</span>(ex);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: left; mso-layout-grid-align: none" align="left"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt"><span lang="EN-US" style="font-size: 10pt; font-family: 'Courier New'; mso-fareast-font-family: 'YaHei Consolas Hybrid'; mso-font-kerning: 0pt; mso-no-proof: yes">}<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt"><span lang="EN-US" style="font-size: 12pt; font-family: 'Courier New'"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">可以看到，线程中</span><span lang="EN-US" style="font-size: 12pt">catch</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">到错误后，创建了</span><span lang="EN-US" style="font-size: 12pt">WorkerThreadException</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类，由该类统一处理，而不是在线程中抒写重复的代码。无论从代码、还是交互角度来看，都建议这样做。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><o:p>&nbsp;</o:p></span></p>
<h2><span style="font-family: 黑体; mso-ascii-font-family: Arial">最后</span></h2>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">此文并没有介绍调试技巧，然而预防胜于补漏，合理利用</span><span lang="EN-US" style="font-size: 12pt">.NET</span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的异常处理机制，就能很好的捕获到错误及其信息，减少调试的时间。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt"><span style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">最后想说明的是，发生错误并不可怕；可怕的是，错误重复发生，而你却对它一无所知。</span><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></p>
   <img src="http://www.cnblogs.com/lemony/aggbug/1248625.html?type=1" width="1" height="1" alt=""/><p>评论: 3　<a href="http://www.cnblogs.com/lemony/archive/2008/07/22/1248625.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/lemony/archive/2008/07/22/1248625.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56845/" target="_blank">奇虎新注资两家知名软件公司 投资项目达10笔</a><span style="color:gray">(2010-02-10 15:14)</span><br/>· <a href="http://news.cnblogs.com/n/56844/" target="_blank">网友对Google的9大期待</a><span style="color:gray">(2010-02-10 15:07)</span><br/>· <a href="http://news.cnblogs.com/n/56843/" target="_blank">分析称Google Buzz有十大特点：将改变搜索</a><span style="color:gray">(2010-02-10 15:06)</span><br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>WebBrowser控件使用详解</title><link>http://www.cnblogs.com/lemony/archive/2007/11/04/948886.html</link><dc:creator>柠檬的</dc:creator><author>柠檬的</author><pubDate>Sun, 04 Nov 2007 06:15:00 GMT</pubDate><guid>http://www.cnblogs.com/lemony/archive/2007/11/04/948886.html</guid><description><![CDATA[<p>阅读: 5892 评论: 2 作者: <a href="http://www.cnblogs.com/lemony/" target="_blank">柠檬的</a> 发表于 2007-11-04 14:15 <a href="http://www.cnblogs.com/lemony/archive/2007/11/04/948886.html" target="_blank">原文链接</a></p><table cellspacing="0" cellpadding="2" width="610" border="1">
    <tbody>
        <tr>
            <td width="100">
            <div align="center">方法</div>
            </td>
            <td>
            <div align="center">说明</div>
            </td>
        </tr>
        <tr>
            <td width="100">　<strong><font face="Verdana, Arial, Helvetica, sans-serif">GoBack</font></strong> </td>
            <td>
            <div>相当于<strong><font face="Verdana, Arial, Helvetica, sans-serif">IE</font></strong>的&#8220;<strong>后退</strong>&#8221;按钮，使你在当前历史列表中后退一项 </div>
            </td>
        </tr>
        <tr>
            <td width="100">　<font face="Verdana, Arial, Helvetica, sans-serif"><strong>GoForward</strong></font> </td>
            <td>相当于<strong><font face="Verdana,        Arial, Helvetica, sans-serif">IE</font></strong>的&#8220;<strong>前进</strong>&#8221;按钮，使你在当前历史列表中前进一项 </td>
        </tr>
        <tr>
            <td width="100">　<font face="Verdana, Arial, Helvetica, sans-serif"><strong>GoHome</strong></font> </td>
            <td>相当于<strong><font face="Verdana, Arial, Helvetica, sans-serif">IE</font></strong>的&#8220;<strong>主页</strong>&#8221;按钮，连接用户默认的主页 </td>
        </tr>
        <tr>
            <td width="100">　<font face="Verdana, Arial, Helvetica, sans-serif"><strong>GoSearch</strong></font> </td>
            <td>相当于<strong><font face="Verdana, Arial, Helvetica, sans-serif">IE</font></strong>的&#8220;<strong>搜索</strong>&#8221;按钮，连接用户默认的搜索页面 </td>
        </tr>
        <tr>
            <td width="100">　<font face="Verdana, Arial, Helvetica, sans-serif"><strong>Navigate</strong></font> </td>
            <td>连接到指定的<strong><font face="Verdana, Arial, Helvetica, sans-serif">URL</font></strong> </td>
        </tr>
        <tr>
            <td width="100">　<font face="Verdana, Arial, Helvetica, sans-serif"><strong>Refresh</strong></font> </td>
            <td>刷新当前页面</td>
        </tr>
        <tr>
            <td valign="top" width="100">　<strong><font face="Verdana, Arial, Helvetica, sans-serif">Refresh2</font></strong> </td>
            <td>
            <div>同上，只是可以指定刷新级别，所指定的刷新级别的值来自<strong><font face="Verdana, Arial, Helvetica, sans-serif">RefreshConstants</font></strong>枚举表， <br />
            该表定义在<strong><font face="Verdana, Arial, Helvetica, sans-serif">ExDisp.h</font></strong>中，可以指定的不同值如下： <br />
            <strong><font face="Verdana, Arial, Helvetica, sans-serif">REFRESH_NORMAL</font></strong> 执行简单的刷新，不将<font face="Verdana, Arial, Helvetica, sans-serif">HTTP pragma: no-cache</font>头发送给服务器 <br />
            <font face="Verdana, Arial, Helvetica, sans-serif"><strong>REFRESH_IFEXPIRED</strong></font> 只有在网页过期后才进行简单的刷新 <br />
            <font face="Verdana, Arial, Helvetica, sans-serif"><strong>REFRESH_CONTINUE</strong></font> 仅作内部使用。在<strong><font face="Verdana, Arial, Helvetica, sans-serif">MSDN</font></strong>里写着<strong><font face="Verdana, Arial, Helvetica, sans-serif">DO NOT USE!</font> 请勿使用 <br />
            <font face="Verdana, Arial, Helvetica, sans-serif">REFRESH_COMPLETELY</font></strong> 将包含<font face="Verdana, Arial, Helvetica, sans-serif">pragma: no-cache</font>头的请求发送到服务器 </div>
            </td>
        </tr>
        <tr>
            <td width="100">　<font face="Verdana, Arial, Helvetica, sans-serif"><strong>Stop</strong></font> </td>
            <td>相当于<strong><font face="Verdana, Arial, Helvetica, sans-serif">IE</font></strong>的&#8220;<strong>停止</strong>&#8221;按钮，停止当前页面及其内容的载入 </td>
        </tr>
    </tbody>
</table>
<table cellspacing="0" cellpadding="2" width="610" border="1">
    <tbody>
        <tr>
            <td width="140">
            <div align="center">属性</div>
            </td>
            <td>
            <div align="center">说明</div>
            </td>
        </tr>
        <tr>
            <td valign="top" width="140">　<strong><font face="Geneva, Arial, Helvetica, san-serif">Application</font></strong> </td>
            <td>如果该对象有效，则返回掌管<strong><font face="Verdana, Arial, Helvetica, sans-serif">WebBrowser</font></strong>控件的应用程序实现的自动化对象(<strong><font face="Verdana, Arial, Helvetica, sans-serif">IDispatch</font></strong>)。如果在宿主对象中自动化对象无效，这个程序将返回<strong><font face="Verdana, Arial, Helvetica, sans-serif">WebBrowser</font></strong> <br />
            控件的自动化对象 </td>
        </tr>
        <tr>
            <td width="140">　<font face="Verdana, Arial, Helvetica, sans-serif"><strong>Parent</strong></font> </td>
            <td>返回<strong><font face="Verdana, Arial, Helvetica, sans-serif">WebBrowser</font></strong>控件的父自动化对象，通常是一个容器，例如是宿主或<strong><font face="Verdana, Arial, Helvetica, sans-serif">IE</font></strong>窗口 </td>
        </tr>
        <tr>
            <td width="140">　<font face="Verdana, Arial, Helvetica, sans-serif"><strong>Container</strong></font> </td>
            <td>返回<strong><font face="Verdana, Arial, Helvetica, sans-serif">WebBrowser</font></strong>控件容器的自动化对象。通常该值与<strong><font face="Verdana, Arial, Helvetica, sans-serif">Parent</font></strong>属性返回的值相同 </td>
        </tr>
        <tr>
            <td width="140">　<strong><font face="Verdana, Arial, Helvetica, sans-serif">Document</font></strong> </td>
            <td>为活动的文档返回自动化对象。如果<font face="Verdana, Arial, Helvetica, sans-serif"><strong>HTML</strong></font>当前正被显示在<strong><font face="Verdana, Arial, Helvetica, sans-serif">WebBrowser</font></strong>中，则 <br />
            <font face="Verdana, Arial, Helvetica, sans-serif"><strong>Document</strong></font>属性提供对<strong><font face="Verdana, Arial, Helvetica, sans-serif">DHTML Object Model</font></strong>的访问途径 </td>
        </tr>
        <tr>
            <td width="140">　<strong><font face="Verdana, Arial,        Helvetica, sans-serif">TopLevelContainer</font></strong> </td>
            <td>
            <div>返回一个<strong><font face="Verdana, Arial, Helvetica, sans-serif">Boolean</font></strong>值，表明<strong><font face="Verdana, Arial, Helvetica, sans-serif">IE</font></strong>是否是<strong><font face="Verdana, Arial, Helvetica, sans-serif">WebBrowser</font></strong>控件顶层容器，是就返回<font face="Verdana, Arial, Helvetica, sans-serif"><strong>true</strong></font> </div>
            </td>
        </tr>
        <tr>
            <td valign="top" width="140">　<strong><font face="Verdana, Arial, Helvetica, sans-serif">Type</font></strong> </td>
            <td>返回已被<strong><font face="Verdana, Arial, Helvetica, sans-serif">WebBrowser</font></strong>控件加载的对象的类型。例如：如果加载<strong><font face="Verdana, Arial, Helvetica, sans-serif">.doc</font></strong>文件，就会返 <br />
            回<font face="Verdana, Arial, Helvetica, sans-serif"><strong>Microsoft Word Document</strong></font> </td>
        </tr>
        <tr>
            <td width="140">　<font face="Verdana, Arial, Helvetica, sans-serif"><strong>Left</strong></font> </td>
            <td>返回或设置<strong><font face="Verdana, Arial, Helvetica, sans-serif">WebBrowser</font></strong>控件窗口的内部左边与容器窗口左边的距离 </td>
        </tr>
        <tr>
            <td width="140">　<strong><font face="Verdana, Arial, Helvetica, sans-serif">Top</font></strong> </td>
            <td>返回或设置<strong><font face="Verdana, Arial, Helvetica, sans-serif">WebBrowser</font></strong>控件窗口的内部左边与容器窗口顶边的距离 </td>
        </tr>
        <tr>
            <td width="140">　<strong><font face="Verdana, Arial, Helvetica, sans-serif">Width</font></strong> </td>
            <td>返回或设置<strong><font face="Verdana, Arial, Helvetica, sans-serif">WebBrowser</font></strong>窗口的宽度，以像素为单位 </td>
        </tr>
        <tr>
            <td width="140">　<strong><font face="Verdana, Arial, Helvetica, sans-serif">Height</font></strong> </td>
            <td>返回或设置<strong><font face="Verdana, Arial, Helvetica,        sans-serif">WebBrowser</font></strong>窗口的高度，以像素为单位 </td>
        </tr>
        <tr>
            <td width="140">　<strong><font face="Verdana, Arial, Helvetica, sans-serif">LocationName</font></strong> </td>
            <td>返回一个字符串，该字符串包含着<strong><font face="Verdana, Arial, Helvetica, sans-serif">WebBrowser</font></strong>当前显示的资源的名称，如果资源 <br />
            是网页就是网页的标题；如果是文件或文件夹，就是文件或文件夹的名称 </td>
        </tr>
        <tr>
            <td width="140">　<strong><font face="Verdana, Arial, Helvetica, sans-serif">LocationURL</font></strong> </td>
            <td>返回<strong><font face="Verdana, Arial, Helvetica, sans-serif">WebBrowser</font></strong>当前正在显示的资源的<font face="Verdana, Arial, Helvetica, sans-serif"><strong>URL</strong></font> </td>
        </tr>
        <tr>
            <td valign="top" width="140">　<strong><font face="Verdana, Arial, Helvetica, sans-serif">Busy</font></strong> </td>
            <td>返回一个<strong><font face="Verdana, Arial, Helvetica,        sans-serif">Boolean</font></strong>值，说明<strong><font face="Verdana, Arial, Helvetica, sans-serif">WebBrowser</font></strong>当前是否正在加载<strong><font face="Verdana, Arial, Helvetica, sans-serif">URL</font></strong>，如果返回<strong><font face="Verdana, Arial, Helvetica, sans-serif">true</font></strong> <br />
            就可以使用<strong><font face="Verdana, Arial, Helvetica, sans-serif">stop</font></strong>方法来撤销正在执行的访问操作 </td>
        </tr>
    </tbody>
</table>
<font color="#f70968">WebBrowser 的事件 </font>
<table cellspacing="2" cellpadding="3" width="95%" align="center">
    <tbody>
        <tr bgcolor="#cccccc">
            <th bgcolor="#cccccc"><font color="#f70968"><strong><em><font face="Verdana, Arial, Helvetica, sans-serif"><font size="2">Private Events</font></font></em></strong> </font></th>
            <th><font color="#f70968"><font face="Verdana, Arial, Helvetica, sans-serif"><strong><font size="2">Description</font></strong></font> </font></th>
        </tr>
        <tr bgcolor="#eeeeee">
            <td valign="top"><strong><em><font face="Verdana, Arial, Helvetica, sans-serif" color="#f70968">BeforeNavigate2 </font></em></strong></td>
            <td valign="top"><font color="#f70968">导航发生前激发，刷新时不激发</font></td>
        </tr>
        <tr bgcolor="#eeeeee">
            <td valign="top"><strong><em><font face="Verdana, Arial, Helvetica, sans-serif" color="#f70968">CommandStateChange </font></em></strong></td>
            <td valign="top"><font color="#f70968">当命令的激活状态改变时激发。它表明何时激活或关闭<strong><font face="Verdana, Arial, Helvetica, sans-serif">Back</font></strong>和<font face="Verdana, Arial, Helvetica, sans-serif"><strong>Forward</strong></font> <br />
            菜单项或按钮 </font></td>
        </tr>
        <tr bgcolor="#eeeeee">
            <td valign="top"><strong><em><font face="Verdana, Arial, Helvetica, sans-serif" color="#f70968">DocumentComplete </font></em></strong></td>
            <td valign="top"><font color="#f70968">当整个文档完成是激发，刷新页面不激发</font></td>
        </tr>
        <tr bgcolor="#eeeeee">
            <td valign="top"><strong><em><font face="Verdana, Arial,Helvetica, sans-serif" color="#f70968">DownloadBegin </font></em></strong></td>
            <td valign="top"><font color="#f70968">当某项下载操作已经开始后激发，刷新也可激发此事件</font></td>
        </tr>
        <tr bgcolor="#eeeeee">
            <td valign="top"><font color="#f70968"><strong><em><font face="Verdana, Arial, Helvetica, sans-serif">DownloadComplete</font></em></strong> </font></td>
            <td valign="top"><font color="#f70968">当某项下载操作已经完成后激发，刷新也可激发此事件</font></td>
        </tr>
        <tr bgcolor="#eeeeee">
            <td valign="top"><strong><em><font face="Verdana, Arial, Helvetica, sans-serif" color="#f70968">NavigateComplete2 </font></em></strong></td>
            <td valign="top"><font color="#f70968">导航完成后激发，刷新时不激发</font></td>
        </tr>
        <tr bgcolor="#eeeeee">
            <td valign="top"><strong><em><font face="Verdana, Arial, Helvetica, sans-serif" color="#f70968">NewWindow2 </font></em></strong></td>
            <td valign="top"><font color="#f70968">在创建新窗口以前激发</font></td>
        </tr>
        <tr bgcolor="#eeeeee">
            <td valign="top"><strong><em><font face="Verdana, Arial, Helvetica, sans-serif" color="#f70968">OnFullScreen </font></em></strong></td>
            <td valign="top"><font color="#f70968">当<strong><font face="Verdana, Arial, Helvetica, sans-serif">FullScreen</font></strong>属性改变时激发。该事件采用<strong><font face="Verdana, Arial, Helvetica, sans-serif">VARIENT_BOOL</font></strong>的一个输 <br />
            入参数来指示<strong><font face="Verdana, Arial, Helvetica, sans-serif">IE</font></strong>是全屏显示方式(<strong><font face="Verdana, Arial, Helvetica, sans-serif">VARIENT_TRUE</font></strong>)还是普通显示方式(<strong><font face="Verdana, Arial, Helvetica, sans-serif">VARIENT_FALSE</font></strong>) </font></td>
        </tr>
        <tr bgcolor="#eeeeee">
            <td valign="top"><strong><em><font face="Verdana, Arial, Helvetica, sans-serif" color="#f70968">OnMenuBar </font></em></strong></td>
            <td valign="top"><font color="#f70968">改变<strong><font face="Verdana, Arial, Helvetica, sans-serif">MenuBar</font></strong>的属性时激发，标示参数是<strong><font face="Verdana, Arial, Helvetica, sans-serif">VARIENT_BOOL</font></strong>类型的。 <br />
            <strong><font face="Verdana, Arial, Helvetica, sans-serif">VARIANT_TRUE</font></strong>是可见，<strong><font face="Verdana, Arial, Helvetica, sans-serif">VARIANT_ FALSE</font></strong>是隐藏 </font></td>
        </tr>
        <tr bgcolor="#eeeeee">
            <td valign="top"><strong><em><font face="Verdana, Arial, Helvetica, sans-serif" color="#f70968">OnQuit </font></em></strong></td>
            <td valign="top"><font color="#f70968">无论是用户关闭浏览器还是开发者调用<strong><font face="Verdana, Arial, Helvetica, sans-serif">Quit</font></strong>方法，当<strong><font face="Verdana, Arial, Helvetica, sans-serif">IE</font></strong>退出时就会激发 </font></td>
        </tr>
        <tr bgcolor="#eeeeee">
            <td valign="top"><strong><em><font face="Verdana, Arial, Helvetica, sans-serif" color="#f70968">OnStatusBar </font></em></strong></td>
            <td valign="top"><font color="#f70968">与<strong><font face="Verdana, Arial, Helvetica,sans-serif">OnMenuBar</font></strong>调用方法相同，标示状态栏是否可见。 </font></td>
        </tr>
        <tr bgcolor="#eeeeee">
            <td valign="top"><strong><em><font face="Verdana, Arial, Helvetica, sans-serif" color="#f70968">OnToolBar </font></em></strong></td>
            <td valign="top"><font color="#f70968">调用方法同上，标示工具栏是否可见。</font></td>
        </tr>
        <tr bgcolor="#eeeeee">
            <td valign="top"><strong><em><font face="Verdana, Arial, Helvetica, sans-serif" color="#f70968">OnVisible </font></em></strong></td>
            <td valign="top"><font color="#f70968">控制窗口的可见或隐藏，也使用一个<strong><font face="Verdana, Arial, Helvetica, sans-serif">VARIENT_BOOL</font></strong>类型的参数 </font></td>
        </tr>
        <tr bgcolor="#eeeeee">
            <td valign="top"><strong><em><font face="Verdana, Arial, Helvetica, sans-serif" color="#f70968">StatusTextChange </font></em></strong></td>
            <td valign="top"><font color="#f70968">如果要改变状态栏中的文字，这个事件就会被激发，但它并不理会程序是否有状态栏</font></td>
        </tr>
        <tr bgcolor="#eeeeee">
            <td valign="top"><strong><em><font face="Verdana, Arial, Helvetica, sans-serif" color="#f70968">TitleChange </font></em></strong></td>
            <td valign="top">
            <p><font color="#f70968">Title有效或改变时激发</font></p>
            </td>
        </tr>
    </tbody>
</table>
<p>&nbsp;</p>
<p><font size="5">一些使用技巧</font></p>
<p><font color="#ff00ff">1.禁止右键</font></p>
<p>看到很多关于WebBrowser控件禁止右键的提问，回复的方法很多，其中有提到使用微软提供的Webbrowser扩展COM服务器对象（WBCustomizer.dll），但是该方法在我们想使用Webbrowser编辑网页（Webbrowser1.Document.execCommand "editMode"）的时候有很多弊端，比如不能显示选中的文本等。另有些方法也就不用一一列举了。<br />
这儿我想提到的是关于MSHTML.HTMLDocument<br />
引用Microsoft HTML OBject Library<br />
Rem ＃窗体代码＃<br />
Dim WithEvents M_Dom As MSHTML.HTMLDocument<br />
Private Function M_Dom_oncontextmenu() As Boolean<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; M_Dom_oncontextmenu = False<br />
End Function<br />
Private Sub Webbrowser1_DownloadComplete()<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set M_Dom = Webbrowser1.Document<br />
End Sub<br />
Rem 好了，右键菜单没有了<br />
<br />
=========================================================================</p>
<p><font color="#ff00ff">2、控件调用和获得收藏夹里面</font><br />
基本上用 specialfolder(6 ) 就可以得到收藏夹的路径, 然后你可以用dir去循环读入每个目录,然后dir里面的file, file的名字就是你要的收藏的名字, 路径可以自己根据从上面得到的路径去得到.<br />
如果你不用dir也可以用vb的dir控件.<br />
Private Type SHITEMID<br />
&nbsp;&nbsp;&nbsp;&nbsp; cb As Long<br />
&nbsp;&nbsp;&nbsp;&nbsp; abID As Byte<br />
End Type<br />
Public Type ITEMIDLIST<br />
&nbsp;&nbsp;&nbsp;&nbsp; mkid As SHITEMID<br />
End Type<br />
Public Function SpecialFolder(ByRef CSIDL As Long) As String<br />
&nbsp;&nbsp;&nbsp;&nbsp; 'locate the favorites folder<br />
&nbsp;&nbsp;&nbsp;&nbsp; Dim R As Long<br />
&nbsp;&nbsp;&nbsp;&nbsp; Dim sPath As String<br />
&nbsp;&nbsp;&nbsp;&nbsp; Dim IDL As ITEMIDLIST<br />
&nbsp;&nbsp;&nbsp;&nbsp; Const NOERROR = 0<br />
&nbsp;&nbsp;&nbsp;&nbsp; Const MAX_LENGTH = 260<br />
&nbsp;&nbsp;&nbsp;&nbsp; R = SHGetSpecialFolderLocation(MDIMain.hwnd, CSIDL, IDL)<br />
&nbsp;&nbsp;&nbsp;&nbsp; If R = NOERROR Then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sPath = Space$(MAX_LENGTH)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; R = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal sPath)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If R Then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SpecialFolder = Left$(sPath, InStr(sPath, vbNullChar) - 1)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br />
&nbsp;&nbsp;&nbsp;&nbsp; End If<br />
End Function<br />
==============================================＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝<br />
<font color="#ff00ff">3、全屏</font></p>
<p>是的,webbrowser本生是一个控件, 你要它全屏,就是要它所在的窗体全屏, 可以用setwindowlong取消窗体的 title, 用Call ShowWindow(FindWindow("Shell_traywnd", ""), 0) 隐藏tray,就是下边那个包含开始那一行. 用Call ShowWindow(FindWindow("Shell_traywnd", ""), 9) 恢复. 够详细了吧.<br />
然后在form1.windowstate = 2 就可以了.<br />
================================================================================<br />
<font color="#ff00ff">4、选择网页上的内容。</font><br />
Private Sub Command1_Click()<br />
'请先选中一些内容<br />
Me.WebBrowser1.ExecWB OLECMDID_COPY, OLECMDEXECOPT_DODEFAULT<br />
MsgBox Clipboard.GetText<br />
End Sub<br />
==========================================================================<br />
<font color="#ff00ff">5、用IE来下载文件</font><br />
Private Declare Function DoFileDownload Lib "shdocvw.dll" (ByVal lpszFile As String) As Long</p>
<p>Private Sub Command1_Click()<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp; Dim sDownload As String<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp; sDownload = StrConv(Text1.Text, vbUnicode)<br />
&nbsp;&nbsp;&nbsp; Call DoFileDownload(sDownload)<br />
&nbsp;&nbsp;<br />
End Sub<br />
Private Sub Form_Load()<br />
Text1.Text = "<a href="http://www.chat.ru/~softdaily/fo-ag162.zip">http://www.chat.ru/~softdaily/fo-ag162.zip</a>"<br />
Form1.Caption = "Audiograbber 1.62 Full"<br />
Text2.Text = "<a href="http://www6.50megs.com/audiograbber/demos/cr-ag161.zip">http://www6.50megs.com/audiograbber/demos/cr-ag161.zip</a>"<br />
End Sub</p>
<p>=======================================================================<br />
<font color="#ff00ff">6、我要动态加载和删除WebBrowser控件应该怎么做</font>？<br />
Private Sub Command1_Click()<br />
&nbsp;&nbsp;&nbsp; Form1.Controls.Add "shell.explorer.2", "NewWeb", Form1<br />
&nbsp;&nbsp;&nbsp;&nbsp; With Form1!NewWeb<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .Visible = True<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .Width = 10000<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .Height = 10000<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .Left = 0<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .Top = 0<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .Navigate2 "<a href="http://www.csdn.net/">www.csdn.net</a>"<br />
&nbsp;&nbsp;&nbsp;&nbsp; End With<br />
End Sub<br />
Private Sub Command2_Click()<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Controls.Remove Form1!newweb<br />
End Sub<br />
Form1.Controls.Add "shell.explorer.2", newweb(newweb.Count), Form1<br />
&nbsp;&nbsp;&nbsp;&nbsp; With Form1!newweb(newweb.Count)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .Visible = True<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .Width = 1000<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .Height = 1000<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .Left = newweb(newweb.Count - 1).Left + newweb(newweb.Count - 1).Width<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .Top = 0<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '.Navigate2 "<a href="http://www.csdn.net/">www.csdn.net</a>"<br />
&nbsp;&nbsp;&nbsp;&nbsp; End With<br />
为什么他说我<br />
Form1.Controls.Add "shell.explorer.2", newweb(newweb.Count), Form1<br />
这一行错误13 类型不匹配？<br />
ps：我在form中已经有了一个newweb(0)控件<br />
<br />
先为一个WebBrowser<br />
Dim i As Integer<br />
Private Sub AddWeb_Click()<br />
&nbsp;&nbsp;&nbsp;&nbsp; For i = 1 To 10<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Load NewWeb(i)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NewWeb(i).Top = i * 100<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NewWeb(i).Left = i * 100<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NewWeb(i).Visible = True<br />
&nbsp;&nbsp;&nbsp;&nbsp; Next i<br />
End Sub<br />
Private Sub DelWeb_Click()<br />
&nbsp;&nbsp;&nbsp;&nbsp; For i = 1 To 10<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Unload NewWeb(i)<br />
&nbsp;&nbsp;&nbsp;&nbsp; Next i<br />
End Sub<br />
=======================================================</p>
<p><font color="#ff00ff">7、一个把页面保存为MHT(即MHTML)文件</font></p>
<p>将 pcwak(书剑狂生[MS MVP]) 大侠提供的资料贴出来，以供大家参考：<br />
我终于找到一个把页面保存为MHT(即MHTML)文件的方法了!<br />
首先，在工程中必须要引用一个库：<br />
Library CDO<br />
D:\WINNT\System32\cdosys.dll<br />
Microsoft CDO for Windows 2000 Library<br />
其次，需要Stream对应的接口的支持，如果你一时找不到就使用支持这个的较新的ADO就行了，如<br />
Library ADODB<br />
D:\Program Files\Common Files\system\ado\msado15.dll<br />
Microsoft ActiveX Data Objects 2.5 Library<br />
代码如下，十分简单(同时由于流的特点，显示在实际应用中没必要象本例中那样把文件保存到磁盘上就可直接转换为字符串或字节数组什么的处理的。<br />
另，对于Microsoft CDO for Windows 2000 Library这个库，在WIN98中要怎么使用还没试过，感兴趣的朋友可以试试并跟帖，以丰富完善其内容：)<br />
Private Sub Command1_Click()<br />
' Reference to Microsoft ActiveX Data Objects 2.5 Library<br />
' Reference to Microsoft CDO for Windows 2000 Library<br />
Dim iMsg As New CDO.Message<br />
Dim iConf As New CDO.Configuration<br />
Dim objStream As ADODB.Stream<br />
With iMsg<br />
.CreateMHTMLBody "<a href="http://www.163.com/">http://www.163.com/</a>";, , _<br />
"domain\username", _<br />
"password"<br />
Set objStream = .GetStream<br />
Call objStream.SaveToFile("f:\test.mht", adSaveCreateOverWrite)<br />
End With<br />
End Sub<br />
2、</p>
<p>'首先加入对ADODB和CDO（Microsoft CDO for Windows 2000 Library，对应文件名为CDOSYS.dll）的引用<br />
Private Sub Command1_Click()<br />
&nbsp;&nbsp;&nbsp;&nbsp; Dim message As New CDO.message<br />
&nbsp;&nbsp;&nbsp;&nbsp; Dim Outstream As ADODB.Stream<br />
&nbsp;&nbsp;&nbsp;&nbsp; On Error GoTo myerr1<br />
&nbsp;&nbsp;&nbsp;&nbsp; Call message.CreateMHTMLBody("<a href="http://www.csdn.net/">http://www.csdn.net</a>", CDO.CdoMHTMLFlags.cdoSuppressNone, "", "")<br />
&nbsp;&nbsp;&nbsp;&nbsp; Set Outstream = message.GetStream<br />
&nbsp;&nbsp;&nbsp;&nbsp; Call Outstream.SaveToFile("c:\test.mht", ADODB.SaveOptionsEnum.adSaveCreateOverWrite)<br />
&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "完成"<br />
&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub<br />
myerr1:<br />
&nbsp;&nbsp;&nbsp;&nbsp; Set message = Nothing<br />
&nbsp;&nbsp;&nbsp;&nbsp; Set Outstream = Nothing<br />
End Sub<br />
=======================================================<br />
</p>
<p><font color="#ff00ff">8、在WebBrowser控件调用收藏夹和在收藏夹里添加收藏</font><br />
Option Explicit<br />
Private Sub Command1_Click()<br />
&nbsp;&nbsp;&nbsp;&nbsp; Dim ObjSUH As New ShellUIHelper<br />
&nbsp;&nbsp;&nbsp;&nbsp; ObjSUH.AddFavorite "<a href="http://www.csdn.net/">http://www.csdn.net</a>", "CSDN"<br />
&nbsp;&nbsp;&nbsp;&nbsp; Set ObjSUH = Nothing<br />
End Sub<br />
=========================================================</p>
<p><font color="#ff00ff">9、如何使网页不出现滚动条：</font><br />
Private Sub mnuScroll1_Click()<br />
'注意：必须在网页完全显示之后才可以运行<br />
&nbsp;&nbsp;&nbsp;&nbsp; WebBrowser1.Document.body.Scroll = "no" '不显示滚动条的办法<br />
End Sub<br />
Private Sub mnuScroll2_Click()<br />
'注意：必须在网页完全显示之后才可以运行<br />
&nbsp;&nbsp;&nbsp;&nbsp; WebBrowser1.Document.body.Scroll = "Auto" '显示滚动条的办法<br />
End Sub<br />
==============================================================<br />
<font color="#ff00ff">10、如何获得网页中被选中部分的HTML：</font><br />
Private Sub Command1_Click()<br />
&nbsp;&nbsp;&nbsp;&nbsp; Dim objSelection<br />
&nbsp;&nbsp;&nbsp;&nbsp; Dim objTxtRange<br />
&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp; Set objSelection = WebBrowser1.Document.selection<br />
&nbsp;&nbsp;&nbsp;&nbsp; If Not (objSelection Is Nothing) Then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set objTxtRange = objSelection.createRange<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Not (objTxtRange Is Nothing) Then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Debug.Print objTxtRange.htmlText<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set objTxtRange = Nothing<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set objSelection = Nothing<br />
&nbsp;&nbsp;&nbsp;&nbsp; End If<br />
End Sub<br />
Private Sub Form_Load()<br />
&nbsp;&nbsp;&nbsp;&nbsp; WebBrowser1.Navigate "<a href="http://www.applevb.com/">http://www.applevb.com</a>"<br />
End Sub</p>
<font color="#ff00ff">11、页面滚动：</font><br />
<br />
Private Sub Command2_Click()<br />
&nbsp;&nbsp;&nbsp;&nbsp; WebBrowser1.Document.parentwindow.scrollby 0, 30<br />
End Sub<br />
Private Sub Form_Load()<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WebBrowser1.Navigate "http://www.applevb.com"<br />
End Sub<br />
<br />
点击Command2就可以使当前页面向下滚动30像素<br />
<font color="#ff00ff"><br />
12、判断页面是否可以前进后退</font><br />
<br />
Private Sub Command1_Click()<br />
&nbsp;&nbsp;&nbsp;&nbsp; WebBrowser1.GoForward<br />
End Sub<br />
<br />
Private Sub Command2_Click()<br />
&nbsp;&nbsp;&nbsp;&nbsp; WebBrowser1.GoBack<br />
End Sub<br />
<br />
Private Sub Form_Load()<br />
&nbsp;&nbsp;&nbsp;&nbsp; WebBrowser1.Navigate "http://www.applevb.com"<br />
End Sub<br />
<br />
Private Sub WebBrowser1_CommandStateChange(ByVal Command As Long, ByVal Enable As Boolean)<br />
&nbsp;&nbsp;&nbsp;&nbsp; If (Command = CSC_NAVIGATEBACK) Then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Command2.Enabled = Enable<br />
&nbsp;&nbsp;&nbsp;&nbsp; End If<br />
&nbsp;&nbsp;&nbsp;&nbsp; If (Command = CSC_NAVIGATEFORWARD) Then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Command1.Enabled = Enable<br />
&nbsp;&nbsp;&nbsp;&nbsp; End If<br />
End Sub<br />
上面的command1是前进按钮，command2是后退按钮
 <img src="http://www.cnblogs.com/lemony/aggbug/948886.html?type=1" width="1" height="1" alt=""/><p>评论: 2　<a href="http://www.cnblogs.com/lemony/archive/2007/11/04/948886.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/lemony/archive/2007/11/04/948886.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56845/" target="_blank">奇虎新注资两家知名软件公司 投资项目达10笔</a><span style="color:gray">(2010-02-10 15:14)</span><br/>· <a href="http://news.cnblogs.com/n/56844/" target="_blank">网友对Google的9大期待</a><span style="color:gray">(2010-02-10 15:07)</span><br/>· <a href="http://news.cnblogs.com/n/56843/" target="_blank">分析称Google Buzz有十大特点：将改变搜索</a><span style="color:gray">(2010-02-10 15:06)</span><br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>SQL连接查询深度探险</title><link>http://www.cnblogs.com/lemony/archive/2007/11/01/945280.html</link><dc:creator>柠檬的</dc:creator><author>柠檬的</author><pubDate>Thu, 01 Nov 2007 02:13:00 GMT</pubDate><guid>http://www.cnblogs.com/lemony/archive/2007/11/01/945280.html</guid><description><![CDATA[<p>阅读: 933 评论: 0 作者: <a href="http://www.cnblogs.com/lemony/" target="_blank">柠檬的</a> 发表于 2007-11-01 10:13 <a href="http://www.cnblogs.com/lemony/archive/2007/11/01/945280.html" target="_blank">原文链接</a></p><div style="margin: 0cm 0cm 0pt"><span style="font-family: 宋体"  Roman? New ?Times Times><font color="#ff0000" size="3"><strong>测试环境：</strong></font></span></div>
<div style="margin: 0cm 0cm 0pt"><font color="#000000" size="3">Windows XP Profession</font></div>
<div style="margin: 0cm 0cm 0pt"><font size="3"><font color="#000000">MySQL 5.0.45</font></font></div>
<div style="margin: 0cm 0cm 0pt"><font color="#000000" size="3">Oracle 9i</font></div>
<div style="margin: 0cm 0cm 0pt"><font color="#000000" size="3">DB2 UDB 9.1</font></div>
<div style="margin: 0cm 0cm 0pt"><font size="3"><font color="#000000"><span style="font-family: 宋体"  Roman? New ?Times Times>测试的</span>SQL<span style="font-family: 宋体"  Roman? New ?Times Times>脚本如下：此脚本适合</span>MySQL<span style="font-family: 宋体"  Roman? New ?Times Times>、</span>DB2<span style="font-family: 宋体"  Roman? New ?Times Times>，如果要在</span>Oracle<span style="font-family: 宋体"  Roman? New ?Times Times>上执行，需要做个替换</span>BIGINT<span style="font-family: wingdings"  New ?Times Times Wingdings??>&#224;</span></span>INTEGER<span style="font-family: 宋体"  Roman? New ?Times Times>、</span>VARCHAR<span style="font-family: wingdings"  New ?Times Times Wingdings??>&#224;</span></span>VARCHAR2<span style="font-family: 宋体"  Roman? New ?Times Times>。</span></font></font></div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>CREATE</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>TABLE</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> CUSTOMERS (</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>&nbsp;&nbsp; ID <strong>BIGINT</strong> </span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>NOT</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>NULL</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>&nbsp;&nbsp; NAME <strong>VARCHAR</strong>(</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>15</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>) </span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>NOT</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>NULL</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>&nbsp;&nbsp; AGE <strong>INT</strong>,</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>&nbsp;&nbsp; </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>PRIMARY</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>KEY</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> (ID)</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>)</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>CREATE</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>TABLE</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> ORDERS (</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>&nbsp;&nbsp; ID <strong>BIGINT</strong> </span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>NOT</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>NULL</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>&nbsp;&nbsp; ORDER_NUMBER <strong>VARCHAR</strong>(</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>15</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>) </span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>NOT</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>NULL</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>&nbsp;&nbsp; PRICE <strong>DOUBLE</strong> <strong>PRECISION</strong>,</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>&nbsp;&nbsp; CUSTOMER_ID <strong>BIGINT</strong>,</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>&nbsp;&nbsp; </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>PRIMARY</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>KEY</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> (ID)</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>)</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>COMMIT</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>/*</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>ALTER</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>TABLE</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> ORDERS </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>ADD</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>INDEX</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> FK_CUSTOMER (CUSTOMER_ID), </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>ADD</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>CONSTRAINT</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> FK_CUSTOMER </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>FOREIGN</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>KEY</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> (CUSTOMER_ID) </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>REFERENCES</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> CUSTOMERS (ID)</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>*/</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: fuchsia; font-family: "  0pt Courier>INSERT</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>INTO</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> CUSTOMERS(ID,NAME,AGE) </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>VALUES</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>(</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>1</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><span style="font-size: 10pt; color: red; font-family: "  0pt Courier>'TOM'</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>21</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>)</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: fuchsia; font-family: "  0pt Courier>INSERT</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>INTO</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> CUSTOMERS(ID,NAME,AGE) </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>VALUES</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>(</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>2</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><span style="font-size: 10pt; color: red; font-family: "  0pt Courier>'MIKE'</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>24</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>)</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: fuchsia; font-family: "  0pt Courier>INSERT</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>INTO</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> CUSTOMERS(ID,NAME,AGE) </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>VALUES</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>(</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>3</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><span style="font-size: 10pt; color: red; font-family: "  0pt Courier>'JACK'</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>30</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>)</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: fuchsia; font-family: "  0pt Courier>INSERT</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>INTO</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> CUSTOMERS(ID,NAME,AGE) </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>VALUES</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>(</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>4</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><span style="font-size: 10pt; color: red; font-family: "  0pt Courier>'LINDA'</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>25</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>)</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: fuchsia; font-family: "  0pt Courier>INSERT</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>INTO</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> CUSTOMERS(ID,NAME,AGE) </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>VALUES</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>(</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>5</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><span style="font-size: 10pt; color: red; font-family: "  0pt Courier>'TOM'</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>NULL</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>)</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>COMMIT</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: fuchsia; font-family: "  0pt Courier>INSERT</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>INTO</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> ORDERS(ID,ORDER_NUMBER,PRICE,CUSTOMER_ID) </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>VALUES</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>(</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>1</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><span style="font-size: 10pt; color: red; font-family: "  0pt Courier>'TOM_ORDER001'</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>100</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>1</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>)</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: fuchsia; font-family: "  0pt Courier>INSERT</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>INTO</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> ORDERS(ID,ORDER_NUMBER,PRICE,CUSTOMER_ID) </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>VALUES</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>(</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>2</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><span style="font-size: 10pt; color: red; font-family: "  0pt Courier>'TOM_ORDER002'</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>200</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>1</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>)</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: fuchsia; font-family: "  0pt Courier>INSERT</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>INTO</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> ORDERS(ID,ORDER_NUMBER,PRICE,CUSTOMER_ID) </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>VALUES</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>(</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>3</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><span style="font-size: 10pt; color: red; font-family: "  0pt Courier>'TOM_ORDER003'</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>300</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>1</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>)</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: fuchsia; font-family: "  0pt Courier>INSERT</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>INTO</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> ORDERS(ID,ORDER_NUMBER,PRICE,CUSTOMER_ID) </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>VALUES</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>(</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>4</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><span style="font-size: 10pt; color: red; font-family: "  0pt Courier>'MIKE_ORDER001'</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>100</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>2</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>)</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: fuchsia; font-family: "  0pt Courier>INSERT</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>INTO</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> ORDERS(ID,ORDER_NUMBER,PRICE,CUSTOMER_ID) </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>VALUES</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>(</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>5</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><span style="font-size: 10pt; color: red; font-family: "  0pt Courier>'JACK_ORDER001'</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>200</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>3</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>)</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: fuchsia; font-family: "  0pt Courier>INSERT</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>INTO</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> ORDERS(ID,ORDER_NUMBER,PRICE,CUSTOMER_ID) </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>VALUES</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>(</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>6</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><span style="font-size: 10pt; color: red; font-family: "  0pt Courier>'LINDA_ORDER001'</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>100</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>4</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>)</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: fuchsia; font-family: "  0pt Courier>INSERT</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>INTO</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> ORDERS(ID,ORDER_NUMBER,PRICE,CUSTOMER_ID) </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>VALUES</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>(</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>7</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><span style="font-size: 10pt; color: red; font-family: "  0pt Courier>'UNKNOWNORDER'</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>200</span></strong><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>,</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>NULL</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>)</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt"><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>COMMIT</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt"><span style="font-family: 宋体"  Roman? New ?Times Times><font size="3">两表的数据如下：</font></span></div>
<div style="margin: 0cm 0cm 0pt"><font size="3">CUSTOMERS<span style="font-family: 宋体"  Roman? New ?Times Times>表数据：</span></font></div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt"><font size="3">ORDERS<span style="font-family: 宋体"  Roman? New ?Times Times>表数据</span></font></div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt">&nbsp;&nbsp;</div>
<div style="margin: 0cm 0cm 0pt 21pt; text-indent: -21pt; tab-stops: list 21.0pt"><font size="3"><font color="#ff0000"><strong>一、<span style="font-family: 宋体"  Roman? New ?Times Times>交叉连接（</span>CROSS JOIN<span style="font-family: 宋体"  Roman? New ?Times Times>）</span></strong></font></font></div>
<div style="margin: 0cm 0cm 0pt 21pt; text-indent: -21pt; tab-stops: list 21.0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>交叉连接（</span>CROSS JOIN<span style="font-family: 宋体"  Roman? New ?Times Times>）：有两种，显式的和隐式的，不带</span>ON<span style="font-family: 宋体"  Roman? New ?Times Times>子句，返回的是两表的乘积，也叫笛卡尔积。</span></font></div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: 宋体"  0pt Courier New? ? font-family: blue; color: 10pt; ?Courier?font-size:><span style="font-size: 10pt; color: blue; font-family: 宋体"  0pt Courier New? ? font-family: blue; color: 10pt; ?Courier?font-size:><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>SELECT</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> O.ID, O.ORDER_NUMBER, C.ID, C.NAME</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>FROM</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> ORDERS O , CUSTOMERS C</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>WHERE</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> O.ID</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>=</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>1</span></strong><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>语句</span>2<span style="font-family: 宋体"  Roman? New ?Times Times>：显式的交叉连接，使用</span>CROSS JOIN<span style="font-family: 宋体"  Roman? New ?Times Times>。</span></font></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>SELECT</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> O.ID,O.ORDER_NUMBER,C.ID,C.NAME</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>FROM</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> ORDERS O </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>CROSS</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>JOIN</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> CUSTOMERS C</span></div>
<div style="margin: 0cm 0cm 0pt"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>WHERE</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> O.ID</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>=</span><strong><span style="font-size: 10pt; color: maroon; font-family: "  0pt Courier>1</span></strong><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>语句</span>1<span style="font-family: 宋体"  Roman? New ?Times Times>和语句</span>2<span style="font-family: 宋体"  Roman? New ?Times Times>的结果是相同的，查询结果如下：</span></font></div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt 21pt; text-indent: -21pt; tab-stops: list 21.0pt"><font size="3"><font color="#ff0000"><strong>二、<span style="font-family: 宋体"  Roman? New ?Times Times>内连接（</span>INNER JOIN<span style="font-family: 宋体"  Roman? New ?Times Times>）</span></strong></font></font></div>
<div style="margin: 0cm 0cm 0pt 21pt; text-indent: -21pt; tab-stops: list 21.0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>内连接（</span>INNER JOIN<span style="font-family: 宋体"  Roman? New ?Times Times>）：有两种，显式的和隐式的，返回连接表中符合连接条件和查询条件的数据行。（所谓的链接表就是数据库在做查询形成的中间表）。</span></font></div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>例如：下面的语句</span>3<span style="font-family: 宋体"  Roman? New ?Times Times>和语句</span>4<span style="font-family: 宋体"  Roman? New ?Times Times>的结果是相同的。</span></font></div>
<div style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>语句</span>3<span style="font-family: 宋体"  Roman? New ?Times Times>：隐式的内连接，没有</span>INNER JOIN<span style="font-family: 宋体"  Roman? New ?Times Times>，形成的中间表为两个表的笛卡尔积。</span></font></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>SELECT</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> O.ID,O.ORDER_NUMBER,C.ID,C.NAME</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>FROM</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> CUSTOMERS C,ORDERS O</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>WHERE</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> C.ID</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>=</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>O.CUSTOMER_ID</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: black; font-family: 宋体"  0pt Courier New? ? font-family: color: 10pt; ?Courier?font-size: black;>INNER JOIN<span style="font-family: 宋体"  Roman? New ?Times Times>，形成的中间表为两个表经过</span>ON<span style="font-family: 宋体"  Roman? New ?Times Times>条件过滤后的笛卡尔积。</span></font></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>SELECT</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> O.ID,O.ORDER_NUMBER,C.ID,C.NAME</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>FROM</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> CUSTOMERS C </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>INNER</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>JOIN</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> ORDERS O </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>ON</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> C.ID</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>=</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>O.CUSTOMER_ID</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>语句</span>3<span style="font-family: 宋体"  Roman? New ?Times Times>和语句</span>4<span style="font-family: 宋体"  Roman? New ?Times Times>的查询结果：</span></font></div>
<div style="margin: 0cm 0cm 0pt 21pt; text-indent: -21pt; tab-stops: list 21.0pt"><font size="3"><img onclick='window.open("http://blog.51cto.com/viewpic.php?refimg=" + this.src)' alt="" src="http://blog.51cto.com/attachment/200708/200708201187547700625.png" border="0" /></font></div>
<div style="margin: 0cm 0cm 0pt 21pt; text-indent: -21pt; tab-stops: list 21.0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt 21pt; text-indent: -21pt; tab-stops: list 21.0pt"><font size="3"><strong><font color="#ff0000">三、<span style="font-family: 宋体"  Roman? New ?Times Times>外连接（</span>OUTER JOIN</font></strong><span style="font-family: 宋体"  Roman? New ?Times Times><strong><font color="#ff0000">）：</font></strong>外连不但返回符合连接和查询条件的数据行，还返回不符合条件的一些行。外连接分三类：左外连接（</span>LEFT OUTER JOIN<span style="font-family: 宋体"  Roman? New ?Times Times>）、右外连接（</span>RIGHT OUTER JOIN<span style="font-family: 宋体"  Roman? New ?Times Times>）和全外连接（</span>FULL OUTER JOIN<span style="font-family: 宋体"  Roman? New ?Times Times>）。</span></font></div>
<div style="margin: 0cm 0cm 0pt; text-indent: 21pt"><span style="font-family: 宋体"  Roman? New ?Times Times><font size="3">三者的共同点是都返回符合连接条件和查询条件（即：内连接）的数据行。不同点如下：</font></span></div>
<div style="margin: 0cm 0cm 0pt 21pt"><span style="font-family: 宋体"  Roman? New ?Times Times><font size="3">左外连接还返回左表中不符合连接条件单符合查询条件的数据行。</font></span></div>
<div style="margin: 0cm 0cm 0pt 21pt"><span style="font-family: 宋体"  Roman? New ?Times Times><font size="3">右外连接还返回右表中不符合连接条件单符合查询条件的数据行。</font></span></div>
<div style="margin: 0cm 0cm 0pt 21pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>全外连接还返回左表中不符合连接条件单符合查询条件的数据行，并且还返回右表中不符合连接条件单符合查询条件的数据行。全外连接实际是上左外连接和右外连接的数学合集（去掉重复），即&#8220;全外</span>=<span style="font-family: 宋体"  Roman? New ?Times Times>左外</span> UNION <span style="font-family: 宋体"  Roman? New ?Times Times>右外&#8221;。</span></font></div>
<div style="margin: 0cm 0cm 0pt 21pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>说明：左表就是在&#8220;（</span>LEFT OUTER JOIN<span style="font-family: 宋体"  Roman? New ?Times Times>）&#8221;关键字左边的表。右表当然就是右边的了。在三种类型的外连接中，</span>OUTER <span style="font-family: 宋体"  Roman? New ?Times Times>关键字是可省略的。</span></font></div>
<div style="margin: 0cm 0cm 0pt 21pt"><span style="font-family: 宋体"  Roman? New ?Times Times><font size="3">下面举例说明：</font></span></div>
<div style="margin: 0cm 0cm 0pt 21pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>语句</span>5<span style="font-family: 宋体"  Roman? New ?Times Times>：左外连接（</span>LEFT OUTER JOIN<span style="font-family: 宋体"  Roman? New ?Times Times>）</span></font></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>SELECT</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> O.ID,O.ORDER_NUMBER,O.CUSTOMER_ID,C.ID,C.NAME</span></div>
<div style="margin: 0cm 0cm 0pt"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>FROM</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> ORDERS O </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>LEFT</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>OUTER</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>JOIN</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> CUSTOMERS C </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>ON</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> C.ID</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>=</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>O.CUSTOMER_ID</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times><img onclick='window.open("http://blog.51cto.com/viewpic.php?refimg=" + this.src)' alt="" src="http://blog.51cto.com/attachment/200708/200708201187547952296.png" border="0" /></span></font></div>
<div style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>语句</span>6<span style="font-family: 宋体"  Roman? New ?Times Times>：右外连接（</span>RIGHT OUTER JOIN<span style="font-family: 宋体"  Roman? New ?Times Times>）</span></font></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>SELECT</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> O.ID,O.ORDER_NUMBER,O.CUSTOMER_ID,C.ID,C.NAME</span></div>
<div style="margin: 0cm 0cm 0pt"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>FROM</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> ORDERS O </span><span style="font-size: 10pt; color: fuchsia; font-family: "  0pt Courier>RIGHT</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>OUTER</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>JOIN</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> CUSTOMERS C </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>ON</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> C.ID</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>=</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>O.CUSTOMER_ID</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>注意：</span>WHERE<span style="font-family: 宋体"  Roman? New ?Times Times>条件放在</span>ON<span style="font-family: 宋体"  Roman? New ?Times Times>后面查询的结果是不一样的。例如：</span></font></div>
<div style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times><img onclick='window.open("http://blog.51cto.com/viewpic.php?refimg=" + this.src)' alt="" src="http://blog.51cto.com/attachment/200708/200708201187548034593.png" border="0" /></span></font></div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>语句</span>7<span style="font-family: 宋体"  Roman? New ?Times Times>：</span></font><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>WHERE</span><span style="font-size: 10pt; color: blue; font-family: 宋体"  Courier New? align="left"  left;? text-align: 0pt; 0cm ?Courier?margin:><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>SELECT</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> O.ID,O.ORDER_NUMBER,O.CUSTOMER_ID,C.ID,C.NAME</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>FROM</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> ORDERS O </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>LEFT</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>OUTER</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>JOIN</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> CUSTOMERS C </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>ON</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> C.ID</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>=</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>O.CUSTOMER_ID</span></div>
<div style="margin: 0cm 0cm 0pt"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>WHERE</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> O.ORDER_NUMBER</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>&lt;&gt;</span><span style="font-size: 10pt; color: red; font-family: "  0pt Courier>'MIKE_ORDER001'</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>语句</span>8<span style="font-family: 宋体"  Roman? New ?Times Times>：将语句</span>7<span style="font-family: 宋体"  Roman? New ?Times Times>中的</span>WHERE<span style="font-family: 宋体"  Roman? New ?Times Times>条件放到</span>ON<span style="font-family: 宋体"  Roman? New ?Times Times>后面。</span></font></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>SELECT</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> O.ID,O.ORDER_NUMBER,O.CUSTOMER_ID,C.ID,C.NAME</span></div>
<div style="margin: 0cm 0cm 0pt"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>FROM</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> ORDERS O </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>LEFT</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>OUTER</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>JOIN</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> CUSTOMERS C </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>ON</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> C.ID</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>=</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>O.CUSTOMER_ID </span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>AND</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> O.ORDER_NUMBER</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>&lt;&gt;</span><span style="font-size: 10pt; color: red; font-family: "  0pt Courier>'MIKE_ORDER001'</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times><img onclick='window.open("http://blog.51cto.com/viewpic.php?refimg=" + this.src)' alt="" src="http://blog.51cto.com/attachment/200708/200708201187548144640.png" border="0" /></span></font></div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>从语句</span>7<span style="font-family: 宋体"  Roman? New ?Times Times>和语句</span>8<span style="font-family: 宋体"  Roman? New ?Times Times>查询的结果来看，显然是不相同的，语句</span>8<span style="font-family: 宋体"  Roman? New ?Times Times>显示的结果是难以理解的。因此，推荐在写连接查询的时候，</span>ON<span style="font-family: 宋体"  Roman? New ?Times Times>后面只跟连接条件，而对中间表限制的条件都写到</span>WHERE<span style="font-family: 宋体"  Roman? New ?Times Times>子句中。</span></font></div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>语句</span>9<span style="font-family: 宋体"  Roman? New ?Times Times>：全外连接（</span>FULL OUTER JOIN<span style="font-family: 宋体"  Roman? New ?Times Times>）。</span></font></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>SELECT</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> O.ID,O.ORDER_NUMBER,O.CUSTOMER_ID,C.ID,C.NAME</span></div>
<div style="margin: 0cm 0cm 0pt"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>FROM</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> ORDERS O FULL </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>OUTER</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>JOIN</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> CUSTOMERS C </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>ON</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> C.ID</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>=</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>O.CUSTOMER_ID;</span></div>
<div style="margin: 0cm 0cm 0pt"><span style="font-size: 10pt; color: black; font-family: 宋体"  0pt Courier New? ? font-family: color: 10pt; ?Courier?font-size: black;>&nbsp;</div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt"><span style="font-size: 10pt; color: black; font-family: 宋体"  0pt Courier New? ? font-family: color: 10pt; ?Courier?font-size: black;><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>SELECT</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> O.ID,O.ORDER_NUMBER,O.CUSTOMER_ID,C.ID,C.NAME</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>FROM</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> ORDERS O </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>LEFT</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>OUTER</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>JOIN</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> CUSTOMERS C </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>ON</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> C.ID</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>=</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>O.CUSTOMER_ID</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>UNION</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>SELECT</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> O.ID,O.ORDER_NUMBER,O.CUSTOMER_ID,C.ID,C.NAME</span></div>
<div style="margin: 0cm 0cm 0pt"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>FROM</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> ORDERS O </span><span style="font-size: 10pt; color: fuchsia; font-family: "  0pt Courier>RIGHT</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>OUTER</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>JOIN</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> CUSTOMERS C </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>ON</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> C.ID</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>=</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>O.CUSTOMER_ID</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt"><span style="font-size: 10pt; color: black; font-family: 宋体"  0pt Courier New? ? font-family: color: 10pt; ?Courier?font-size: black;>&nbsp;</div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt 21pt; text-indent: -21pt; tab-stops: list 21.0pt"><font size="3"><strong><font color="#ff0000">四、<span style="font-family: 宋体"  Roman? New ?Times Times>联合连接（</span>UNION JOIN</font></strong><span style="font-family: 宋体"  Roman? New ?Times Times><strong><font color="#ff0000">）：</font></strong>这是一种很少见的连接方式。</span>Oracle<span style="font-family: 宋体"  Roman? New ?Times Times>、</span>MySQL<span style="font-family: 宋体"  Roman? New ?Times Times>均不支持，其作用是：找出全外连接和内连接之间差异的所有行。这在数据分析中排错中比较常用。也可以利用数据库的集合操作来实现此功能。</span></font></div>
<div style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>语句</span>11<span style="font-family: 宋体"  Roman? New ?Times Times>：联合查询（</span>UNION JOIN<span style="font-family: 宋体"  Roman? New ?Times Times>）例句，还没有找到能执行的</span>SQL<span style="font-family: 宋体"  Roman? New ?Times Times>环境。</span></font></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>SELECT</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> O.ID,O.ORDER_NUMBER,O.CUSTOMER_ID,C.ID,C.NAME</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>FROM</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> ORDERS O </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>UNION</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>JOIN</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> CUSTOMERS C </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>ON</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> C.ID</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>=</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>O.CUSTOMER_ID</span></div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>语句</span>12<span style="font-family: 宋体"  Roman? New ?Times Times>：语句</span>11<span style="font-family: 宋体"  Roman? New ?Times Times>在</span>DB2<span style="font-family: 宋体"  Roman? New ?Times Times>下的等价实现。还不知道</span>DB2<span style="font-family: 宋体"  Roman? New ?Times Times>是否支持语句</span>11<span style="font-family: 宋体"  Roman? New ?Times Times>呢！</span></font></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>SELECT</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> O.ID,O.ORDER_NUMBER,O.CUSTOMER_ID,C.ID,C.NAME</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>FROM</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> ORDERS O FULL </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>OUTER</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>JOIN</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> CUSTOMERS C </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>ON</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> C.ID</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>=</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>O.CUSTOMER_ID</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>EXCEPT</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>SELECT</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> O.ID,O.ORDER_NUMBER,O.CUSTOMER_ID,C.ID,C.NAME</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>FROM</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> ORDERS O </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>INNER</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>JOIN</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> CUSTOMERS C </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>ON</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> C.ID</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>=</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>O.CUSTOMER_ID</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>语句</span>13<span style="font-family: 宋体"  Roman? New ?Times Times>：语句</span>11<span style="font-family: 宋体"  Roman? New ?Times Times>在</span>Oracle<span style="font-family: 宋体"  Roman? New ?Times Times>下的等价实现。</span></font></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>SELECT</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> O.ID,O.ORDER_NUMBER,O.CUSTOMER_ID,C.ID,C.NAME</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>FROM</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> ORDERS O FULL </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>OUTER</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>JOIN</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> CUSTOMERS C </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>ON</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> C.ID</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>=</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>O.CUSTOMER_ID</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>MINUS</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>SELECT</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> O.ID,O.ORDER_NUMBER,O.CUSTOMER_ID,C.ID,C.NAME</span></div>
<div style="margin: 0cm 0cm 0pt"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>FROM</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> ORDERS O </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>INNER</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>JOIN</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> CUSTOMERS C </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>ON</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> C.ID</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>=</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>O.CUSTOMER_ID</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt"><span style="font-family: 宋体"  Roman? New ?Times Times><font size="3">查询结果如下：</font></span></div>
<div style="margin: 0cm 0cm 0pt"><font size="3"><img onclick='window.open("http://blog.51cto.com/viewpic.php?refimg=" + this.src)' alt="" src="http://blog.51cto.com/attachment/200708/200708201187548310562.png" border="0" /></font></div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt 21pt; text-indent: -21pt; tab-stops: list 21.0pt"><font size="3"><strong><font color="#ff0000">五、<span style="font-family: 宋体"  Roman? New ?Times Times>自然连接（</span>NATURAL INNER JOIN</font></strong><span style="font-family: 宋体"  Roman? New ?Times Times><strong><font color="#ff0000">）：</font></strong>说真的，这种连接查询没有存在的价值，既然是</span>SQL2<span style="font-family: 宋体"  Roman? New ?Times Times>标准中定义的，就给出个例子看看吧。自然连接无需指定连接列，</span>SQL<span style="font-family: 宋体"  Roman? New ?Times Times>会检查两个表中是否相同名称的列，且假设他们在连接条件中使用，并且在连接条件中仅包含一个连接列。不允许使用</span>ON<span style="font-family: 宋体"  Roman? New ?Times Times>语句，不允许指定显示列，显示列只能用</span>*<span style="font-family: 宋体"  Roman? New ?Times Times>表示（</span>ORACLE<span style="font-family: 宋体"  Roman? New ?Times Times>环境下测试的）。对于每种连接类型（除了交叉连接外），均可指定</span>NATURAL<span style="font-family: 宋体"  Roman? New ?Times Times>。下面给出几个例子。</span></font></div>
<div style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>语句</span>14<span style="font-family: 宋体"  Roman? New ?Times Times>：</span></font></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>SELECT</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>*</span></div>
<div style="margin: 0cm 0cm 0pt"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>FROM</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> ORDERS O </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>NATURAL</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>INNER</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>JOIN</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> CUSTOMERS C</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>语句</span>15<span style="font-family: 宋体"  Roman? New ?Times Times>：</span></font></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>SELECT</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>*</span></div>
<div style="margin: 0cm 0cm 0pt"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>FROM</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> ORDERS O </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>NATURAL</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>LEFT</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>OUTER</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>JOIN</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> CUSTOMERS C</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>语句</span>16<span style="font-family: 宋体"  Roman? New ?Times Times>：</span></font></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>SELECT</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>*</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>FROM</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> ORDERS O </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>NATURAL</span><span style="font-size: 10pt; color: fuchsia; font-family: "  0pt Courier>RIGHT</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>OUTER</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>JOIN</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> CUSTOMERS C</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>语句</span>17<span style="font-family: 宋体"  Roman? New ?Times Times>：</span></font></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>SELECT</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>*</span></div>
<div style="margin: 0cm 0cm 0pt"><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>FROM</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> ORDERS O </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>NATURAL</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> FULL </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>OUTER</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>JOIN</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> CUSTOMERS C</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt 21pt; text-indent: -21pt; tab-stops: list 21.0pt"><font size="3"><strong><font color="#ff0000">六、SQL</font></strong><span style="font-family: 宋体"  Roman? New ?Times Times><strong><font color="#ff0000">查询的基本原理：</font></strong>两种情况介绍。</span></font></div>
<div style="margin: 0cm 0cm 0pt 57pt; text-indent: -36pt; tab-stops: list 57.0pt"><font size="3">第一、</font><span style="font-weight: normal; font-size: 7pt; line-height: normal; font-style: normal; font-variant: normal"  Roman? New Times>&nbsp;&nbsp; </span><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>单表查询：根据</span>WHERE<span style="font-family: 宋体"  Roman? New ?Times Times>条件过滤表中的记录，形成中间表（这个中间表对用户是不可见的）；然后根据</span>SELECT<span style="font-family: 宋体"  Roman? New ?Times Times>的选择列选择相应的列进行返回最终结果。</span></font></div>
<div style="margin: 0cm 0cm 0pt 57pt; text-indent: -36pt; tab-stops: list 57.0pt"><font size="3">第二、</font><span style="font-weight: normal; font-size: 7pt; line-height: normal; font-style: normal; font-variant: normal"  Roman? New Times>&nbsp;&nbsp; </span><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>两表连接查询：对两表求积（笛卡尔积）并用</span>ON<span style="font-family: 宋体"  Roman? New ?Times Times>条件和连接连接类型进行过滤形成中间表；然后根据</span>WHERE<span style="font-family: 宋体"  Roman? New ?Times Times>条件过滤中间表的记录，并根据</span>SELECT<span style="font-family: 宋体"  Roman? New ?Times Times>指定的列返回查询结果。</span></font></div>
<div style="margin: 0cm 0cm 0pt 57pt; text-indent: -36pt; tab-stops: list 57.0pt"><font size="3">第三、</font><span style="font-weight: normal; font-size: 7pt; line-height: normal; font-style: normal; font-variant: normal"  Roman? New Times>&nbsp;&nbsp; </span><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>多表连接查询：先对第一个和第二个表按照两表连接做查询，然后用查询结果和第三个表做连接查询，以此类推，直到所有的表都连接上为止，最终形成一个中间的结果表，然后根据</span>WHERE<span style="font-family: 宋体"  Roman? New ?Times Times>条件过滤中间表的记录，并根据</span>SELECT<span style="font-family: 宋体"  Roman? New ?Times Times>指定的列返回查询结果。</span></font></div>
<div style="margin: 0cm 0cm 0pt 21pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>理解</span>SQL<span style="font-family: 宋体"  Roman? New ?Times Times>查询的过程是进行</span>SQL<span style="font-family: 宋体"  Roman? New ?Times Times>优化的理论依据。</span></font></div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt 21pt; text-indent: -21pt; tab-stops: list 21.0pt"><font size="3"><strong><font color="#ff0000">七、ON<span style="font-family: 宋体"  Roman? New ?Times Times>后面的条件（</span>ON<span style="font-family: 宋体"  Roman? New ?Times Times>条件）和</span>WHERE<span style="font-family: 宋体"  Roman? New ?Times Times>条件的区别：</span></font></strong></font></div>
<div style="margin: 0cm 0cm 0pt 21pt; text-indent: -21pt; tab-stops: list 21.0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt 21pt"><font size="3">ON<span style="font-family: 宋体"  Roman? New ?Times Times>条件：是过滤两个链接表笛卡尔积形成中间表的约束条件。</span></font></div>
<div style="margin: 0cm 0cm 0pt 21pt"><font size="3">WHERE<span style="font-family: 宋体"  Roman? New ?Times Times>条件：在有</span>ON<span style="font-family: 宋体"  Roman? New ?Times Times>条件的</span>SELECT<span style="font-family: 宋体"  Roman? New ?Times Times>语句中是过滤中间表的约束条件。在没有</span>ON<span style="font-family: 宋体"  Roman? New ?Times Times>的单表查询中，是限制物理表或者中间查询结果返回记录的约束。在两表或多表连接中是限制连接形成最终中间表的返回结果的约束。</span></font></div>
<div style="margin: 0cm 0cm 0pt 21pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>从这里可以看出，将</span>WHERE<span style="font-family: 宋体"  Roman? New ?Times Times>条件移入</span>ON<span style="font-family: 宋体"  Roman? New ?Times Times>后面是不恰当的。推荐的做法是：</span></font></div>
<div style="margin: 0cm 0cm 0pt 21pt"><font size="3">ON<span style="font-family: 宋体"  Roman? New ?Times Times>只进行连接操作，</span>WHERE<span style="font-family: 宋体"  Roman? New ?Times Times>只过滤中间表的记录。</span></font></div>
<div style="margin: 0cm 0cm 0pt 21pt; text-indent: -21pt; tab-stops: list 21.0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt 21pt; text-indent: -21pt; tab-stops: list 21.0pt"><font size="3"><strong><font color="#ff0000">八、<span style="font-family: 宋体"  Roman? New ?Times Times>总结</span></font></strong></font></div>
<div style="margin: 0cm 0cm 0pt 21pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>连接查询是</span>SQL<span style="font-family: 宋体"  Roman? New ?Times Times>查询的核心，连接查询的连接类型选择依据实际需求。如果选择不当，非但不能提高查询效率，反而会带来一些逻辑错误或者性能低下。下面总结一下两表连接查询选择方式的依据：</span></font></div>
<div style="margin: 0cm 0cm 0pt 21pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt 21pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt 60pt; text-indent: -18pt; tab-stops: list 60.0pt"><span Roman? New Times><font size="3">1、</font>&nbsp;</span><span style="font-family: 宋体"  Roman? New ?Times Times><font size="3">查两表关联列相等的数据用内连接。</font></span></div>
<div style="margin: 0cm 0cm 0pt 60pt; text-indent: -18pt; tab-stops: list 60.0pt"><span Roman? New Times><font size="3">2、</font>&nbsp;</span><font size="3">Col_L<span style="font-family: 宋体"  Roman? New ?Times Times>是</span>Col_R<span style="font-family: 宋体"  Roman? New ?Times Times>的子集时用右外连接。</span></font></div>
<div style="margin: 0cm 0cm 0pt 60pt; text-indent: -18pt; tab-stops: list 60.0pt"><span Roman? New Times><font size="3">3、</font>&nbsp;</span><font size="3">Col_R<span style="font-family: 宋体"  Roman? New ?Times Times>是</span>Col_L<span style="font-family: 宋体"  Roman? New ?Times Times>的子集时用左外连接。</span></font></div>
<div style="margin: 0cm 0cm 0pt 60pt; text-indent: -18pt; tab-stops: list 60.0pt"><span Roman? New Times><font size="3">4、</font>&nbsp;</span><font size="3">Col_R<span style="font-family: 宋体"  Roman? New ?Times Times>和</span>Col_L<span style="font-family: 宋体"  Roman? New ?Times Times>彼此有交集但彼此互不为子集时候用全外。</span></font></div>
<div style="margin: 0cm 0cm 0pt 60pt; text-indent: -18pt; tab-stops: list 60.0pt"><span Roman? New Times><font size="3">5、</font>&nbsp;</span><span style="font-family: 宋体"  Roman? New ?Times Times><font size="3">求差操作的时候用联合查询。</font></span></div>
<div style="margin: 0cm 0cm 0pt 21pt"><span style="font-family: 宋体"  Roman? New ?Times Times><font size="3">多个表查询的时候，这些不同的连接类型可以写到一块。例如：</font></span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>&nbsp;</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>SELECT</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> T1.C1,T2.CX,T3.CY</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>&nbsp;</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>FROM</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> TAB1 T1</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>INNER</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>JOIN</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> TAB2 T2 </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>ON</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> (T1.C1</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>=</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>T2.C2)</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>INNER</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>JOIN</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> TAB3 T3 </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>ON</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> (T1.C1</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>=</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>T2.C3)</span></div>
<div style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>LEFT</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>OUTER</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>JOIN</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> TAB4 </span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>ON</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>(T2.C2</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>=</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>T3.C3)</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt 21pt"><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>&nbsp;</span><span style="font-size: 10pt; color: blue; font-family: "  0pt Courier>WHERE</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier> T1.X </span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>&gt;</span><span style="font-size: 10pt; color: black; font-family: "  0pt Courier>T3.Y</span><span style="font-size: 10pt; color: gray; font-family: "  0pt Courier>;</span></div>
<div style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>上面这个</span>SQL<span style="font-family: 宋体"  Roman? New ?Times Times>查询是多表连接的一个示范。</span></font></div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt"><font size="3"><span style="font-family: 宋体"  Roman? New ?Times Times>----全文完。</span></font></div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
<div style="margin: 0cm 0cm 0pt"><span style="font-family: 宋体"  Roman? New ?Times Times><font size="2">说明：此测试环境的SQL脚本来自孙卫秦《精通Hibernate》一书中的客户订单模型。</font></span></div>
<div style="margin: 0cm 0cm 0pt">&nbsp;</div>
</span></span></span></span></span></span></span>
<img src="http://www.cnblogs.com/lemony/aggbug/945280.html?type=1" width="1" height="1" alt=""/><p>评论: 0　<a href="http://www.cnblogs.com/lemony/archive/2007/11/01/945280.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/lemony/archive/2007/11/01/945280.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56845/" target="_blank">奇虎新注资两家知名软件公司 投资项目达10笔</a><span style="color:gray">(2010-02-10 15:14)</span><br/>· <a href="http://news.cnblogs.com/n/56844/" target="_blank">网友对Google的9大期待</a><span style="color:gray">(2010-02-10 15:07)</span><br/>· <a href="http://news.cnblogs.com/n/56843/" target="_blank">分析称Google Buzz有十大特点：将改变搜索</a><span style="color:gray">(2010-02-10 15:06)</span><br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>悲壮的一天，记华为核心网面试经历</title><link>http://www.cnblogs.com/lemony/archive/2007/10/17/927014.html</link><dc:creator>柠檬的</dc:creator><author>柠檬的</author><pubDate>Wed, 17 Oct 2007 02:00:00 GMT</pubDate><guid>http://www.cnblogs.com/lemony/archive/2007/10/17/927014.html</guid><description><![CDATA[<p>阅读: 3849 评论: 12 作者: <a href="http://www.cnblogs.com/lemony/" target="_blank">柠檬的</a> 发表于 2007-10-17 10:00 <a href="http://www.cnblogs.com/lemony/archive/2007/10/17/927014.html" target="_blank">原文链接</a></p>&nbsp;&nbsp;&nbsp;&nbsp;10月13日，我和同事一起到华为核心网面试。那鸟部门很早就天天打电话烦我们了，不来不行啊。不过华为核心网貌似真的挺不错，搞搞3G技术，混上2年出去，以后也可以号称&#8220;牛人&#8221;一个了，嘻嘻&#8230;&#8230;。 <br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;这的确是悲壮的一天，从早上9点一直折磨到晚上7点，从笔试到五轮面试，无一不让人饱受煎熬。 <br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;笔试我才得60分，但足够我进行后面的面试。说实在，题目难度一般，但没考好有几个原因，一是准备时间太短-_-!，二是不知道只有一小时答题，结果有些题目答案都还没填上去...笔试成绩估计也会影响到对方给你的开价吧。总之早上我就以为挂了，准备收拾回家。 <br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;笔试得以勉强通过，马上进行了两轮技术面试。第一轮是总体技术面试，一般是围绕你之前工作的内容，从系统结构，系统设计，开发流程到项目控制，我都对答如流。第二轮是细节技术面试，对方先问你的工作内容，然后抓住你回答中的某一点问下去。我一不小心谈及了数据包丢失的问题，结果被问得壮烈，幸好当时看过底层通讯动态库的代码，能勉强&#8220;忽悠&#8221;他一下。实际上，对方都是很牛的人，千万别真的以为能忽悠他。 <br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;技术面试过后，就可以填招聘表了。封面上还让你选择是否愿意到国外艰苦地区工作。天啊，想卖了我啊！不过不选是不行的，只能很违心的打上勾，心里再狠狠地骂一句。 <br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;第三轮是人事面试，这轮本来比较轻松，因为只是和你聊一下天（再一次被认为不像广东人），还有检查一下你的证件：学位、毕业证、英语四级。鬼都知道我没有四级证书，所以我还&#8220;理直气壮&#8221;地说我就是没有，你们说没有也无所谓我才来面试的。哈哈，对方也只能点点头。这年头，没四级真是低人一等啊！ <br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;接下来就是重头戏了，集体面试（以前貌似没有这个环节）。如果在这一轮表现稍微差一点，估计就会遭受淘汰，真是悲惨。大致的经过是：几十人，分3次，每次14人，分A、B两组。每个人先自我介绍一把。然后给了一道题目，每个组作为一个团队，用15分钟来讨论，得出答案，然后主考官再选择问某个人答案是什么以及为什么。 <br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;别以为简单，前后可是花了2个小时。这轮主要是考察你的积极性、是否认真、团队合作、交际、思维以及表达能力。这一轮也是我今天表现得最好的一轮了。在自我介绍的环节，你首先要积极，主动站出来自我介绍（我是第二个，是我组的第一个自我介绍的），而且要简单清晰的介绍你自己，要有自己的特色（而不是中国特色）。所有人介绍完以后，鸟主考官居然还抽取几个人，来问是否记得别人的自我介绍，然后陈述一遍。天啊，如果当时在发呆的，就死翘翘了。我也被问及，幸好能说出个所以然。 <br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;然后就是考题目了，主要是考察你的团队协助能力。题目和答案都是其次的，重要的是，你参与讨论的过程，以及你能不能很好的表达团队的思想。人帅就是没办法，鸟蛋主考官问的第一个就是我！足足站了10多分钟。这次我表现得异常好，表达的意思非常清晰也很准确，主考官提出的疑惑都被我一一打压（哈哈，爽）。为什么这么说呢，我观察了后面的回答者，几乎都是我回答内容的拷贝。另外有一点要注意，当主考官提问的时候，我和某个人同时举手了，但是他居然拍一下我，然后自己站起来回答了，我只能微微笑。这样我觉得并不好，主考官并不会喜欢这样的人，不知道他是什么命运。 <br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;这一轮让我见识到了什么叫做面试。在这过程中，许多人并不积极，或者回答的时候吞吞吐吐，根本无法让人理解他表达的意思，估计下场不会很好。前后一共2个小时，简直是如坐针毡，因为你必须时刻都认真，脑子要不断酝酿，以免被问及后无法回答。 <br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;最后议论就是和你谈待遇了。华为是个吸血鬼，你开的价他无视，然后开个低价给你。我嘛，心虚啊，为什么呢？一是那鸟人说没四级很难办（我%*&amp;%@&amp;*$*），还有一个就是竞争对手太强了，个个都名牌大学，工作经验丰富。我本来以为我是中兴通讯的有点优势，谁知道，N多中兴出来的，个个都牛得不得了，做集成电路的，在研究所的...我顶，我算啥! <br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;最后告诉我：&#8220;你通过了！&#8221;，我才松一口气。毕竟煎熬了一天，让华为认可了我的能力。他让我12月初报道，哈哈，我才懒得鸟你，回家好好睡觉，来不来还是一回事呢^_^。
<img src="http://www.cnblogs.com/lemony/aggbug/927014.html?type=1" width="1" height="1" alt=""/><p>评论: 12　<a href="http://www.cnblogs.com/lemony/archive/2007/10/17/927014.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/lemony/archive/2007/10/17/927014.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56845/" target="_blank">奇虎新注资两家知名软件公司 投资项目达10笔</a><span style="color:gray">(2010-02-10 15:14)</span><br/>· <a href="http://news.cnblogs.com/n/56844/" target="_blank">网友对Google的9大期待</a><span style="color:gray">(2010-02-10 15:07)</span><br/>· <a href="http://news.cnblogs.com/n/56843/" target="_blank">分析称Google Buzz有十大特点：将改变搜索</a><span style="color:gray">(2010-02-10 15:06)</span><br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>美少年小猫</title><link>http://www.cnblogs.com/lemony/archive/2007/10/16/926280.html</link><dc:creator>柠檬的</dc:creator><author>柠檬的</author><pubDate>Tue, 16 Oct 2007 07:57:00 GMT</pubDate><guid>http://www.cnblogs.com/lemony/archive/2007/10/16/926280.html</guid><description><![CDATA[<p>阅读: 250 评论: 1 作者: <a href="http://www.cnblogs.com/lemony/" target="_blank">柠檬的</a> 发表于 2007-10-16 15:57 <a href="http://www.cnblogs.com/lemony/archive/2007/10/16/926280.html" target="_blank">原文链接</a></p><img style="cursor: pointer" onclick="javascript:funCheckURL(this);" alt="点击在新窗口中查看该图片" src="http://photo1.bababian.com/upload3/20070912/7EBB1C679C8789BE6192D18B534A4851_500.jpg" /><br />
<img style="cursor: pointer" onclick="javascript:funCheckURL(this);" alt="点击在新窗口中查看该图片" src="http://photo1.bababian.com/upload3/20070912/F81E1733E082FDB1E1C8A6C8F516939B_500.jpg" />&nbsp;
<img src="http://www.cnblogs.com/lemony/aggbug/926280.html?type=1" width="1" height="1" alt=""/><p>评论: 1　<a href="http://www.cnblogs.com/lemony/archive/2007/10/16/926280.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/lemony/archive/2007/10/16/926280.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56845/" target="_blank">奇虎新注资两家知名软件公司 投资项目达10笔</a><span style="color:gray">(2010-02-10 15:14)</span><br/>· <a href="http://news.cnblogs.com/n/56844/" target="_blank">网友对Google的9大期待</a><span style="color:gray">(2010-02-10 15:07)</span><br/>· <a href="http://news.cnblogs.com/n/56843/" target="_blank">分析称Google Buzz有十大特点：将改变搜索</a><span style="color:gray">(2010-02-10 15:06)</span><br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>光驱发展史</title><link>http://www.cnblogs.com/lemony/archive/2007/09/29/910764.html</link><dc:creator>柠檬的</dc:creator><author>柠檬的</author><pubDate>Sat, 29 Sep 2007 07:03:00 GMT</pubDate><guid>http://www.cnblogs.com/lemony/archive/2007/09/29/910764.html</guid><description><![CDATA[<p>阅读: 630 评论: 0 作者: <a href="http://www.cnblogs.com/lemony/" target="_blank">柠檬的</a> 发表于 2007-09-29 15:03 <a href="http://www.cnblogs.com/lemony/archive/2007/09/29/910764.html" target="_blank">原文链接</a></p><div>在各种媒体上有很多关于光驱的文章，但好象文章类型大多数都是评测、选购、维护保养，当然还有很多是各厂商降价、促销搞活动的新闻稿，但谈到光驱发展史的文章很少，其实算一算光驱从出现到现在也有10多年的历史了，从当初的单速、倍速发展到目前50速、58速，从当初的洋品牌占统治地位到现在的国产名牌成为主流，从当初的只能读一种格式到现在的兼容多种格式。下面就请朋友们跟笔者做个时间之旅，看看这个大舌头的朋友的发展历程。<br />
　<br />
<strong>第一代光驱：标准型</strong><br />
　<br />
　之所以管第一代光驱叫做标准型，是因为第一代光驱制定了很多光驱的标准，并且沿用至今，比如一张光盘的容量为640Mb（笔者这里称的光盘制传统的CD-ROM），光驱的数据传输率为150KB/S，这一标准也奠定了几倍速光驱这一光驱独特的叫法，比如40倍速光驱的传输速度为150KB/S*40=6000KB/S。笔者手头正好有那时的一些历史资料，让我们再重温一下。<br />
　<br />
　1991年，由有全球1500家软体厂商加氲腟oftware-Publishers-Association中的Multimdeia PC Working Group公布第一代MPC（Multimedia-Personal-Computer）规格，带动了光盘出版品的流行。一张光盘的容量是640MB，光驱的数据传输率为150KB/S（被国际电子工业联合会定为单倍速光驱），平均搜寻时间为1秒。随着市场的不断需求，硬件技术的不断增进。1993年，第二代MPC规格问世，光驱的速度已变成了双倍速，传输率达到了300KB/S，平均搜寻时间为400ms。<br />
　<br />
　400ms的平均寻道时间，300KB/S的传输率，640MB的容量，对于目前动辄配一个7200转、2MB cache，30GB容量的朋友来说可能觉得第一代光驱速度太慢，容量太小。但要知道第一代光驱出现的时候还是大家用软盘作为主要移动拷贝媒介，经常用10多张盘拷贝一个软件或游戏，然后用2、30分钟将它装入机器内，如果其中一张盘有质量问题或拷错了，整个工夫就白费了。那时侯硬盘也只有200MB上下，400MB的硬盘要1700、1800才能买到。笔者还清晰的记得在第一次在朋友家看到他新买的光驱时，当时的感觉就是无限的游戏和软件，并且装起来快截又方便。当然，不久笔者也拥有了自己的第一块光驱，新加坡的唯用，倍速，1000多块。<br />
　<br />
　第一代光驱的特点是光驱刚刚出现，制定了光驱的很多技术标准，作为软驱与硬盘交换数据的替代品，增大了容量，提高了速度，极大的提高了效率。那时候国内品牌非常少，比较有代表的品牌象SONY、Philips及新加坡的一些品牌。<br />
　<br />
<strong>第二代光驱：提速型</strong><br />
　<br />
　笔者划分的第二代主要是指光驱从4速发展到24速（32速）这一时间段。因为之后从32速再往高速光驱发展过程中虽然速度也在提高，但更多的技术发展目标已不在速度上，因此划入下一代。<br />
　<br />
　光驱发展了一段时间，由于其相对于软盘极大的优越性逐渐普及起来，成为装机时的标准配置。上百MB的软件、游戏也渐渐多了起来。装软件还稍微好一点，装一遍就完了，玩游戏时经常要从光盘调用数据，此时光驱读取速度太慢也逐渐突显出来，有时候一个游戏走到下一关读一下数据要读2、3分钟，特别是玩仙剑这样的RPG游戏，经常要在各关之间穿梭，玩一个小时要有20分钟用来读盘，这谁受得了，怎么办？提速。<br />
　<br />
　此时提速也成为各家厂商技术发展的主要目标，速度从4倍速、8倍速、一直提高到24倍速、32倍速。此时光驱的支持格式也有发展，1995年夏，Multimdeia PC Working Group公布第三代规格标准。兼容光盘格式包括：CD-Audio、CD-Mode1/2、CD-ROM/XA、photo-CD、CD-R、Video-CD、CD-I等。<br />
　<br />
　这个时间笔者的朋友换了一个ACER 16速的光驱，使用起来确实感觉快了，还记得笔者那时侯打仙剑都喜欢去他那，看着载入数据条&#8220;唰&#8221;一下的过去了，心情也愉快起来。但速度快了也并不都好，由于光盘转速太快，噪音变大，发热量变大。当然产品的问题还是要技术的发展来解决，光驱也进入了第三代——发展型。<br />
　<br />
　第二代光驱的特点是光驱逐渐普及起来，但速度慢的弱点也突出起来，提高速度成为各家制造厂商技术竞争的首要目标。光驱支持的格式也渐渐多了起来。<br />
　<br />
　市场上主流的依然是洋品牌及台湾品牌，象Toshiba、NEC、Acer等，出现了一些国产品牌，但还没什么气候。</div>
<div><strong>第三代光驱：发展型<br />
</strong>　<br />
光驱速度再往上提高，传输速度慢的问题已得到很好的解决，但速度提高后所带来的问题却渐渐显现出来。高速度的旋转会产生震动、噪音和热能，震动也会使激光头难以定位，寻道时间加长，并容易与激光头发生碰撞，刮花激光头；产生的热能会影响光盘上的化学介质，影响激光头的准确定位，延长寻道时间；引起的噪音会使人精神上产生不爽的效果，容易疲劳。<br />
　<br />
　针对这些问题，各个不同的生产厂家也推出了相应改善的技术：NEC公司在四角上安装悬浮式减震橡胶；Acer公司采用悬挂技术和香蕉减震支架；Lite-on采用悬浮承载技术；Asus公司采用先进的双重动态悬挂系统&#8230;&#8230;<br />
　<br />
　这一阶段值得一提的是很多国内厂商发展起来，以其完善的品质、低廉的价格受到消费者得青睐，成为市场的主流。<br />
　<br />
　第三代的特点是速度已不是各厂商发展技术的主要目标，大家纷纷推出新技术，使光驱读盘更稳定，发热量更低，工作起来更安静，寿命更长。国内厂商发展起来，成为市场主流。<br />
　<br />
　市场上洋品牌及台湾品牌份额有一定减少，许多国内品牌崛起，象奥美嘉源兴、大白鲨、美达等等。<br />
　<br />
第四代光驱：完美型<br />
　<br />
　又经过几年的发展，光驱的技术已经趋于成熟，各家厂商的产品虽然可能采用的技术略有不同，但产品品质却都臻于完善，甚至说完美，表现在纠错率更强，传输速度更快，工作起来更稳定、更安静、发热量更低。<br />
　<br />
　比如奥美嘉科技推出50X光驱采用专为大陆市场设计的AUTO GAIN CONTROL FUNCTION技术，将传统的三通道镭射光追加到七道，中间一道负责寻轨，其余六道专注于读取资料，因而提高了读盘能力。为降低故障率采用的CSS技术是对等三悬浮系统，以降低噪音、震动，增强光驱的寿命和读盘能力。超静音技术的全钢机芯和DDSSⅡ技术（双悬吊技术），可以在电机高速转动时最大限度地降低震动和噪音。<br />
　<br />
　其它公司的产品虽然可能在某些方面采用不同的技术，但也都是很好的产品。<br />
　<br />
　此外，各家厂商也还在努力将服务做好，除附赠超值软件外，承诺保修包换的售后服务以外，还纷纷推出&#8220;零等待&#8221;服务，包修期内的用户可持返修品到任意一个相应产品经销点现场更换同类保质产品。<br />
　<br />
　如果以上这些技术和服务让您觉得当&#8220;上帝&#8221;还是不过瘾的话，笔者近日在市场上看到的奥美嘉公司一款高端产品——&#8220;任我行&#8221;光驱更是将完美的含义诠释到极至，将包装和服务也做到让用户十分满意。<br />
　<br />
　这款光驱居然采用豪华大礼盒包装（笔者第一眼看见心里还在奇怪，怎么中关村的柜台里也卖起洋酒了：-）），内部采用绫罗绸缎的内饰，里面光驱是塑封的，下面摆着捆绑的相关软件等（笔者想起来了以前买的光驱好多连包装盒都没有，真是感到受宠若惊）。当然，包装还只是一部分，用户更注重的是能享受到的服务，这款&#8220;任我行&#8221;光驱还提供一年的免费换新服务。这种服务方式还是笔者第一次看到，等于用户用一只光驱的价格可以获得2只光驱的使用时间，是不是十分超值呢？能提供这种服务也正是产品有实力的体现。<br />
　<br />
　第四代光驱的特点是各方面都臻于完美，纠错率更强，传输速度更快，工作起来更稳定、更安静、发热量更低，同时包装、服务更好。<br />
　<br />
　代表品牌有奥美嘉&#8220;任我行&#8221;光驱等。<br />
　<br />
　对光驱发展的展望，技术发展如此之快，未来是怎样的，谁也不知道。但技术的发展只会让我们的生活更轻松，就光驱来说，肯定是传输速度更快，容量更大，那时也许是DVD+CDRW，硬盘软盘都会消失，我们可以将全部资料存在一张光盘上，随便拿到哪里放在光驱里，这台机器就跟自己机器里的环境配置和数据都一样了。也欢迎朋友们提出自己对未来光储设备的设想，与笔者交流。</div>
<img src="http://www.cnblogs.com/lemony/aggbug/910764.html?type=1" width="1" height="1" alt=""/><p>评论: 0　<a href="http://www.cnblogs.com/lemony/archive/2007/09/29/910764.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/lemony/archive/2007/09/29/910764.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56845/" target="_blank">奇虎新注资两家知名软件公司 投资项目达10笔</a><span style="color:gray">(2010-02-10 15:14)</span><br/>· <a href="http://news.cnblogs.com/n/56844/" target="_blank">网友对Google的9大期待</a><span style="color:gray">(2010-02-10 15:07)</span><br/>· <a href="http://news.cnblogs.com/n/56843/" target="_blank">分析称Google Buzz有十大特点：将改变搜索</a><span style="color:gray">(2010-02-10 15:06)</span><br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>50年变大了八万倍！超经典硬盘发展史</title><link>http://www.cnblogs.com/lemony/archive/2007/09/29/910749.html</link><dc:creator>柠檬的</dc:creator><author>柠檬的</author><pubDate>Sat, 29 Sep 2007 06:51:00 GMT</pubDate><guid>http://www.cnblogs.com/lemony/archive/2007/09/29/910749.html</guid><description><![CDATA[<p>阅读: 418 评论: 1 作者: <a href="http://www.cnblogs.com/lemony/" target="_blank">柠檬的</a> 发表于 2007-09-29 14:51 <a href="http://www.cnblogs.com/lemony/archive/2007/09/29/910749.html" target="_blank">原文链接</a></p>&nbsp;&nbsp; 首先，还是让我们来简单了解一下<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>的发展历程，以及<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>技术革新的几个方面吧。说到<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>的发展历程，我们不得不提起<a class="keyword" href="http://product.pcpop.com/HDD/00171_1.html" target="_blank">IBM</a>这个国际财团。在整个<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>技术更新的过程中，<a class="keyword" href="http://product.pcpop.com/HDD/00171_1.html" target="_blank">IBM</a>的是功不可没的，几乎每一项革命性的<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>技术都与<a class="keyword" href="http://product.pcpop.com/HDD/00171_1.html" target="_blank">IBM</a>有着千丝万缕的关系。并且，世界上第一块<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>就是有<a class="keyword" href="http://product.pcpop.com/HDD/00171_1.html" target="_blank">IBM</a>发明并制造的。
<p>&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp; 最早的<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>可算是1956年9月，<a class="keyword" href="http://product.pcpop.com/HDD/00171_1.html" target="_blank">IBM</a>的一个工程小组向世界展示了第一台磁盘存储系统<a class="keyword" href="http://product.pcpop.com/HDD/00171_1.html" target="_blank">IBM</a> 350 RAMAC（Random Access Method of Accounting and Control），它的磁头可以直接移动到盘片上的任何一块存储区域，从而成功地实现了随机存储，这套系统的总容量只有5MB，共使用了50个直径为24英寸的磁盘，这些盘片表面涂有一层磁性物质，它们被叠起来固定在一起，绕着同一个轴旋转。此款RAMAC在那时主要用于飞机预约、自动银行、医学诊断及太空领域内。普通用户是不可能用到得，当然当时的<a class="keyword" href="http://product.pcpop.com/PC/00000_1.html" target="_blank">电脑</a>也不多，还没有所谓的PC（Personal Computer）。</p>
<p align="center"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" alt="只用了49年！硬盘容量翻了80000倍" src="http://img2.pcpop.com/ArticleImages/0x0/0/42/000042133.jpg" border="1" /></p>
<div align="center"><img src="http://document.pcpop.com/Image/popup.gif" border="0"  alt="" /><a class="keyword" href="http://product.pcpop.com/HDD/00171_1.html" target="_blank">IBM</a> 350 RAMAC</div>
<p>&nbsp;&nbsp;&nbsp; 由于RAMAC庞大的体积及低效的性能，使用或者制造都非常不便，因此在1968年IBM公司又提出了&#8220;温彻斯特/Winchester&#8221;技术，探讨对硬盘技术做重大改造的可能性。&#8220;温彻斯特&#8221;技术的精隋是：&#8220;密封、固定并高速旋转的镀磁盘片，磁头沿盘片径向移动，磁头悬浮在高速转动的盘片上方，而不与盘片直接接触&#8221;，这也是现代绝大多数硬盘的原型。在此项温氏技术提出后的5年，即1973年，IBM公司制造出了第一台采用&#8220;温彻期特&#8221;技术的硬盘，从此硬盘技术的发展有了正确的结构基础，现在大家所用的硬盘大多是此技术的延伸。 <!--content End--></p>
<br />
&nbsp;&nbsp; 1956年9月 著名的<a class="keyword" href="http://product.pcpop.com/HDD/00171_1.html" target="_blank">IBM</a>的公司的一个工程小组将世界上首个&#8220;<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>&#8221;展示给了大家，它并不是我们现在所说的完整意义上的<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>，它仅仅是一个磁盘储存系统，现在来看较为落后的机械组件，庞大的占地面积，不由让人胆寒。他的名字叫做<a class="keyword" href="http://product.pcpop.com/HDD/00171_1.html" target="_blank">IBM</a> 350 RAMAC（Random Access Method of Accounting and Control）。
<p>&nbsp;</p>
<p align="center"><img src="http://img2.pcpop.com/ArticleImages/0x0/0/41/000041185.jpg" border="0"  alt="" /></p>
<p>&nbsp;&nbsp;&nbsp; 我们可以看到图中左边的那个机轨，中间的一个圆柱体容器，就是我们现在<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>盘片的雏形。</p>
<p>&nbsp;&nbsp;&nbsp; 他的磁头可以直接移动到盘片上的任何一块存储区域，从而成功地实现了随机存储，大家别看他个子比较大，以为容量就吓人，其实他不过才有5M的空间。 </p>
<p align="center"><img src="http://img2.pcpop.com/ArticleImages/0x0/0/41/000041186.jpg" border="0"  alt="" /></p>
<p align="left">&nbsp;&nbsp;&nbsp; 一共使用了50个直径为24英寸的磁盘，这些盘片表面涂有一层磁性物质，并且堆叠在一起，通过一个传动轴承是他可以顺利的工作（真想看看那个时候的电机有多大。）盘片由一台电动机带动，只有一个磁头，磁头上下前后运动寻找要读写的磁道。盘片上每平方英寸的数据密度只有2000bit，数据处理能力为1.1KB/s。</p>
<p align="left">&nbsp;&nbsp; 此款RAMAC在那时主要用于飞机预约、自动银行、医学诊断及太空领域内，推出之后便让人大为震惊，不光是因为他的技术理念，因为有了他才有了后来的温彻斯特，还有他的价格，当时推出的售价是35，000美元，平均每M要有7000美元的成本，想想现在我们真实太幸福了，每M连7分的成本都用不了。就是由此开始<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>的发展之路。下面就让我们一起来回顾一下&#8220;太古&#8221;时期的<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>吧。</p>
<br />
&nbsp;&nbsp; <a class="keyword" href="http://product.pcpop.com/HDD/00171_1.html" target="_blank">IBM</a> WD12的容量只有10 MB，盘片尺寸为5.25英寸。由于缺乏更详细的资料，其出生年月不祥。性能参数也不得而知，不过从其砖头般大小的身躯来看，应该属于80年代末到90年代初的产品。
<p>&nbsp;</p>
<div align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042074" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"></a></div>
<div align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042074" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042074.jpg" border="1"  alt="" /></a></div>
<p align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042075" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/200x150/0/42/000042075.jpg" border="1"  alt="" /></a>&nbsp;&nbsp; <a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042076" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/200x150/0/42/000042076.jpg" border="1"  alt="" /></a></p>
<p align="left">&nbsp;&nbsp;&nbsp; 从<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>电路板密集的电子元件（这是由于芯片的集成度不高而导致的）我们能看出，当时的制造工艺和现在相比简直就是一个地上一个天上。</p>
<p>&nbsp;&nbsp;&nbsp; Tandon，一个在中国鲜为人知的<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>品牌，由于它很早就被<a class="keyword" href="http://product.pcpop.com/HDD/00490_1.html" target="_blank">西部数据</a>收购，因此其生产的<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>对于80出生读者们，恐怕是难得一见了。</p>
<div align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042077" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042077.jpg" border="1"  alt="" /></a></div>
<p align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042078" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042078.jpg" border="1"  alt="" /></a></p>
<p align="center"><img src="http://document.pcpop.com/Image/popup.gif" border="0"  alt="" />TM502 比砖头还要厚</p>
<p align="left">&nbsp;&nbsp;&nbsp; 这款<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>的型号为TM502，容量为10MB，盘片尺寸为5.25英寸。</p>
<p align="left">&nbsp;&nbsp;&nbsp; Seagate的中文名为<a class="keyword" href="http://product.pcpop.com/HDD/00415_1.html" target="_blank">希捷</a>，是大家熟悉的<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>生产商之一，同时也是推动<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>技术更新的生产商之一。</p>
<div align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042079" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042079.jpg" border="1"  alt="" /></a></div>
<p align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042080" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042080.jpg" border="1"  alt="" /></a></p>
<p align="left">&nbsp;&nbsp;&nbsp; ST-412是<a class="keyword" href="http://product.pcpop.com/HDD/00415_1.html" target="_blank">希捷</a>推出的第二块5.25英寸<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>，容量为10MB。第一款是1980年6月推出的ST-506，容量只有5MB。而ST-412是1982年推出的。</p>
<p align="left">&nbsp;&nbsp;&nbsp; 日本品牌的<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>也许许多朋友都别熟悉，从名气上来说，日本<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>在中国并不大，这也是日本<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>近年来很少推出针对<a class="keyword" href="http://desk.pcpop.com/" target="_blank">桌面</a>市场的<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>所导致的。事实上，日本<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>也已经有很久的历史了。</p>
<p align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042081" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042081.jpg" border="1"  alt="" /></a></p>
<div align="center"><img src="http://document.pcpop.com/Image/popup.gif" border="0"  alt="" />&nbsp;NEC&nbsp;D5124正面及反面</div>
<p align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042082" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042082.jpg" border="1"  alt="" /></a></p>
<p align="center"><img src="http://document.pcpop.com/Image/popup.gif" border="0"  alt="" />&nbsp;NEC&nbsp;D5124侧面</p>
<p align="left">&nbsp;&nbsp;&nbsp; NEC退出<a class="keyword" href="http://desk.pcpop.com/" target="_blank">桌面</a><a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>市场争夺已经很多年了，这款D5124也是上世纪80年代初的产品了，容量为10M，盘片尺寸为5.25英寸。</p>
<p align="left">&nbsp;&nbsp;&nbsp; Miniscribe成立于1980年，那一年5.25寸<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>问世，Miniscribe由于掌握了5.25英寸<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>的关键技术，因此在80年代有着不错的成绩。然而由于其对3.5寸<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>技术的抵制，使其失去了以往的<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>市场，因此在1990年4月宣布破产，并于1991年被当时的<a class="keyword" href="http://product.pcpop.com/HDD/00488_1.html" target="_blank">迈拓</a>所收购。</p>
<p align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042083" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042083.jpg" border="1"  alt="" /></a></p>
<div align="center"><img src="http://document.pcpop.com/Image/popup.gif" border="0"  alt="" />&nbsp;Miniscribe MS3212 正面及反面</div>
<p align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042084" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042084.jpg" border="1"  alt="" /></a></p>
<p align="center"><img src="http://document.pcpop.com/Image/popup.gif" border="0"  alt="" />&nbsp;Miniscribe MS3212 容量为10 MB，盘片尺寸为10MB</p>
<br />
&nbsp;&nbsp;&nbsp; Microscience这个品牌嘛，呵呵，说实话，小编也未曾见过，而且他的资料也相当少，其生于何时，现在是否还健在，均无答案。但现在似乎国内市场并没有叫Microscinece品牌的<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>销售，估计不是被收购就是转行做别的了。
<p>&nbsp;</p>
<p align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042085" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042085.jpg" border="1"  alt="" /></a></p>
<p align="center"><img src="http://document.pcpop.com/Image/popup.gif" border="0"  alt="" />&nbsp;Microscience HH1050</p>
<p align="left">&nbsp;&nbsp;&nbsp; 虽然Microscience的底细不明，但他这款<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>的出生时间却有据可查。从该<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>的<a class="keyword" href="http://pp.pcpop.com/" target="_blank">图片</a>中我们能发现该<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>的出场日期为1990年。该<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>的 型号为HH1050，容量为44MB，盘片尺寸为5.25英寸。</p>
<p align="left">&nbsp;&nbsp;&nbsp; 在80年代末的微机中，下面这块Seagate ST225 20MB的5英寸<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>使用率较高，<a class="keyword" href="http://product.pcpop.com/PC/00000_1.html" target="_blank">电脑</a>骨灰级的人物对这块<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>应该似曾相识。</p>
<p align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042097" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042097.jpg" border="1"  alt="" /></a></p>
<p align="center"><img src="http://document.pcpop.com/Image/popup.gif" border="0"  alt="" />&nbsp;Seagate ST225 </p>
<p align="left">&nbsp;&nbsp;&nbsp; 该<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>转速为3600转/分，接口类型为ST412，单碟容量10MB，盘片数2张，4个磁头，记录密度（BPI）9827，磁道密度（TPI）588，道与道时间（ms）23，内部传输速率（Mb/s）5，盘片尺寸5.25英寸，生产日期为1988年。</p>
<br />
&nbsp;&nbsp; 看了好几款几十兆容量的<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>，你是不是都有些郁闷了呢？别急，下面这款就是突破了100兆容量<a class="keyword" href="http://product.pcpop.com/HDD/00415_1.html" target="_blank">希捷</a>ST2383E。
<p>&nbsp;</p>
<p align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042098" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042098.jpg" border="1"  alt="" /></a></p>
<p align="center"><img src="http://document.pcpop.com/Image/popup.gif" border="0"  alt="" />&nbsp;<a class="keyword" href="http://product.pcpop.com/HDD/00415_1.html" target="_blank">希捷</a>ST2383E 338MB容量</p>
<p align="left">&nbsp;&nbsp;&nbsp; 该<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>转速为3600转/分，拥有了32kb缓存，容量为338MB。这样的容量在DOS时代可称得上&#8220;海量&#8221;了。</p>
<br />
&nbsp;&nbsp; Quantum的辉煌我想凡是玩儿<a class="keyword" href="http://product.pcpop.com/PC/00000_1.html" target="_blank">电脑</a>有5年以上，应该都会有所体会。上世纪90年代，几乎就是昆腾的天下，他的<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>质量过关，性能稳定，技术更新快，是当时最成功的<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>厂商之一。然而，由于决策失误，以及对3.5寸<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>的排斥，使其丧失了市场先机，从而走向了末路。
<p>&nbsp;</p>
<p align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042104" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042104.jpg" border="1"  alt="" /></a></p>
<p align="center"><img src="http://document.pcpop.com/Image/popup.gif" border="0"  alt="" />&nbsp;Quantum Bigfoot 大脚<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>（2GB）</p>
<p align="left">&nbsp;&nbsp;&nbsp; 而这款容量为2G的Quantum Bigfoot 大脚<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>，应该算得上是昆腾<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>中的经典产品，同时也是昆腾征战市场主力军。该<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>的拥有3600转/分的转速，5.25英寸的盘片。</p>
<br />
&nbsp;&nbsp; TM262可以说是Tandon最早采用3.25英寸盘片的<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>了。虽然已经步入3.25英寸时代，<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>体积也进一步缩小，但<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>容量的却仍然只有20MB。
<p>&nbsp;</p>
<p align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042105" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042105.jpg" border="1"  alt="" /></a></p>
<div align="center"><img src="http://document.pcpop.com/Image/popup.gif" border="0"  alt="" />&nbsp;Tandon TM262， 容量20MB</div>
<p>&nbsp;&nbsp;&nbsp; 从下面这款NEC容量为42MB的D3142<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>来看，NEC直到90年代初还未退出<a class="keyword" href="http://desk.pcpop.com/" target="_blank">桌面</a><a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>市场，因为采用3.25盘片的<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>到80年代末才出现的，而且容量也不高。</p>
<div align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042097" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"></a></div>
<p align="center"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042106.jpg" border="1"  alt="" /></p>
<p align="center"><img src="http://document.pcpop.com/Image/popup.gif" border="0"  alt="" />&nbsp;NEC D3142 容量：42 MB</p>
<p align="left">&nbsp;&nbsp;&nbsp; 在昆腾如日中天的上世纪90年代。Maxtor却在艰难度日，但是他却很好的把握住了3.25英寸<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>的契机，终于在上世纪90年代末期将昆腾远远抛在了自己身后，造就了<a class="keyword" href="http://product.pcpop.com/HDD/00488_1.html" target="_blank">迈拓</a>现在的辉煌。下面这款<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>就是Maxtor 40MB容量的 8051A。</p>
<p align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042107" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042107.jpg" border="1"  alt="" /></a></p>
<p align="center"><img src="http://document.pcpop.com/Image/popup.gif" border="0"  alt="" />&nbsp;Maxtor 8051A反面</p>
<p align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042108" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042108.jpg" border="1"  alt="" /></a></p>
<p align="center"><img src="http://document.pcpop.com/Image/popup.gif" border="0"  alt="" />&nbsp;Maxtor 8051A电路板</p>
<p align="left">&nbsp;&nbsp;&nbsp; 从图中的电路板中我们明显感到，3.25英寸<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>电路板中的芯片集成度已经有了长足的进步。这款<a class="keyword" href="http://product.pcpop.com/HDD/00488_1.html" target="_blank">迈拓</a>8051A事实上是被其收购的Miniscribe生产的，推算它的生产日期应该在1991年之后了。该<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>具备40MB容量，32KB缓存，以及28ms平均存取时间。</p>
<p align="left">&nbsp;&nbsp;&nbsp; KALOK，又一个小编以前未曾听过的<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>品牌，而现在市场上也早已没有KALOL这个品牌了，因此也难觅其相关资料。下面这KALOK<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>型号为KL320，容量20MB。</p>
<p align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042109" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042109.jpg" border="1"  alt="" /></a></p>
<p align="center"><img src="http://document.pcpop.com/Image/popup.gif" border="0"  alt="" />&nbsp;KALOK KL320 容量：20MB</p>
<p align="left">&nbsp;&nbsp;&nbsp; 不过从仅有一点点资料中我们还是知道了它的容量为20MB，应该是较早一批3.25英寸<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>了，产于1990年。</p>
<div align="left">&nbsp;&nbsp;&nbsp; 从手里掌握的情况来看，KYOCERA是一个数码产品生产商，其产品包括<a class="keyword" href="http://product.pcpop.com/PDA/00000_1.html" target="_blank">PDA</a>，<a class="keyword" href="http://product.pcpop.com/Mobile/00000_1.html" target="_blank">手机</a>等。然而我们这款KYOCERA KC-20A<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>是否就是我刚才所说的KYOCERA的呢？</div>
<p align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042110" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042110.jpg" border="1"  alt="" /></a></p>
<p align="center"><img src="http://document.pcpop.com/Image/popup.gif" border="0"  alt="" />&nbsp;KYOCERA KC-20A 容量：20MB</p>
<p align="left">&nbsp;&nbsp;&nbsp; 由于暂时没有相关资料，因此得不到证实，但小编猜想他们之间肯定有不小的渊源。KYOCERA KC-20A 具备20MB容量，相信也是最早一批3.25寸<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>之一。</p>
<p align="left">&nbsp;&nbsp;&nbsp; 同时代的Seagate在3.25英寸<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>领域，已经取得了非常好的成绩，只可惜其把重点只放在<a class="keyword" href="http://product.pcpop.com/Server/00000_1.html" target="_blank">服务器</a>等高端市场，在个人消费市场作为不大。下面这款<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>就是Seagate 84MB容量的ST352A<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>，在其发布之初，仍然算得上是&#8220;海量&#8221;<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>。</p>
<p align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042120" target="_blank" alt="它们你都认识几个？50载老硬盘大聚会"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042120.jpg" border="1"  alt="" /></a></p>
<p align="center"><img src="http://document.pcpop.com/Image/popup.gif" border="0"  alt="" />&nbsp;Seagate 3.25英寸<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>：ST352A</p>
<p align="left">&nbsp;&nbsp;&nbsp; CONNER恐怕也是一个另大多数读者陌生的<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>品牌，由于其很早就遭到了被收购的命运，因此其在国内并没有什么影响。</p>
<p align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042118" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042118.jpg" border="1"  alt="" /></a></p>
<p align="center"><img src="http://document.pcpop.com/Image/popup.gif" border="0"  alt="" />&nbsp;CONNER&nbsp; CP3184反面及电路板</p>
<p align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042119" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042119.jpg" border="1"  alt="" /></a></p>
<p align="center"><img src="http://document.pcpop.com/Image/popup.gif" border="0"  alt="" />CONNER&nbsp; CP3184侧面</p>
<p align="left">&nbsp;&nbsp;&nbsp; 从上图中我们已经能够感受到，采用3.25英寸的盘片之后，<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>的厚度已经明显减小了。</p>
<br />
&nbsp;&nbsp; <a class="keyword" href="http://product.pcpop.com/HDD/00282_1.html" target="_blank">富士通</a>是一个在上世纪90年代很有实力的<a class="keyword" href="http://desk.pcpop.com/" target="_blank">桌面</a><a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>生产商。但随着市场竞争的激烈，<a class="keyword" href="http://product.pcpop.com/HDD/00282_1.html" target="_blank">富士通</a><a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>逐渐有些招架不住，于是在几年前已经退出了<a class="keyword" href="http://desk.pcpop.com/" target="_blank">桌面</a><a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>市场的争夺。
<p>&nbsp;</p>
<p align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042113" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042113.jpg" border="1"  alt="" /></a></p>
<div align="center"><img src="http://document.pcpop.com/Image/popup.gif" border="0"  alt="" />&nbsp;<a class="keyword" href="http://product.pcpop.com/HDD/00282_1.html" target="_blank">富士通</a>M2614ET电路板及反面 </div>
<p align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042114" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042114.jpg" border="1"  alt="" /></a></p>
<p align="center"><img src="http://document.pcpop.com/Image/popup.gif" border="0"  alt="" />&nbsp;<a class="keyword" href="http://product.pcpop.com/HDD/00282_1.html" target="_blank">富士通</a>M2614ET侧面</p>
<p align="left">&nbsp;&nbsp;&nbsp; 而这款182MB的<a class="keyword" href="http://product.pcpop.com/HDD/00282_1.html" target="_blank">富士通</a>M2614E0T在那个时候可是<a class="keyword" href="http://product.pcpop.com/HDD/00282_1.html" target="_blank">富士通</a><a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>在<a class="keyword" href="http://desk.pcpop.com/" target="_blank">桌面</a>市场的主力军。其拥有较小的体积和让人满意的速度。 </p>
<br />
&nbsp; <a class="keyword" href="http://product.pcpop.com/HDD/00171_1.html" target="_blank">IBM</a>在<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>领域的龙头地位在进入2000年以前，是没有人能够撼动的。
<p>&nbsp;</p>
<p align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042121" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042121.jpg" border="1"  alt="" /></a></p>
<p align="center"><img src="http://document.pcpop.com/Image/popup.gif" border="0"  alt="" />&nbsp;<a class="keyword" href="http://product.pcpop.com/HDD/00171_1.html" target="_blank">IBM</a> 0663-H12 容量：1004 MB，采用SCIS接口</p>
<p align="left">&nbsp;&nbsp;&nbsp; 唯一能够对其构成威胁的就是<a class="keyword" href="http://product.pcpop.com/HDD/00171_1.html" target="_blank">IBM</a>自己。上图这个是<a class="keyword" href="http://product.pcpop.com/HDD/00171_1.html" target="_blank">IBM</a>在<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>存储容量刚刚突破1GB时的0663-H12 SCSI<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>，主要应用在高端<a class="keyword" href="http://product.pcpop.com/Server/00000_1.html" target="_blank">服务器</a>上。</p>
<br />
<div>&nbsp; 想象一下14英寸的<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>该有多大，至少比砖头要大吧，大家看看下图就应该明白了。</div>
<p align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042126" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042126.jpg" border="1"  alt="" /></a></p>
<p align="center"><img src="http://document.pcpop.com/Image/popup.gif" border="0"  alt="" />&nbsp;NEC制造的14寸<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>DKU800，3620转，2.7GB的容量 </p>
<p align="left">&nbsp;&nbsp;&nbsp; 象个发动机一样，和我们现在用的<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>简直没法比，而且形状也相差太远，第一眼看它，肯定不会以为是<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>了，更像一个鼓风机，而容量却只有2.7GB。</p>
<p align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042124" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042124.jpg" border="1"  alt="" /></a></p>
<div align="center"><img src="http://document.pcpop.com/Image/popup.gif" border="0"  alt="" /><a class="keyword" href="http://product.pcpop.com/HDD/00282_1.html" target="_blank">富士通</a>制造的10.5寸<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>，3600转，446MB的容量，81年的产品</div>
<p align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042123" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042123.jpg" border="1"  alt="" /></a></p>
<div align="center"><img src="http://document.pcpop.com/Image/popup.gif" border="0"  alt="" />NEC制造的8寸<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>，3000转，400MB的容量，82年出品</div>
<p align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042125" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042125.jpg" border="1"  alt="" /></a></p>
<div align="center"><img src="http://document.pcpop.com/Image/popup.gif" border="0"  alt="" />&nbsp;<a class="keyword" href="http://product.pcpop.com/HDD/00282_1.html" target="_blank">富士通</a>的8寸<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>，3600转，2.8GB的容量，92年出品 </div>
<p align="center"><a href="http://www.pcpop.com/doc/App/ImageShow.aspx?category=article&amp;sn=000042127" target="_blank" alt="只用了49年！硬盘容量翻了80000倍"><img style="border-top-width: 1px; border-left-width: 1px; border-left-color: black; border-bottom-width: 1px; border-bottom-color: black; border-top-color: black; border-right-width: 1px; border-right-color: black" src="http://img2.pcpop.com/ArticleImages/400x300/0/42/000042127.jpg" border="1"  alt="" /></a></p>
<p align="center"><img src="http://document.pcpop.com/Image/popup.gif" border="0"  alt="" />&nbsp;<a class="keyword" href="http://product.pcpop.com/HDD/00514_1.html" target="_blank">日立</a>的6.5寸<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>，4200转，2.92GB的容量，93年出品</p>
<div align="left">&nbsp;&nbsp;&nbsp; 看够了吧，呵呵。这些大块头<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>其实都是90年代初应用在大型机和高端<a class="keyword" href="http://product.pcpop.com/Server/00000_1.html" target="_blank">服务器</a>上的<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>，一般老百姓是看不到的。想想现在的<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>只要1个最便宜的40GB<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>都能顶它10几个大块头<a class="keyword" href="http://product.pcpop.com/HDD/00000_1.html" target="_blank">硬盘</a>，直让人感慨科技发展的速度是如何的迅猛。</div>
<!--content End-->
 <img src="http://www.cnblogs.com/lemony/aggbug/910749.html?type=1" width="1" height="1" alt=""/><p>评论: 1　<a href="http://www.cnblogs.com/lemony/archive/2007/09/29/910749.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/lemony/archive/2007/09/29/910749.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56845/" target="_blank">奇虎新注资两家知名软件公司 投资项目达10笔</a><span style="color:gray">(2010-02-10 15:14)</span><br/>· <a href="http://news.cnblogs.com/n/56844/" target="_blank">网友对Google的9大期待</a><span style="color:gray">(2010-02-10 15:07)</span><br/>· <a href="http://news.cnblogs.com/n/56843/" target="_blank">分析称Google Buzz有十大特点：将改变搜索</a><span style="color:gray">(2010-02-10 15:06)</span><br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item></channel></rss>