﻿<?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>C++博客-In my way</title><link>http://www.cppblog.com/kyline/</link><description>On my way</description><language>zh-cn</language><lastBuildDate>Thu, 16 Apr 2026 04:15:55 GMT</lastBuildDate><pubDate>Thu, 16 Apr 2026 04:15:55 GMT</pubDate><ttl>60</ttl><item><title>【转】对话框任务栏隐藏</title><link>http://www.cppblog.com/kyline/archive/2009/05/07/82136.html</link><dc:creator>谷主</dc:creator><author>谷主</author><pubDate>Thu, 07 May 2009 03:19:00 GMT</pubDate><guid>http://www.cppblog.com/kyline/archive/2009/05/07/82136.html</guid><wfw:comment>http://www.cppblog.com/kyline/comments/82136.html</wfw:comment><comments>http://www.cppblog.com/kyline/archive/2009/05/07/82136.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/kyline/comments/commentRss/82136.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/kyline/services/trackbacks/82136.html</trackback:ping><description><![CDATA[隐藏这个Main Dialog的思路就是把这个Dialog看成一个子窗口，然后再把WS_EX_APPWINDOW属性去掉。<br>WS_EX_APPWINDOW不大常用，MSDN的解释是：
<pre>	Forces a top-level window onto the taskbar when the window is visible.
</pre>
把顶层的并且可见的窗口放到任务栏上，移除 WS_EX_APPWINDOW 很容易：
<pre>	ModifyStyleEx(WS_EX_APPWINDOW, 0);
</pre>
就可以了。<br><br>那么什么办法能够最简单的实现创建一个父窗口呢？CFrameWnd 就有点笨了，干脆就用自己好了。在<br>BOOL CHideApp::InitInstance()中：<br>
<pre>	CHideDlg dlgParent;
dlgParent.Create(IDD_HIDE_DIALOG);
dlgParent.ShowWindow(SW_HIDE);
//dlgParent.ShowWindow(SW_SHOW);
CHideDlg dlg(&amp;dlgParent);
m_pMainWnd = &amp;dlg;
int nResponse = dlg.DoModal();
dlgParent.DestroyWindow();
</pre>
在BOOL CHideDlg::OnInitDialog()中：
<pre>	this-&gt;ModifyStyleEx(WS_EX_APPWINDOW, 0);
</pre>
只短短几行，就实现了对话框在任务栏的隐藏。<br><br><img src="http://www.vckbase.com/document/image/paragraph.gif"> <strong>结束语</strong><br>　　如果使用 CDialog 的话，ALT+TAB 图标就不对了:) 之前我也试过用 CWnd，可恨的是它还要去注册窗口类，相比之下还是CHideDlg 最经济，你说呢？祝大家身体健康，每天都有新发现！<br><br>E-Mail : webmaster@sanjin.51.net QQ : 923452 
<img src ="http://www.cppblog.com/kyline/aggbug/82136.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/kyline/" target="_blank">谷主</a> 2009-05-07 11:19 <a href="http://www.cppblog.com/kyline/archive/2009/05/07/82136.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VS 2010 C++ 王者归来</title><link>http://www.cppblog.com/kyline/archive/2009/04/27/81217.html</link><dc:creator>谷主</dc:creator><author>谷主</author><pubDate>Mon, 27 Apr 2009 08:02:00 GMT</pubDate><guid>http://www.cppblog.com/kyline/archive/2009/04/27/81217.html</guid><wfw:comment>http://www.cppblog.com/kyline/comments/81217.html</wfw:comment><comments>http://www.cppblog.com/kyline/archive/2009/04/27/81217.html#Feedback</comments><slash:comments>13</slash:comments><wfw:commentRss>http://www.cppblog.com/kyline/comments/commentRss/81217.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/kyline/services/trackbacks/81217.html</trackback:ping><description><![CDATA[作为Visual C++程序员，大家心里都很憋屈！大家都在问，Visual C++的前途在哪里？坚持C++还有没有意义？<br><br>&nbsp; 在Visual Studio 2010中我们找到了答案，找到了C++的未来：C++王者归来！
<div>&nbsp; 虽然在C++的发展历程中经历了上述小小的波折，但是我们应当看到，世界上还有无数的C++代码在稳定地运行着，这些代码还需要维护，需要升级。另外，C++在某些领域还是具有不可替代的优势，无数基于C++的新项目正在进行着。微软也逐渐意识到了这一点，开始不断增强Visual Studio对C++的支持力度。在这次的Visual Studio 2010 CTP中，无论是从C++语言本身还是从IDE方面，都给我们带来了很多期盼已久的新特性。花开两朵，各表一枝。我们这里按下Visual Studio 2010在IDE方面的增强不表，单说它对即将到来的C++新标准C++0x的支持。</div>
<div><br>&nbsp; C++的新标准C++0x虽然还没有正式发布，但是已经进入了feature freeze的阶段，很多人都在猜测C++0x中的x到底是9还是10，从目前的情况来看，9是最大的可能了。Visual Studio 2010作为下一代开发工具，当然不会错过对新的C++标准C++0x的支持。除了随着之前发布的Visual C++ Feature Pack而引入的TR1包含的部分特性外，在新的Visual Studio 2010中，还引入了4个重要的C++新特性。号称C++0x的&#8220;四大天王&#8221;。这些新特性的引入，必将给C++注入新的活力。</div>
<div>
<div><strong><br>&nbsp; Lambda表达式</strong></div>
</div>
<div><br>&nbsp; 很多编程编程语言都支持匿名函数(anonymous function)。所谓匿名函数，就是这个函数只有函数体，而没有函数名。Lambda表达式就是实现匿名函数的一种编程技巧，它为编写匿名函数提供了简明的函数式的句法。同样是Visual Studio中的开发语言，Visual Basic和Visual C#早就实现了对Lambda表达式的支持，终于Visual C++这次也不甘落后，在Visual Studio 2010中添加了对Lambda表达式的支持。</div>
<p>&nbsp; Lambda表达式使得函数可以在使用的地方定义，并且可以在Lambda函数中使用Lambda函数之外的数据。这就为针对集合操作带来了很大的便利。在作用上，Lambda表达式类似于函数指针和函数对象，Lambda表达式很好地兼顾了函数指针和函数对象的优点，却没有它们的缺点。相对于函数指针或是函数对象复杂的语法形式，Lambda表达式使用非常简单的语法就可以实现同样的功能，降低了Lambda表达式的学习难度，避免了使用复杂的函数对象或是函数指针所带来的错误。我们可以看一个实际的例子：</p>
<div style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; PADDING-BOTTOM: 4px; PADDING-LEFT: 5.4pt; WIDTH: 98%; PADDING-RIGHT: 5.4pt; BACKGROUND: #e6e6e6; WORD-BREAK: break-all; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid; PADDING-TOP: 4px">
<div><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="COLOR: #000000">//</span><span style="COLOR: #000000"> LambdaDemo.cpp : Defines the entry point </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> the console application.<br></span><span style="COLOR: #000000">//</span><span style="COLOR: #000000"><br><br>#include </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">stdafx.h</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000"><br>#include </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">algorithm</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">ostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">vector</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><br></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000"> std;<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> _tmain(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> argc, _TCHAR</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> argv[])<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> v;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">0</span><span style="COLOR: #000000">; i </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">10</span><span style="COLOR: #000000">; </span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">i) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;v.push_back(i);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for_each(v.begin(), v.end(), [] (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> n) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> n;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (n % </span><span style="COLOR: #800080">2</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">0</span><span style="COLOR: #000000">) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000"> even </span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">;<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;&nbsp;&nbsp;&nbsp;&nbsp;cout </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000"> odd </span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;});<br>&nbsp;&nbsp;&nbsp;&nbsp;cout </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> endl;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">0</span><span style="COLOR: #000000">;<br>}</span></div>
</div>
<div><br>&nbsp; 这段代码循环遍历输出vector中的每一个数，并判断这个数是奇数还是偶数。我们可以随时修改Lambda表达式而改变这个匿名函数的实现，修改对集合的操作。在这段代码中，C++使用一对中括号&#8220;[]&#8221;来表示Lambda表达式的开始，其后的&#8221;(int n)&#8221;表示Lambda表达式的参数。这些参数将在Lambda表达式中使用到。为了体会Lambda表达式的简洁，我们来看看同样的功能，如何使用函数对象实现：<br>&nbsp;</div>
<div style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; PADDING-BOTTOM: 4px; PADDING-LEFT: 5.4pt; WIDTH: 98%; PADDING-RIGHT: 5.4pt; BACKGROUND: #e6e6e6; WORD-BREAK: break-all; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid; PADDING-TOP: 4px">
<div><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="COLOR: #000000">#include </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">stdafx.h</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000"><br>#include </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">algorithm</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">ostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">vector</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000"> std;<br><br>struct LambdaFunctor {<br>&nbsp;&nbsp;&nbsp;&nbsp;void operator()(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> n) </span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"> {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> n </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> </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;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (n % </span><span style="COLOR: #800080">2</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">0</span><span style="COLOR: #000000">) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000"> even </span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">;<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;&nbsp;&nbsp;&nbsp;&nbsp;cout </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000"> odd </span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>};<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> _tmain(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> argc, _TCHAR</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> argv[])<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;vector</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> v;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">0</span><span style="COLOR: #000000">; i </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">10</span><span style="COLOR: #000000">; </span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">i) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;v.push_back(i);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;for_each(v.begin(), v.end(), LambdaFunctor());<br>&nbsp;&nbsp;&nbsp;&nbsp;cout </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> endl;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">0</span><span style="COLOR: #000000">;<br>}</span></div>
</div>
<p>&nbsp; 通过比较我们就可以发现，Lambda表达式的语法更加简洁，使用起来更加简单高效。<br><br><strong>静态断言static_assert<br><br></strong>&nbsp; 在之前的C++标准C++03中，我们可以使用两种断言：<br>&nbsp; &#8226;&nbsp;使用预处理中的条件编译和#error指令，可以在预处理阶段检查一些编译条件<br>&nbsp; &#8226;&nbsp;可以使用宏assert来进行运行时检查，以确保程序逻辑的正确性<br><br>&nbsp; 但使用#error方法是非常烦琐的，并且不能够对模板参数进行检查，因为模板实例化是在编译时进行，而#error方法是在预处理阶段进行的。而assert宏是在运行时进行检查。不难发现，我们缺少了一样东西，那就是可用于在编译时检查的工具。于是，静态断言应运而生。<br><br>&nbsp; 在新的C++标准C++0x中，加入了对静态断言的支持，引入了新的关键字static_assert来表示静态断言。使用静态断言，我们可以在程序的编译时期检测一些条件是否成立，这个特性在调试模板函数的模板参数时特别有用。在编译的时候，模板函数实例化，这时我们就可以使用静态断言去测试模板函数的参数是否按照我们的设计拥有合适的值。例如下面这段代码：</p>
<div style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; PADDING-BOTTOM: 4px; PADDING-LEFT: 5.4pt; WIDTH: 98%; PADDING-RIGHT: 5.4pt; BACKGROUND: #e6e6e6; WORD-BREAK: break-all; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid; PADDING-TOP: 4px">
<div><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="COLOR: #000000">template </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> N</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> struct Kitten {<br>&nbsp;&nbsp;&nbsp;&nbsp;static_assert(N </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">2</span><span style="COLOR: #000000">, </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">Kitten&lt;N&gt; requires N &lt; 2.</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">);<br>};<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> main() {<br>&nbsp;&nbsp;&nbsp;&nbsp;Kitten</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #800080">1</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> peppermint;<br>&nbsp;&nbsp;&nbsp;&nbsp;Kitten</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #800080">3</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> jazz;<br><br>&nbsp;&nbsp; </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">0</span><span style="COLOR: #000000">;<br>}</span></div>
</div>
<p>&nbsp; 当我们在主函数中使用&#8220;1&#8221;去实例化Kitten这个结构体时，在编译的时候，静态断言static_assert会测试参数N的值，当N的值小于2时就会产生一个断言错误，并将相应的调试帮助信息输出到&#8220;Error List&#8221;窗口中，这样程序员就可以对问题快速定位，解决问题就更加方便了。<br>&nbsp;</p>
<p style="TEXT-ALIGN: center"><img style="WIDTH: 521px; HEIGHT: 171px" border=0 alt="" src="http://image4.it168.com/2008/12/24/99c76e78-a0d4-4112-9bc3-acddcf64dad0.jpg" width=537 height=291><br>图2 static_assert断言及其输出</p>
<p style="TEXT-ALIGN: left"><br>&nbsp; 另外，静态断言还带来很多其他的优势。例如静态断言在编译时进行处理，不会产生任何运行时刻空间和时间上的开销，这就使得它比assert宏具有更好的效率。另外比较重要的一个特性是如果断言失败，它会产生有意义且充分的诊断信息，帮助程序员快速解决问题。<br><br><strong>&nbsp; auto关键字<br></strong><br>&nbsp; 在C++0x中，auto关键字的意义发生了改变。从Visual C++ 2010开始，auto关键字将用于指引编译器根据变量的初始值来决定变量的数据类型。换句话说，我们可以把auto当成一种新的数据类型，它可以&#8220;从初始化器(initialize)中推导出所代表的变量的真正类型&#8221;。这种对auto关键字的使用方式可以大大消除当前替代方式所导致的冗长和易出错的代码。我们看一个实际的例子：</p>
<div style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; PADDING-BOTTOM: 4px; PADDING-LEFT: 5.4pt; WIDTH: 98%; PADDING-RIGHT: 5.4pt; BACKGROUND: #e6e6e6; WORD-BREAK: break-all; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid; PADDING-TOP: 4px">
<div><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="COLOR: #000000">#include </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">map</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">ostream</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">regex</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br>#include </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000"> std;<br></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000"> std::tr1;<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> main() {<br>&nbsp;&nbsp;&nbsp;&nbsp;map</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">, </span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> m;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"> regex r(</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">(\\w+) (\\w+)</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000"> s; getline(cin, s); ) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;smatch results;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (regex_match(s, results, r)) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m[results[</span><span style="COLOR: #800080">1</span><span style="COLOR: #000000">]] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> results[</span><span style="COLOR: #800080">2</span><span style="COLOR: #000000">];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">auto</span><span style="COLOR: #000000"> i </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> m.begin(); i !</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> m.end(); </span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">i) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #0000ff">second</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000"> are </span><span style="COLOR: #800000">"</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">first </span><span style="COLOR: #000000">&lt;&lt;</span><span style="COLOR: #000000"> endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">0</span><span style="COLOR: #000000">;<br>}</span></div>
</div>
<p>&nbsp; 在这段代码中，我们使用auto关键字来代替了真正的数据类型map&lt;string, string&gt;::iterator，这使得整个代码自然而简洁。<br><br>&nbsp; 另外，跟其他数据类型一样，我们也可以对auto关键字进行修饰，例如添加const，指针(*)，左值引用(&amp;)，右值引用(&amp;&amp;)等等，编译器会根据auto类型所代表的真正的数据来决定这些修饰的具体含义。<br><br>&nbsp; 为了兼容一些旧有的C++代码，我们可以使用/Zc:auto这个编译器选项，来告诉编译器是采用auto关键字的原有定义还是在新标准C++0x中的定义。</p>
<strong>右值引用<br><br></strong>&nbsp; 作为最重要的一项语言特性，右值引用(rvalue references)被引入到 C++0x中。我们可以通过操作符&#8220;&amp;&amp;&#8221;来声明一个右值引用，原先在C++中使用&#8220;&amp;&#8221;操作符声明的引用现在被称为左值引用。&nbsp;
<div style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; PADDING-BOTTOM: 4px; PADDING-LEFT: 5.4pt; WIDTH: 98%; PADDING-RIGHT: 5.4pt; BACKGROUND: #e6e6e6; WORD-BREAK: break-all; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid; PADDING-TOP: 4px">
<div><!--<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"> a;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000"> a_lvref </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> a;&nbsp;&nbsp;</span><span style="COLOR: #000000">//</span><span style="COLOR: #000000"> 左值引用<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> b;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000"> b_rvref </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> b;&nbsp;&nbsp;</span><span style="COLOR: #000000">//</span><span style="COLOR: #000000"> 右值应用</span></div>
</div>
<p>&nbsp; 左值引用和右值引用的表现行为基本一致，它们唯一的差别就是右值引用可以绑定到一个临时对象(右值)上，而左值引用不可以。例如：&nbsp;</p>
<div style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; PADDING-BOTTOM: 4px; PADDING-LEFT: 5.4pt; WIDTH: 98%; PADDING-RIGHT: 5.4pt; BACKGROUND: #e6e6e6; WORD-BREAK: break-all; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid; PADDING-TOP: 4px">
<div><!--<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">&amp;</span><span style="COLOR: #000000"> a_lvref </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #000000">//</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">error</span><span style="COLOR: #000000"> C2440: </span><span style="COLOR: #008000">'</span><span style="COLOR: #008000">initializing' : cannot convert from 'int' to 'int &amp;'&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000"><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000"> b_rvref </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">();&nbsp;&nbsp;</span><span style="COLOR: #000000">//</span><span style="COLOR: #000000"> OK!</span></div>
</div>
<p>&nbsp; 在第一行代码中，我们将一个临时对象int()绑定到一个左值引用，将产生一个编译错误。而在第二行中，我们将临时对象绑定到右值引用，就可以顺利通过编译。<br><br>&nbsp; 右值是无名的数据，例如函数的返回值一般说来就是右值。当对右值进行操作的时候，右值本身往往没有必要保留，因此在某些情况下可以直接&#8220;移动&#8221;之。通过右值引用，程序可以明确的区分出传入的参数是否为右值，从而避免了不必要的拷贝，程序的效率也就得到了提高。我们考虑一个简单的数据交换的小程序，从中来体会右值引用所带来的效率提升。我们可以写一个函数swap来实现两个变量值的交换：</p>
<div style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; PADDING-BOTTOM: 4px; PADDING-LEFT: 5.4pt; WIDTH: 98%; PADDING-RIGHT: 5.4pt; BACKGROUND: #e6e6e6; WORD-BREAK: break-all; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid; PADDING-TOP: 4px">
<div><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="COLOR: #000000">template </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> T</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> swap(T</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000"> a, T</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000"> b)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;T tmp(a);&nbsp;&nbsp; </span><span style="COLOR: #000000">//</span><span style="COLOR: #000000"> tmp对象创建后，我们就拥有了a的两份拷贝<br>&nbsp;&nbsp;&nbsp;&nbsp;a </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> b;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #000000">//</span><span style="COLOR: #000000"> 现在我们拥有b的两份拷贝<br>&nbsp;&nbsp;&nbsp;&nbsp;b </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> tmp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #000000">//</span><span style="COLOR: #000000"> 现在我们拥有a的两份拷贝<br>}</span></div>
</div>
<p>&nbsp; 在这段代码中，虽然我们只是为了进行简单的数据交换，但是却执行了多次对象拷贝。这些对象的拷贝操作，特别是当这些对象比较大的时候，无疑会影响程序的效率。<br><br>&nbsp; 那么，如果使用右值引用如何实现呢？</p>
<div style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; PADDING-BOTTOM: 4px; PADDING-LEFT: 5.4pt; WIDTH: 98%; PADDING-RIGHT: 5.4pt; BACKGROUND: #e6e6e6; WORD-BREAK: break-all; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid; PADDING-TOP: 4px">
<div><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="COLOR: #000000">//</span><span style="COLOR: #000000"> RValueRef.cpp : Defines the entry point </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> the console application.<br></span><span style="COLOR: #000000">//</span><span style="COLOR: #000000"><br><br>#include </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">stdafx.h</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000"><br><br>template </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> T</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> <br>T</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000"> move(T</span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000"> a)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> a;<br>}<br><br>template </span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> T</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> void swap(T</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000"> a, T</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000"> b)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;T tmp(move(a)); </span><span style="COLOR: #000000">//</span><span style="COLOR: #000000"> 对象a被移动到对象tmp，a被清空<br>&nbsp;&nbsp;&nbsp;&nbsp;a </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> move(b);&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #000000">//</span><span style="COLOR: #000000"> 对象b被移动到对象a，b被清空<br>&nbsp;&nbsp;&nbsp;&nbsp;b </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> move(tmp);&nbsp;&nbsp;</span><span style="COLOR: #000000">//</span><span style="COLOR: #000000"> 对象tmp被移动到对象b<br>}<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> _tmain(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> argc, _TCHAR</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> argv[])<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> a </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">1</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> b </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">2</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;swap(a, b);<br><br>&nbsp;&nbsp; </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">0</span><span style="COLOR: #000000">;<br>}</span></div>
</div>
<p>&nbsp; 在这段重新实现的代码中，我们使用了一个move()函数来代替对象的赋值操作符&#8220;=&#8221;,move()只是简单地接受一个右值引用或者左值引用作为参数，然后直接返回相应对象的右值引用。这一过程不会产生拷贝(Copy)操作，而只会将源对象移动(Move)到目标对象。<br><br>&nbsp; 正是拷贝(Copy)和移动(Move)的差别，使得右值引用成为C++0x中最激动人心的新特性之一。从实践角度讲，它能够完美是解决C++中长久以来为人所诟病的临时对象的效率问题。从语言本身讲，它健全了C++中的引用类型在左值右值方面的缺陷。从库设计者的角度讲，它给库设计者又带来了一把利器。而对于广大的库使用者而言，不动一兵一卒便能够获得&#8220;免费的&#8221;效率提升。<br><br>&nbsp; 在Visual Studio 2010中，因为有了对这些C++0x新特性的支持，重新点燃了程序员们对C++的热情。C++重振雄风，指日可待！</p>
<img src ="http://www.cppblog.com/kyline/aggbug/81217.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/kyline/" target="_blank">谷主</a> 2009-04-27 16:02 <a href="http://www.cppblog.com/kyline/archive/2009/04/27/81217.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>直接的VS 2005 远程调试</title><link>http://www.cppblog.com/kyline/archive/2009/04/23/80821.html</link><dc:creator>谷主</dc:creator><author>谷主</author><pubDate>Thu, 23 Apr 2009 03:34:00 GMT</pubDate><guid>http://www.cppblog.com/kyline/archive/2009/04/23/80821.html</guid><wfw:comment>http://www.cppblog.com/kyline/comments/80821.html</wfw:comment><comments>http://www.cppblog.com/kyline/archive/2009/04/23/80821.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/kyline/comments/commentRss/80821.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/kyline/services/trackbacks/80821.html</trackback:ping><description><![CDATA[<h2>VS2005中远程调试的配置方法</h2>
<div id=message12869 class=t_msgfont>
<div id=firstpost>在VS2005中不能使用VS2003的远程调试程序。VS2005远程调试的方法：<br>(1) 远程端：安装VS2005光盘"X:\vs\Remote Debugger\x86\ rdbgsetup.exe"。或者直接运行或copy本地端的： "Program Files\Microsoft Visual Studio 8\Common7\IDE\Remote Debugger\x86"<br>(2) 远程端：&#8220;本地安全策略 － 安全选项 － 网络访问：本地帐户的共享和安全模式&#8221;改为：经典－本地用户以自己的身份验证。<br>(3) 远程端：启动Remote Debuger，从&#8220;工具 － 选项&#8221;中将身份验证模式改为&#8220;无身份验证，允许任何用户进行调试&#8221;。<br>或者直接用命令行："X:\ msvsmon.exe" /noauth /anyuser /nosecuritywarn，可以建个快捷方式以方便运行。<br>(4) 本地：在VS2005中，&#8220;工具&#8221;－－&#8220;附加到进程&#8221;，传输选&#8220;远程&#8221;，限定符输入远程端的主机名或IP地址，回车，终于出来了可爱的进程列表。<br>小结：跟VS2003相比，2005的远程调试的配置要稍麻烦一些，不过有一点重要的进步是它可以配置成服务，不像在2003下面要做繁琐的手工配置。</div>
</div>
<br>整那么多都没有没有用的！
<img src ="http://www.cppblog.com/kyline/aggbug/80821.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/kyline/" target="_blank">谷主</a> 2009-04-23 11:34 <a href="http://www.cppblog.com/kyline/archive/2009/04/23/80821.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>GDI+绘图</title><link>http://www.cppblog.com/kyline/archive/2009/04/10/79513.html</link><dc:creator>谷主</dc:creator><author>谷主</author><pubDate>Fri, 10 Apr 2009 07:54:00 GMT</pubDate><guid>http://www.cppblog.com/kyline/archive/2009/04/10/79513.html</guid><wfw:comment>http://www.cppblog.com/kyline/comments/79513.html</wfw:comment><comments>http://www.cppblog.com/kyline/archive/2009/04/10/79513.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/kyline/comments/commentRss/79513.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/kyline/services/trackbacks/79513.html</trackback:ping><description><![CDATA[<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #000000">Graphics&nbsp;&nbsp;&nbsp;&nbsp;graphics(hdc);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;GraphicsPath&nbsp;path;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;LinearGradientBrush&nbsp;linGrBrushB(<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Point(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">70</span><span style="COLOR: #000000">),<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Point(</span><span style="COLOR: #000000">140</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">70</span><span style="COLOR: #000000">),<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Color(</span><span style="COLOR: #000000">255</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">),&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;opaque&nbsp;red</span><span style="COLOR: #008000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Color(</span><span style="COLOR: #000000">255</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">255</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">255</span><span style="COLOR: #000000">));&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;opaque&nbsp;blue</span><span style="COLOR: #008000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;LinearGradientBrush&nbsp;linGrBrushF(<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Point(</span><span style="COLOR: #000000">20</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">70</span><span style="COLOR: #000000">),<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Point(</span><span style="COLOR: #000000">120</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">70</span><span style="COLOR: #000000">),<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Color(</span><span style="COLOR: #000000">255</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">255</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">255</span><span style="COLOR: #000000">),&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;opaque&nbsp;red</span><span style="COLOR: #008000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Color(</span><span style="COLOR: #000000">255</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">));&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;opaque&nbsp;blue</span><span style="COLOR: #008000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;graphics.FillEllipse(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">linGrBrushB,&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">140</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">140</span><span style="COLOR: #000000">);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;graphics.FillEllipse(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">linGrBrushF,&nbsp;</span><span style="COLOR: #000000">20</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">20</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Play</span><span style="COLOR: #008000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;SolidBrush&nbsp;&nbsp;brush(Color(</span><span style="COLOR: #000000">255</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">255</span><span style="COLOR: #000000">));<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;FontFamily&nbsp;&nbsp;fontFamily(L</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Times&nbsp;New&nbsp;Roman</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;Font&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;font(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">fontFamily,&nbsp;</span><span style="COLOR: #000000">24</span><span style="COLOR: #000000">,&nbsp;FontStyleRegular,&nbsp;UnitPixel);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;PointF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pointF(</span><span style="COLOR: #000000">49.0f</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">58.0f</span><span style="COLOR: #000000">);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">&nbsp;&nbsp;&nbsp;&nbsp;graphics.DrawString(L</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Play</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">font,&nbsp;pointF,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">brush);</span></div>
<img border=0 alt="" src="http://www.cppblog.com/images/cppblog_com/kyline/GDI.jpg" width=141 height=140>
<img src ="http://www.cppblog.com/kyline/aggbug/79513.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/kyline/" target="_blank">谷主</a> 2009-04-10 15:54 <a href="http://www.cppblog.com/kyline/archive/2009/04/10/79513.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>How To Play a File use DirectShow?</title><link>http://www.cppblog.com/kyline/archive/2009/04/09/79325.html</link><dc:creator>谷主</dc:creator><author>谷主</author><pubDate>Thu, 09 Apr 2009 02:26:00 GMT</pubDate><guid>http://www.cppblog.com/kyline/archive/2009/04/09/79325.html</guid><wfw:comment>http://www.cppblog.com/kyline/comments/79325.html</wfw:comment><comments>http://www.cppblog.com/kyline/archive/2009/04/09/79325.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/kyline/comments/commentRss/79325.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/kyline/services/trackbacks/79325.html</trackback:ping><description><![CDATA[<br>DirectShow application always performs the same basic steps:
<ol>
    <li>Create an instance of the <a href="ms-help://MS.LHSMSSDK.1033/MS.LHSWinSDK.1033/directshow/htm/filtergraphmanager.htm">Filter Graph Manager</a>.
    <li>Use the Filter Graph Manager to build a filter graph.
    <li>Run the graph, causing data to move through the filters. </li>
</ol>
<p>Start by calling <strong>CoInitialize</strong> to initialize the COM library:</p>
<pre class=syntax>HRESULT hr = CoInitialize(NULL);
if (FAILED(hr))
{
// Add error-handling code here. (Omitted for clarity.)
}
</pre>
<p>To keep things simple, this example ignores the return value, but you should always check the <strong>HRESULT</strong> value from any method call. </p>
<p>Next, call <strong>CoCreateInstance</strong> to create the Filter Graph Manager:</p>
<pre class=syntax>IGraphBuilder *pGraph;
HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL,
CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&amp;pGraph);
</pre>
<p>As shown, the class identifier (CLSID) is CLSID_FilterGraph. The Filter Graph Manager is provided by an in-process DLL, so the execution context is CLSCTX_INPROC_SERVER. DirectShow supports the free-threading model, so you can also call <strong>CoInitializeEx</strong> with the COINIT_MULTITHREADED flag.</p>
<p>The call to <strong>CoCreateInstance</strong> returns the <a href="ms-help://MS.LHSMSSDK.1033/MS.LHSWinSDK.1033/directshow/htm/igraphbuilderinterface.htm"><strong>IGraphBuilder</strong></a> interface, which mostly contains methods for building the filter graph. Two other interfaces are needed for this example:
<ul type=disc>
    <li><a href="ms-help://MS.LHSMSSDK.1033/MS.LHSWinSDK.1033/directshow/htm/imediacontrolinterface.htm"><strong>IMediaControl</strong></a> controls streaming. It contains methods for stopping and starting the graph.
    <li><a href="ms-help://MS.LHSMSSDK.1033/MS.LHSWinSDK.1033/directshow/htm/imediaeventinterface.htm"><strong>IMediaEvent</strong></a> has methods for getting events from the Filter Graph Manager. In this example, the interface is used to wait for playback to complete. </li>
</ul>
<p>Both of these interfaces are exposed by the Filter Graph Manager. Use the returned <strong>IGraphBuilder</strong> pointer to query for them:</p>
<pre class=syntax>IMediaControl *pControl;
IMediaEvent   *pEvent;
hr = pGraph-&gt;QueryInterface(IID_IMediaControl, (void **)&amp;pControl);
hr = pGraph-&gt;QueryInterface(IID_IMediaEvent, (void **)&amp;pEvent);
</pre>
<p>Now you can build the filter graph. For file playback, this is done by a single method call:</p>
<pre class=syntax>hr = pGraph-&gt;RenderFile(L"C:\\Example.avi", NULL);
</pre>
<p>The <a href="ms-help://MS.LHSMSSDK.1033/MS.LHSWinSDK.1033/directshow/htm/igraphbuilderrenderfile.htm"><strong>IGraphBuilder::RenderFile</strong></a> method builds a filter graph that can play the specified file. The first parameter is the file name, represented as a wide character (2-byte) string. The second parameter is reserved and must equal NULL.</p>
<p>This method can fail if the specified file does not exist, or the file format is not recognized. Assuming that the method succeeds, however, the filter graph is now ready for playback. To run the graph, call the <a href="ms-help://MS.LHSMSSDK.1033/MS.LHSWinSDK.1033/directshow/htm/imediacontrolrun.htm"><strong>IMediaControl::Run</strong></a> method:</p>
<pre class=syntax>hr = pControl-&gt;Run();
</pre>
<p>When the filter graph runs, data moves through the filters and is rendered as video and audio. Playback occurs on a separate thread. You can wait for playback to complete by calling the <a href="ms-help://MS.LHSMSSDK.1033/MS.LHSWinSDK.1033/directshow/htm/imediaeventwaitforcompletion.htm"><strong>IMediaEvent::WaitForCompletion</strong></a> method:</p>
<pre class=syntax>long evCode = 0;
pEvent-&gt;WaitForCompletion(INFINITE, &amp;evCode);
</pre>
<p>This method blocks until the file is done playing, or until the specified time-out interval elapses. The value INFINITE means the application blocks indefinitely until the file is done playing. For a more realistic example of event handling, see <a href="ms-help://MS.LHSMSSDK.1033/MS.LHSWinSDK.1033/directshow/htm/respondingtoevents.htm">Responding to Events</a>.</p>
<p>When the application is finished, release the interface pointers and close the COM library:</p>
<pre class=syntax>pControl-&gt;Release();
pEvent-&gt;Release();
pGraph-&gt;Release();
CoUninitialize();
</pre>
<p class=blue><strong>Sample Code</strong></p>
<p>Here is the complete code for the example described in this article: </p>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">dshow.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;main(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">)<br><img id=Codehighlighter1_37_1388_Open_Image onclick="this.style.display='none'; Codehighlighter1_37_1388_Open_Text.style.display='none'; Codehighlighter1_37_1388_Closed_Image.style.display='inline'; Codehighlighter1_37_1388_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_37_1388_Closed_Image onclick="this.style.display='none'; Codehighlighter1_37_1388_Closed_Text.style.display='none'; Codehighlighter1_37_1388_Open_Image.style.display='inline'; Codehighlighter1_37_1388_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_37_1388_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_37_1388_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;IGraphBuilder&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">pGraph&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;NULL;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;IMediaControl&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">pControl&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;NULL;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;IMediaEvent&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">pEvent&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;NULL;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;Initialize&nbsp;the&nbsp;COM&nbsp;library.</span><span style="COLOR: #008000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;HRESULT&nbsp;hr&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;CoInitialize(NULL);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(FAILED(hr))<br><img id=Codehighlighter1_240_322_Open_Image onclick="this.style.display='none'; Codehighlighter1_240_322_Open_Text.style.display='none'; Codehighlighter1_240_322_Closed_Image.style.display='inline'; Codehighlighter1_240_322_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_240_322_Closed_Image onclick="this.style.display='none'; Codehighlighter1_240_322_Closed_Text.style.display='none'; Codehighlighter1_240_322_Open_Image.style.display='inline'; Codehighlighter1_240_322_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_240_322_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_240_322_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">ERROR&nbsp;-&nbsp;Could&nbsp;not&nbsp;initialize&nbsp;COM&nbsp;library</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;Create&nbsp;the&nbsp;filter&nbsp;graph&nbsp;manager&nbsp;and&nbsp;query&nbsp;for&nbsp;interfaces.</span><span style="COLOR: #008000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;hr&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;CoCreateInstance(CLSID_FilterGraph,&nbsp;NULL,&nbsp;CLSCTX_INPROC_SERVER,&nbsp;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IID_IGraphBuilder,&nbsp;(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">**</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">pGraph);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(FAILED(hr))<br><img id=Codehighlighter1_550_642_Open_Image onclick="this.style.display='none'; Codehighlighter1_550_642_Open_Text.style.display='none'; Codehighlighter1_550_642_Closed_Image.style.display='inline'; Codehighlighter1_550_642_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_550_642_Closed_Image onclick="this.style.display='none'; Codehighlighter1_550_642_Closed_Text.style.display='none'; Codehighlighter1_550_642_Open_Image.style.display='inline'; Codehighlighter1_550_642_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_550_642_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_550_642_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">ERROR&nbsp;-&nbsp;Could&nbsp;not&nbsp;create&nbsp;the&nbsp;Filter&nbsp;Graph&nbsp;Manager.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;hr&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;pGraph</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">QueryInterface(IID_IMediaControl,&nbsp;(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">**</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">pControl);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;hr&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;pGraph</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">QueryInterface(IID_IMediaEvent,&nbsp;(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">**</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">pEvent);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;Build&nbsp;the&nbsp;graph.&nbsp;IMPORTANT:&nbsp;Change&nbsp;this&nbsp;string&nbsp;to&nbsp;a&nbsp;file&nbsp;on&nbsp;your&nbsp;system.</span><span style="COLOR: #008000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;hr&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;pGraph</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">RenderFile(L</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">C:\\Example.avi</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;NULL);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(SUCCEEDED(hr))<br><img id=Codehighlighter1_950_1293_Open_Image onclick="this.style.display='none'; Codehighlighter1_950_1293_Open_Text.style.display='none'; Codehighlighter1_950_1293_Closed_Image.style.display='inline'; Codehighlighter1_950_1293_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_950_1293_Closed_Image onclick="this.style.display='none'; Codehighlighter1_950_1293_Closed_Text.style.display='none'; Codehighlighter1_950_1293_Open_Image.style.display='inline'; Codehighlighter1_950_1293_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_950_1293_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_950_1293_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;Run&nbsp;the&nbsp;graph.</span><span style="COLOR: #008000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hr&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;pControl</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">Run();<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(SUCCEEDED(hr))<br><img id=Codehighlighter1_1043_1287_Open_Image onclick="this.style.display='none'; Codehighlighter1_1043_1287_Open_Text.style.display='none'; Codehighlighter1_1043_1287_Closed_Image.style.display='inline'; Codehighlighter1_1043_1287_Closed_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_1043_1287_Closed_Image onclick="this.style.display='none'; Codehighlighter1_1043_1287_Closed_Text.style.display='none'; Codehighlighter1_1043_1287_Open_Image.style.display='inline'; Codehighlighter1_1043_1287_Open_Text.style.display='inline';" align=top src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_1043_1287_Closed_Text><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_1043_1287_Open_Text><span style="COLOR: #000000">{<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;Wait&nbsp;for&nbsp;completion.</span><span style="COLOR: #008000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;evCode;<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pEvent</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">WaitForCompletion(INFINITE,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">evCode);<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;Note:&nbsp;Do&nbsp;not&nbsp;use&nbsp;INFINITE&nbsp;in&nbsp;a&nbsp;real&nbsp;application,&nbsp;because&nbsp;it<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;can&nbsp;block&nbsp;indefinitely.</span><span style="COLOR: #008000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif"></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;pControl</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">Release();<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;pEvent</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">Release();<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;pGraph</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">Release();<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;CoUninitialize();<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span></div>
<img src ="http://www.cppblog.com/kyline/aggbug/79325.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/kyline/" target="_blank">谷主</a> 2009-04-09 10:26 <a href="http://www.cppblog.com/kyline/archive/2009/04/09/79325.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>哈哈，快要考研了</title><link>http://www.cppblog.com/kyline/archive/2009/04/09/79319.html</link><dc:creator>谷主</dc:creator><author>谷主</author><pubDate>Thu, 09 Apr 2009 01:44:00 GMT</pubDate><guid>http://www.cppblog.com/kyline/archive/2009/04/09/79319.html</guid><wfw:comment>http://www.cppblog.com/kyline/comments/79319.html</wfw:comment><comments>http://www.cppblog.com/kyline/archive/2009/04/09/79319.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/kyline/comments/commentRss/79319.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/kyline/services/trackbacks/79319.html</trackback:ping><description><![CDATA[都快被高斯公式搞死了!!
<img src ="http://www.cppblog.com/kyline/aggbug/79319.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/kyline/" target="_blank">谷主</a> 2009-04-09 09:44 <a href="http://www.cppblog.com/kyline/archive/2009/04/09/79319.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>