﻿<?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++博客-VC++ C++ C# Algorithm </title><link>http://www.cppblog.com/mrcplusplus/</link><description /><language>zh-cn</language><lastBuildDate>Sun, 05 Apr 2026 20:08:35 GMT</lastBuildDate><pubDate>Sun, 05 Apr 2026 20:08:35 GMT</pubDate><ttl>60</ttl><item><title>用递规方法解决Hanoi问题</title><link>http://www.cppblog.com/mrcplusplus/archive/2007/03/15/19907.html</link><dc:creator>大熊猫</dc:creator><author>大熊猫</author><pubDate>Thu, 15 Mar 2007 08:46:00 GMT</pubDate><guid>http://www.cppblog.com/mrcplusplus/archive/2007/03/15/19907.html</guid><wfw:comment>http://www.cppblog.com/mrcplusplus/comments/19907.html</wfw:comment><comments>http://www.cppblog.com/mrcplusplus/archive/2007/03/15/19907.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mrcplusplus/comments/commentRss/19907.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mrcplusplus/services/trackbacks/19907.html</trackback:ping><description><![CDATA[
		<p> </p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> move(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> number,</span>
				<span style="COLOR: #0000ff">char</span>
				<span style="COLOR: #000000"> from,</span>
				<span style="COLOR: #0000ff">char</span>
				<span style="COLOR: #000000"> rely,</span>
				<span style="COLOR: #0000ff">char</span>
				<span style="COLOR: #000000"> to)<br /><img id="Codehighlighter1_50_218_Open_Image" onclick="this.style.display='none'; Codehighlighter1_50_218_Open_Text.style.display='none'; Codehighlighter1_50_218_Closed_Image.style.display='inline'; Codehighlighter1_50_218_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_50_218_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_50_218_Closed_Text.style.display='none'; Codehighlighter1_50_218_Open_Image.style.display='inline'; Codehighlighter1_50_218_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_50_218_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_50_218_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000">(number </span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_70_133_Open_Image" onclick="this.style.display='none'; Codehighlighter1_70_133_Open_Text.style.display='none'; Codehighlighter1_70_133_Closed_Image.style.display='inline'; Codehighlighter1_70_133_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_70_133_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_70_133_Closed_Text.style.display='none'; Codehighlighter1_70_133_Open_Image.style.display='inline'; Codehighlighter1_70_133_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_70_133_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_70_133_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        printf(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">Move a disk from %c to %c\n</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">,from,to);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    move(number</span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">,from,to,rely);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    move(</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">,from,rely,to);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    move(number</span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">,rely,from,to);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</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 /><img id="Codehighlighter1_258_313_Open_Image" onclick="this.style.display='none'; Codehighlighter1_258_313_Open_Text.style.display='none'; Codehighlighter1_258_313_Closed_Image.style.display='inline'; Codehighlighter1_258_313_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_258_313_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_258_313_Closed_Text.style.display='none'; Codehighlighter1_258_313_Open_Image.style.display='inline'; Codehighlighter1_258_313_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_258_313_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_258_313_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    move(</span>
						<span style="COLOR: #000000">3</span>
						<span style="COLOR: #000000">,</span>
						<span style="COLOR: #000000">'</span>
						<span style="COLOR: #000000">A</span>
						<span style="COLOR: #000000">'</span>
						<span style="COLOR: #000000">,</span>
						<span style="COLOR: #000000">'</span>
						<span style="COLOR: #000000">B</span>
						<span style="COLOR: #000000">'</span>
						<span style="COLOR: #000000">,</span>
						<span style="COLOR: #000000">'</span>
						<span style="COLOR: #000000">C</span>
						<span style="COLOR: #000000">'</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    ::system(</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">pause</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
		</div>
		<p> </p>
		<p> </p>
<img src ="http://www.cppblog.com/mrcplusplus/aggbug/19907.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mrcplusplus/" target="_blank">大熊猫</a> 2007-03-15 16:46 <a href="http://www.cppblog.com/mrcplusplus/archive/2007/03/15/19907.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>插入排序</title><link>http://www.cppblog.com/mrcplusplus/archive/2007/03/15/19902.html</link><dc:creator>大熊猫</dc:creator><author>大熊猫</author><pubDate>Thu, 15 Mar 2007 08:32:00 GMT</pubDate><guid>http://www.cppblog.com/mrcplusplus/archive/2007/03/15/19902.html</guid><wfw:comment>http://www.cppblog.com/mrcplusplus/comments/19902.html</wfw:comment><comments>http://www.cppblog.com/mrcplusplus/archive/2007/03/15/19902.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mrcplusplus/comments/commentRss/19902.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mrcplusplus/services/trackbacks/19902.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #008080"> 1</span>
				<img id="Codehighlighter1_10_35_Open_Image" onclick="this.style.display='none'; Codehighlighter1_10_35_Open_Text.style.display='none'; Codehighlighter1_10_35_Closed_Image.style.display='inline'; Codehighlighter1_10_35_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
				<img id="Codehighlighter1_10_35_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_10_35_Closed_Text.style.display='none'; Codehighlighter1_10_35_Open_Image.style.display='inline'; Codehighlighter1_10_35_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> A[</span>
				<span style="COLOR: #000000">10</span>
				<span style="COLOR: #000000">]</span>
				<span style="COLOR: #000000">=</span>
				<span id="Codehighlighter1_10_35_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_10_35_Open_Text">
						<span style="COLOR: #000000">{</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">,</span>
						<span style="COLOR: #000000">2</span>
						<span style="COLOR: #000000">,</span>
						<span style="COLOR: #000000">5</span>
						<span style="COLOR: #000000">,</span>
						<span style="COLOR: #000000">7</span>
						<span style="COLOR: #000000">,</span>
						<span style="COLOR: #000000">3</span>
						<span style="COLOR: #000000">,</span>
						<span style="COLOR: #000000">14</span>
						<span style="COLOR: #000000">,</span>
						<span style="COLOR: #000000">78</span>
						<span style="COLOR: #000000">,</span>
						<span style="COLOR: #000000">25</span>
						<span style="COLOR: #000000">,</span>
						<span style="COLOR: #000000">11</span>
						<span style="COLOR: #000000">,</span>
						<span style="COLOR: #000000">14</span>
						<span style="COLOR: #000000">}</span>
				</span>
				<span style="COLOR: #000000">;<br /></span>
				<span style="COLOR: #008080"> 2</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> InsertSort(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> a[],</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> size)<br /></span>
				<span style="COLOR: #008080"> 3</span>
				<span style="COLOR: #000000">
						<img id="Codehighlighter1_72_208_Open_Image" onclick="this.style.display='none'; Codehighlighter1_72_208_Open_Text.style.display='none'; Codehighlighter1_72_208_Closed_Image.style.display='inline'; Codehighlighter1_72_208_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
						<img id="Codehighlighter1_72_208_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_72_208_Closed_Text.style.display='none'; Codehighlighter1_72_208_Open_Image.style.display='inline'; Codehighlighter1_72_208_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				</span>
				<span id="Codehighlighter1_72_208_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_72_208_Open_Text">
						<span style="COLOR: #000000">{<br /></span>
						<span style="COLOR: #008080"> 4</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </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">1</span>
						<span style="COLOR: #000000">; i</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000">size; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">)<br /></span>
						<span style="COLOR: #008080"> 5</span>
						<span style="COLOR: #000000">
								<img id="Codehighlighter1_102_206_Open_Image" onclick="this.style.display='none'; Codehighlighter1_102_206_Open_Text.style.display='none'; Codehighlighter1_102_206_Closed_Image.style.display='inline'; Codehighlighter1_102_206_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_102_206_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_102_206_Closed_Text.style.display='none'; Codehighlighter1_102_206_Open_Image.style.display='inline'; Codehighlighter1_102_206_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_102_206_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_102_206_Open_Text">
								<span style="COLOR: #000000">{<br /></span>
								<span style="COLOR: #008080"> 6</span>
								<span style="COLOR: #000000">
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">int</span>
								<span style="COLOR: #000000"> key</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">a[i];<br /></span>
								<span style="COLOR: #008080"> 7</span>
								<span style="COLOR: #000000">
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">int</span>
								<span style="COLOR: #000000"> j</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">i</span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">;<br /></span>
								<span style="COLOR: #008080"> 8</span>
								<span style="COLOR: #000000">
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">while</span>
								<span style="COLOR: #000000">(a[j]</span>
								<span style="COLOR: #000000">&gt;</span>
								<span style="COLOR: #000000">key </span>
								<span style="COLOR: #000000">&amp;&amp;</span>
								<span style="COLOR: #000000"> j</span>
								<span style="COLOR: #000000">&gt;=</span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">)<br /></span>
								<span style="COLOR: #008080"> 9</span>
								<span style="COLOR: #000000">
										<img id="Codehighlighter1_161_189_Open_Image" onclick="this.style.display='none'; Codehighlighter1_161_189_Open_Text.style.display='none'; Codehighlighter1_161_189_Closed_Image.style.display='inline'; Codehighlighter1_161_189_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
										<img id="Codehighlighter1_161_189_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_161_189_Closed_Text.style.display='none'; Codehighlighter1_161_189_Open_Image.style.display='inline'; Codehighlighter1_161_189_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span id="Codehighlighter1_161_189_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_161_189_Open_Text">
										<span style="COLOR: #000000">{<br /></span>
										<span style="COLOR: #008080">10</span>
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            a[j</span>
										<span style="COLOR: #000000">+</span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">]</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000">a[j];<br /></span>
										<span style="COLOR: #008080">11</span>
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            j</span>
										<span style="COLOR: #000000">--</span>
										<span style="COLOR: #000000">;<br /></span>
										<span style="COLOR: #008080">12</span>
										<span style="COLOR: #000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
								</span>
								<span style="COLOR: #008080">13</span>
								<span style="COLOR: #000000">
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        a[j</span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">]</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">key;<br /></span>
								<span style="COLOR: #008080">14</span>
								<span style="COLOR: #000000">
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
						</span>
						<span style="COLOR: #008080">15</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #008080">16</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
				</span>
				<span style="COLOR: #008080">17</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</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 /></span>
				<span style="COLOR: #008080">18</span>
				<span style="COLOR: #000000">
						<img id="Codehighlighter1_248_376_Open_Image" onclick="this.style.display='none'; Codehighlighter1_248_376_Open_Text.style.display='none'; Codehighlighter1_248_376_Closed_Image.style.display='inline'; Codehighlighter1_248_376_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
						<img id="Codehighlighter1_248_376_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_248_376_Closed_Text.style.display='none'; Codehighlighter1_248_376_Open_Image.style.display='inline'; Codehighlighter1_248_376_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				</span>
				<span id="Codehighlighter1_248_376_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_248_376_Open_Text">
						<span style="COLOR: #000000">{<br /></span>
						<span style="COLOR: #008080">19</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
						</span>
						<span style="COLOR: #008080">20</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    InsertSort(A,</span>
						<span style="COLOR: #0000ff">sizeof</span>
						<span style="COLOR: #000000">(A)</span>
						<span style="COLOR: #000000">/</span>
						<span style="COLOR: #0000ff">sizeof</span>
						<span style="COLOR: #000000">(A[</span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">]));<br /></span>
						<span style="COLOR: #008080">21</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </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">0</span>
						<span style="COLOR: #000000">; i</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #000000">10</span>
						<span style="COLOR: #000000">; i</span>
						<span style="COLOR: #000000">++</span>
						<span style="COLOR: #000000">)<br /></span>
						<span style="COLOR: #008080">22</span>
						<span style="COLOR: #000000">
								<img id="Codehighlighter1_316_343_Open_Image" onclick="this.style.display='none'; Codehighlighter1_316_343_Open_Text.style.display='none'; Codehighlighter1_316_343_Closed_Image.style.display='inline'; Codehighlighter1_316_343_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_316_343_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_316_343_Closed_Text.style.display='none'; Codehighlighter1_316_343_Open_Image.style.display='inline'; Codehighlighter1_316_343_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_316_343_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_316_343_Open_Text">
								<span style="COLOR: #000000">{<br /></span>
								<span style="COLOR: #008080">23</span>
								<span style="COLOR: #000000">
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        printf(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">%d\n</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">,A[i]);<br /></span>
								<span style="COLOR: #008080">24</span>
								<span style="COLOR: #000000">
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
						</span>
						<span style="COLOR: #008080">25</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    ::system(</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">pause</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">);<br /></span>
						<span style="COLOR: #008080">26</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /></span>
						<span style="COLOR: #008080">27</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #008080">28</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
		</div>
<img src ="http://www.cppblog.com/mrcplusplus/aggbug/19902.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mrcplusplus/" target="_blank">大熊猫</a> 2007-03-15 16:32 <a href="http://www.cppblog.com/mrcplusplus/archive/2007/03/15/19902.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SDL游戏编程(8)鼠标事件</title><link>http://www.cppblog.com/mrcplusplus/archive/2007/03/12/19653.html</link><dc:creator>大熊猫</dc:creator><author>大熊猫</author><pubDate>Mon, 12 Mar 2007 12:10:00 GMT</pubDate><guid>http://www.cppblog.com/mrcplusplus/archive/2007/03/12/19653.html</guid><wfw:comment>http://www.cppblog.com/mrcplusplus/comments/19653.html</wfw:comment><comments>http://www.cppblog.com/mrcplusplus/archive/2007/03/12/19653.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/mrcplusplus/comments/commentRss/19653.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mrcplusplus/services/trackbacks/19653.html</trackback:ping><description><![CDATA[
		<p>很多游戏都是用鼠标控制的，所以说处理鼠标事件也是非常重要的，鼠标事件和键盘事件处理方式差的不太多，所以我就直接给出了一个小程序，该程序把窗口一分为二，当在左半部分移动时，左面部分就变绿色，右面部分变黑色，在右半部分移动时，该部分就变蓝色，左半部分就变成了黑色，当鼠标左击时，对应的部分将会变红色。<br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<font face="Courier New">
						<font size="2">
								<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
								<span style="COLOR: #000000">#include </span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">SDL.h</span>
								<span style="COLOR: #000000">"</span>
						</font>
				</font>
				<span style="COLOR: #000000">
						<br />
						<font face="Courier New" size="2">
								<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </font>
				</span>
				<font face="Courier New">
						<font size="2">
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">SDL_ttf.h</span>
								<span style="COLOR: #000000">"</span>
						</font>
				</font>
				<span style="COLOR: #000000">
						<br />
						<font face="Courier New" size="2">
								<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />SDL_Surface </font>
				</span>
				<font face="Courier New">
						<font size="2">
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">screen</span>
								<span style="COLOR: #000000">=</span>
						</font>
				</font>
				<font face="Courier New">
						<font size="2">
								<span style="COLOR: #000000">NULL;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />TTF_Font </span>
								<span style="COLOR: #000000">*</span>
								<span style="COLOR: #000000">font</span>
								<span style="COLOR: #000000">=</span>
						</font>
				</font>
				<font face="Courier New">
						<font size="2">
								<span style="COLOR: #000000">NULL;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">screen to show on window</span>
						</font>
				</font>
				<span style="COLOR: #008000">
						<br />
						<font face="Courier New" size="2">
								<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						</font>
				</span>
				<font face="Courier New">
						<font size="2">
								<span style="COLOR: #0000ff">const</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">int</span>
								<span style="COLOR: #000000"> SCREEN_BPP</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">32</span>
						</font>
				</font>
				<font face="Courier New">
						<font size="2">
								<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
								<span style="COLOR: #0000ff">int</span>
								<span style="COLOR: #000000"> main( </span>
								<span style="COLOR: #0000ff">int</span>
								<span style="COLOR: #000000"> argc, </span>
								<span style="COLOR: #0000ff">char</span>
								<span style="COLOR: #000000">*</span>
						</font>
				</font>
				<font face="Courier New">
						<font size="2">
								<span style="COLOR: #000000"> args[] )<br /><img id="Codehighlighter1_176_1773_Open_Image" onclick="this.style.display='none'; Codehighlighter1_176_1773_Open_Text.style.display='none'; Codehighlighter1_176_1773_Closed_Image.style.display='inline'; Codehighlighter1_176_1773_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_176_1773_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_176_1773_Closed_Text.style.display='none'; Codehighlighter1_176_1773_Open_Image.style.display='inline'; Codehighlighter1_176_1773_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
								<span id="Codehighlighter1_176_1773_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
						</font>
				</font>
				<span id="Codehighlighter1_176_1773_Open_Text">
						<font face="Courier New">
								<font size="2">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">Start SDL</span>
								</font>
						</font>
						<span style="COLOR: #008000">
								<br />
								<font face="Courier New" size="2">
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</font>
						</span>
						<font face="Courier New">
								<font size="2">
										<span style="COLOR: #000000">    </span>
										<span style="COLOR: #0000ff">bool</span>
										<span style="COLOR: #000000"> quit</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #0000ff">false</span>
								</font>
						</font>
						<font face="Courier New">
								<font size="2">
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    SDL_Rect rectLeft;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    SDL_Rect rectRight;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    rectLeft.x</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000">0</span>
								</font>
						</font>
						<font face="Courier New">
								<font size="2">
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    rectLeft.y</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000">0</span>
								</font>
						</font>
						<font face="Courier New">
								<font size="2">
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    rectLeft.w</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000">320</span>
								</font>
						</font>
						<font face="Courier New">
								<font size="2">
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    rectLeft.h</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000">480</span>
								</font>
						</font>
						<font face="Courier New">
								<font size="2">
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    rectRight.x</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000">320</span>
								</font>
						</font>
						<font face="Courier New">
								<font size="2">
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    rectRight.y</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000">0</span>
								</font>
						</font>
						<font face="Courier New">
								<font size="2">
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    rectRight.w</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000">640</span>
								</font>
						</font>
						<font face="Courier New">
								<font size="2">
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    rectRight.h</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000">480</span>
								</font>
						</font>
						<font face="Courier New">
								<font size="2">
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    SDL_Init( SDL_INIT_EVERYTHING );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000">(TTF_Init()</span>
										<span style="COLOR: #000000">==-</span>
										<span style="COLOR: #000000">1</span>
								</font>
						</font>
						<font face="Courier New">
								<font size="2">
										<span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
										<span style="COLOR: #0000ff">return</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #0000ff">false</span>
								</font>
						</font>
						<font face="Courier New">
								<font size="2">
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    screen </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> SDL_SetVideoMode( </span>
										<span style="COLOR: #000000">600</span>
										<span style="COLOR: #000000">, </span>
										<span style="COLOR: #000000">480</span>
								</font>
						</font>
						<font face="Courier New">
								<font size="2">
										<span style="COLOR: #000000">, SCREEN_BPP, SDL_SWSURFACE );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000">(screen</span>
										<span style="COLOR: #000000">==</span>
								</font>
						</font>
						<font face="Courier New">
								<font size="2">
										<span style="COLOR: #000000">NULL)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
										<span style="COLOR: #0000ff">return</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #0000ff">false</span>
								</font>
						</font>
						<font face="Courier New">
								<font size="2">
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Uint32 colorBlue</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000">SDL_MapRGB(screen</span>
										<span style="COLOR: #000000">-&gt;</span>
										<span style="COLOR: #000000">format,</span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">,</span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">,</span>
										<span style="COLOR: #000000">255</span>
								</font>
						</font>
						<font face="Courier New">
								<font size="2">
										<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Uint32 colorGreen</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000">SDL_MapRGB(screen</span>
										<span style="COLOR: #000000">-&gt;</span>
										<span style="COLOR: #000000">format,</span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">,</span>
										<span style="COLOR: #000000">255</span>
										<span style="COLOR: #000000">,</span>
										<span style="COLOR: #000000">0</span>
								</font>
						</font>
						<font face="Courier New">
								<font size="2">
										<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Uint32 colorRed</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000">SDL_MapRGB(screen</span>
										<span style="COLOR: #000000">-&gt;</span>
										<span style="COLOR: #000000">format,</span>
										<span style="COLOR: #000000">255</span>
										<span style="COLOR: #000000">,</span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">,</span>
										<span style="COLOR: #000000">0</span>
								</font>
						</font>
						<font face="Courier New">
								<font size="2">
										<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Uint32 colorBlack</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000">SDL_MapRGB(screen</span>
										<span style="COLOR: #000000">-&gt;</span>
										<span style="COLOR: #000000">format,</span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">,</span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">,</span>
										<span style="COLOR: #000000">0</span>
								</font>
						</font>
						<font face="Courier New">
								<font size="2">
										<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    SDL_Event </span>
										<span style="COLOR: #0000ff">event</span>
								</font>
						</font>
						<font face="Courier New">
								<font size="2">
										<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
										<span style="COLOR: #0000ff">while</span>
										<span style="COLOR: #000000">(</span>
										<span style="COLOR: #000000">!</span>
								</font>
						</font>
						<font face="Courier New">
								<font size="2">
										<span style="COLOR: #000000">quit)<br /><img id="Codehighlighter1_806_1716_Open_Image" onclick="this.style.display='none'; Codehighlighter1_806_1716_Open_Text.style.display='none'; Codehighlighter1_806_1716_Closed_Image.style.display='inline'; Codehighlighter1_806_1716_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_806_1716_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_806_1716_Closed_Text.style.display='none'; Codehighlighter1_806_1716_Open_Image.style.display='inline'; Codehighlighter1_806_1716_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
										<span id="Codehighlighter1_806_1716_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
								</font>
						</font>
						<span id="Codehighlighter1_806_1716_Open_Text">
								<font face="Courier New">
										<font size="2">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
												<span style="COLOR: #0000ff">if</span>
												<span style="COLOR: #000000">(SDL_PollEvent(</span>
												<span style="COLOR: #000000">&amp;</span>
												<span style="COLOR: #0000ff">event</span>
										</font>
								</font>
								<font face="Courier New">
										<font size="2">
												<span style="COLOR: #000000">))<br /><img id="Codehighlighter1_838_1659_Open_Image" onclick="this.style.display='none'; Codehighlighter1_838_1659_Open_Text.style.display='none'; Codehighlighter1_838_1659_Closed_Image.style.display='inline'; Codehighlighter1_838_1659_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_838_1659_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_838_1659_Closed_Text.style.display='none'; Codehighlighter1_838_1659_Open_Image.style.display='inline'; Codehighlighter1_838_1659_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
												<span id="Codehighlighter1_838_1659_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
														<img src="http://www.cppblog.com/images/dot.gif" />
												</span>
										</font>
								</font>
								<span id="Codehighlighter1_838_1659_Open_Text">
										<font face="Courier New">
												<font size="2">
														<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
														<span style="COLOR: #0000ff">if</span>
														<span style="COLOR: #000000">(</span>
														<span style="COLOR: #0000ff">event</span>
														<span style="COLOR: #000000">.type </span>
														<span style="COLOR: #000000">==</span>
												</font>
										</font>
										<font face="Courier New">
												<font size="2">
														<span style="COLOR: #000000"> SDL_MOUSEMOTION)<br /><img id="Codehighlighter1_880_1240_Open_Image" onclick="this.style.display='none'; Codehighlighter1_880_1240_Open_Text.style.display='none'; Codehighlighter1_880_1240_Closed_Image.style.display='inline'; Codehighlighter1_880_1240_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_880_1240_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_880_1240_Closed_Text.style.display='none'; Codehighlighter1_880_1240_Open_Image.style.display='inline'; Codehighlighter1_880_1240_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
														<span id="Codehighlighter1_880_1240_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
																<img src="http://www.cppblog.com/images/dot.gif" />
														</span>
												</font>
										</font>
										<span id="Codehighlighter1_880_1240_Open_Text">
												<font face="Courier New">
														<font size="2">
																<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                Uint16 x</span>
																<span style="COLOR: #000000">=</span>
																<span style="COLOR: #0000ff">event</span>
														</font>
												</font>
												<font face="Courier New">
														<font size="2">
																<span style="COLOR: #000000">.motion.x;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                Uint16 y</span>
																<span style="COLOR: #000000">=</span>
																<span style="COLOR: #0000ff">event</span>
														</font>
												</font>
												<font face="Courier New">
														<font size="2">
																<span style="COLOR: #000000">.motion.y;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span>
																<span style="COLOR: #0000ff">if</span>
																<span style="COLOR: #000000">(x</span>
																<span style="COLOR: #000000">&gt;</span>
																<span style="COLOR: #000000">0</span>
																<span style="COLOR: #000000"> </span>
																<span style="COLOR: #000000">&amp;&amp;</span>
																<span style="COLOR: #000000"> x</span>
																<span style="COLOR: #000000">&lt;</span>
																<span style="COLOR: #000000">320</span>
																<span style="COLOR: #000000"> </span>
																<span style="COLOR: #000000">&amp;&amp;</span>
																<span style="COLOR: #000000"> y</span>
																<span style="COLOR: #000000">&gt;</span>
																<span style="COLOR: #000000">0</span>
																<span style="COLOR: #000000"> </span>
																<span style="COLOR: #000000">&amp;&amp;</span>
																<span style="COLOR: #000000"> y</span>
																<span style="COLOR: #000000">&lt;</span>
																<span style="COLOR: #000000">480</span>
														</font>
												</font>
												<font face="Courier New">
														<font size="2">
																<span style="COLOR: #000000"> )<br /><img id="Codehighlighter1_984_1086_Open_Image" onclick="this.style.display='none'; Codehighlighter1_984_1086_Open_Text.style.display='none'; Codehighlighter1_984_1086_Closed_Image.style.display='inline'; Codehighlighter1_984_1086_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_984_1086_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_984_1086_Closed_Text.style.display='none'; Codehighlighter1_984_1086_Open_Image.style.display='inline'; Codehighlighter1_984_1086_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />                </span>
																<span id="Codehighlighter1_984_1086_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
																		<img src="http://www.cppblog.com/images/dot.gif" />
																</span>
														</font>
												</font>
												<span id="Codehighlighter1_984_1086_Open_Text">
														<font face="Courier New">
																<font size="2">
																		<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                    SDL_FillRect(screen,</span>
																		<span style="COLOR: #000000">&amp;</span>
																</font>
														</font>
														<font face="Courier New">
																<font size="2">
																		<span style="COLOR: #000000">rectLeft,colorBlue);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                    SDL_FillRect(screen,</span>
																		<span style="COLOR: #000000">&amp;</span>
																</font>
														</font>
														<span style="COLOR: #000000">
																<font face="Courier New" size="2">rectRight,colorBlack);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />                }</font>
														</span>
												</span>
												<span style="COLOR: #000000">
														<br />
														<font face="Courier New" size="2">
																<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </font>
												</span>
												<font face="Courier New">
														<font size="2">
																<span style="COLOR: #0000ff">if</span>
																<span style="COLOR: #000000">(x</span>
																<span style="COLOR: #000000">&gt;</span>
																<span style="COLOR: #000000">320</span>
																<span style="COLOR: #000000"> </span>
																<span style="COLOR: #000000">&amp;&amp;</span>
																<span style="COLOR: #000000"> x</span>
																<span style="COLOR: #000000">&lt;</span>
																<span style="COLOR: #000000">640</span>
																<span style="COLOR: #000000"> </span>
																<span style="COLOR: #000000">&amp;&amp;</span>
																<span style="COLOR: #000000"> y</span>
																<span style="COLOR: #000000">&gt;</span>
																<span style="COLOR: #000000">0</span>
																<span style="COLOR: #000000"> </span>
																<span style="COLOR: #000000">&amp;&amp;</span>
																<span style="COLOR: #000000"> y</span>
																<span style="COLOR: #000000">&lt;</span>
																<span style="COLOR: #000000">480</span>
														</font>
												</font>
												<font face="Courier New">
														<font size="2">
																<span style="COLOR: #000000"> )<br /><img id="Codehighlighter1_1132_1235_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1132_1235_Open_Text.style.display='none'; Codehighlighter1_1132_1235_Closed_Image.style.display='inline'; Codehighlighter1_1132_1235_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1132_1235_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1132_1235_Closed_Text.style.display='none'; Codehighlighter1_1132_1235_Open_Image.style.display='inline'; Codehighlighter1_1132_1235_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />                </span>
																<span id="Codehighlighter1_1132_1235_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
																		<img src="http://www.cppblog.com/images/dot.gif" />
																</span>
														</font>
												</font>
												<span id="Codehighlighter1_1132_1235_Open_Text">
														<font face="Courier New">
																<font size="2">
																		<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                    SDL_FillRect(screen,</span>
																		<span style="COLOR: #000000">&amp;</span>
																</font>
														</font>
														<font face="Courier New">
																<font size="2">
																		<span style="COLOR: #000000">rectRight,colorGreen);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                    SDL_FillRect(screen,</span>
																		<span style="COLOR: #000000">&amp;</span>
																</font>
														</font>
														<span style="COLOR: #000000">
																<font face="Courier New" size="2">rectLeft,colorBlack);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />                }</font>
														</span>
												</span>
												<span style="COLOR: #000000">
														<br />
														<font face="Courier New" size="2">
																<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</font>
												</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<font face="Courier New" size="2">
														<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </font>
										</span>
										<font face="Courier New">
												<font size="2">
														<span style="COLOR: #0000ff">if</span>
														<span style="COLOR: #000000">(</span>
														<span style="COLOR: #0000ff">event</span>
														<span style="COLOR: #000000">.type </span>
														<span style="COLOR: #000000">==</span>
												</font>
										</font>
										<font face="Courier New">
												<font size="2">
														<span style="COLOR: #000000">SDL_MOUSEBUTTONDOWN)<br /><img id="Codehighlighter1_1285_1610_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1285_1610_Open_Text.style.display='none'; Codehighlighter1_1285_1610_Closed_Image.style.display='inline'; Codehighlighter1_1285_1610_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1285_1610_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1285_1610_Closed_Text.style.display='none'; Codehighlighter1_1285_1610_Open_Image.style.display='inline'; Codehighlighter1_1285_1610_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
														<span id="Codehighlighter1_1285_1610_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
																<img src="http://www.cppblog.com/images/dot.gif" />
														</span>
												</font>
										</font>
										<span id="Codehighlighter1_1285_1610_Open_Text">
												<font face="Courier New">
														<font size="2">
																<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                Uint16 x</span>
																<span style="COLOR: #000000">=</span>
																<span style="COLOR: #0000ff">event</span>
														</font>
												</font>
												<font face="Courier New">
														<font size="2">
																<span style="COLOR: #000000">.motion.x;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                Uint16 y</span>
																<span style="COLOR: #000000">=</span>
																<span style="COLOR: #0000ff">event</span>
														</font>
												</font>
												<font face="Courier New">
														<font size="2">
																<span style="COLOR: #000000">.motion.y;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span>
																<span style="COLOR: #0000ff">if</span>
																<span style="COLOR: #000000">(</span>
																<span style="COLOR: #0000ff">event</span>
																<span style="COLOR: #000000">.button.button </span>
																<span style="COLOR: #000000">==</span>
														</font>
												</font>
												<font face="Courier New">
														<font size="2">
																<span style="COLOR: #000000"> SDL_BUTTON_LEFT)<br /><img id="Codehighlighter1_1396_1605_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1396_1605_Open_Text.style.display='none'; Codehighlighter1_1396_1605_Closed_Image.style.display='inline'; Codehighlighter1_1396_1605_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1396_1605_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1396_1605_Closed_Text.style.display='none'; Codehighlighter1_1396_1605_Open_Image.style.display='inline'; Codehighlighter1_1396_1605_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />                </span>
																<span id="Codehighlighter1_1396_1605_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
																		<img src="http://www.cppblog.com/images/dot.gif" />
																</span>
														</font>
												</font>
												<span id="Codehighlighter1_1396_1605_Open_Text">
														<font face="Courier New">
																<font size="2">
																		<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                    </span>
																		<span style="COLOR: #0000ff">if</span>
																		<span style="COLOR: #000000">(x</span>
																		<span style="COLOR: #000000">&gt;</span>
																		<span style="COLOR: #000000">0</span>
																		<span style="COLOR: #000000"> </span>
																		<span style="COLOR: #000000">&amp;&amp;</span>
																		<span style="COLOR: #000000"> x</span>
																		<span style="COLOR: #000000">&lt;</span>
																		<span style="COLOR: #000000">320</span>
																		<span style="COLOR: #000000"> </span>
																		<span style="COLOR: #000000">&amp;&amp;</span>
																		<span style="COLOR: #000000"> y</span>
																		<span style="COLOR: #000000">&gt;</span>
																		<span style="COLOR: #000000">0</span>
																		<span style="COLOR: #000000"> </span>
																		<span style="COLOR: #000000">&amp;&amp;</span>
																		<span style="COLOR: #000000"> y</span>
																		<span style="COLOR: #000000">&lt;</span>
																		<span style="COLOR: #000000">480</span>
																</font>
														</font>
														<font face="Courier New">
																<font size="2">
																		<span style="COLOR: #000000"> )<br /><img id="Codehighlighter1_1442_1496_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1442_1496_Open_Text.style.display='none'; Codehighlighter1_1442_1496_Closed_Image.style.display='inline'; Codehighlighter1_1442_1496_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1442_1496_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1442_1496_Closed_Text.style.display='none'; Codehighlighter1_1442_1496_Open_Image.style.display='inline'; Codehighlighter1_1442_1496_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />                    </span>
																		<span id="Codehighlighter1_1442_1496_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
																				<img src="http://www.cppblog.com/images/dot.gif" />
																		</span>
																</font>
														</font>
														<span id="Codehighlighter1_1442_1496_Open_Text">
																<font face="Courier New">
																		<font size="2">
																				<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                        SDL_FillRect(screen,</span>
																				<span style="COLOR: #000000">&amp;</span>
																		</font>
																</font>
																<span style="COLOR: #000000">
																		<font face="Courier New" size="2">rectLeft,colorRed);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />                    }</font>
																</span>
														</span>
														<span style="COLOR: #000000">
																<br />
																<font face="Courier New" size="2">
																		<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                    </font>
														</span>
														<font face="Courier New">
																<font size="2">
																		<span style="COLOR: #0000ff">if</span>
																		<span style="COLOR: #000000">(x</span>
																		<span style="COLOR: #000000">&gt;</span>
																		<span style="COLOR: #000000">320</span>
																		<span style="COLOR: #000000"> </span>
																		<span style="COLOR: #000000">&amp;&amp;</span>
																		<span style="COLOR: #000000"> x</span>
																		<span style="COLOR: #000000">&lt;</span>
																		<span style="COLOR: #000000">640</span>
																		<span style="COLOR: #000000"> </span>
																		<span style="COLOR: #000000">&amp;&amp;</span>
																		<span style="COLOR: #000000"> y</span>
																		<span style="COLOR: #000000">&gt;</span>
																		<span style="COLOR: #000000">0</span>
																		<span style="COLOR: #000000"> </span>
																		<span style="COLOR: #000000">&amp;&amp;</span>
																		<span style="COLOR: #000000"> y</span>
																		<span style="COLOR: #000000">&lt;</span>
																		<span style="COLOR: #000000">480</span>
																</font>
														</font>
														<font face="Courier New">
																<font size="2">
																		<span style="COLOR: #000000"> )<br /><img id="Codehighlighter1_1544_1599_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1544_1599_Open_Text.style.display='none'; Codehighlighter1_1544_1599_Closed_Image.style.display='inline'; Codehighlighter1_1544_1599_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1544_1599_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1544_1599_Closed_Text.style.display='none'; Codehighlighter1_1544_1599_Open_Image.style.display='inline'; Codehighlighter1_1544_1599_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />                    </span>
																		<span id="Codehighlighter1_1544_1599_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
																				<img src="http://www.cppblog.com/images/dot.gif" />
																		</span>
																</font>
														</font>
														<span id="Codehighlighter1_1544_1599_Open_Text">
																<font face="Courier New">
																		<font size="2">
																				<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                        SDL_FillRect(screen,</span>
																				<span style="COLOR: #000000">&amp;</span>
																		</font>
																</font>
																<span style="COLOR: #000000">
																		<font face="Courier New" size="2">rectRight,colorRed);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />                    }</font>
																</span>
														</span>
														<span style="COLOR: #000000">
																<br />
																<font face="Courier New" size="2">
																		<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />                }</font>
														</span>
												</span>
												<span style="COLOR: #000000">
														<br />
														<font face="Courier New" size="2">
																<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</font>
												</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<font face="Courier New" size="2">
														<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </font>
										</span>
										<font face="Courier New">
												<font size="2">
														<span style="COLOR: #0000ff">if</span>
														<span style="COLOR: #000000">(</span>
														<span style="COLOR: #0000ff">event</span>
														<span style="COLOR: #000000">.type </span>
														<span style="COLOR: #000000">==</span>
												</font>
										</font>
										<font face="Courier New">
												<font size="2">
														<span style="COLOR: #000000"> SDL_QUIT)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                quit</span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #0000ff">true</span>
												</font>
										</font>
										<span style="COLOR: #000000">
												<font face="Courier New" size="2">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</font>
										</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<font face="Courier New" size="2">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </font>
								</span>
								<font face="Courier New">
										<font size="2">
												<span style="COLOR: #0000ff">if</span>
												<span style="COLOR: #000000">(SDL_Flip(screen) </span>
												<span style="COLOR: #000000">==</span>
												<span style="COLOR: #000000"> </span>
												<span style="COLOR: #000000">-</span>
												<span style="COLOR: #000000">1</span>
										</font>
								</font>
								<font face="Courier New">
										<font size="2">
												<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_1692_1713_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1692_1713_Open_Text.style.display='none'; Codehighlighter1_1692_1713_Closed_Image.style.display='inline'; Codehighlighter1_1692_1713_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1692_1713_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1692_1713_Closed_Text.style.display='none'; Codehighlighter1_1692_1713_Open_Image.style.display='inline'; Codehighlighter1_1692_1713_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
												<span id="Codehighlighter1_1692_1713_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
														<img src="http://www.cppblog.com/images/dot.gif" />
												</span>
										</font>
								</font>
								<span id="Codehighlighter1_1692_1713_Open_Text">
										<font face="Courier New">
												<font size="2">
														<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
														<span style="COLOR: #0000ff">return</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #0000ff">false</span>
												</font>
										</font>
										<span style="COLOR: #000000">
												<font face="Courier New" size="2">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</font>
										</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<font face="Courier New" size="2">
												<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</font>
								</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<font face="Courier New" size="2">
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    SDL_FreeSurface(screen);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    SDL_Quit();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </font>
						</span>
						<font face="Courier New">
								<font size="2">
										<span style="COLOR: #0000ff">return</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">0</span>
								</font>
						</font>
						<span style="COLOR: #000000">
								<font face="Courier New" size="2">;    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</font>
						</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<font face="Courier New" size="2">
								<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						</font>
				</span>
		</div>
		<img height="546" alt="mousedown.jpg" src="http://www.cppblog.com/images/cppblog_com/mrcplusplus/mousedown.jpg" width="703" border="0" />
<img src ="http://www.cppblog.com/mrcplusplus/aggbug/19653.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mrcplusplus/" target="_blank">大熊猫</a> 2007-03-12 20:10 <a href="http://www.cppblog.com/mrcplusplus/archive/2007/03/12/19653.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SDL游戏编程(7)键盘事件</title><link>http://www.cppblog.com/mrcplusplus/archive/2007/03/12/19649.html</link><dc:creator>大熊猫</dc:creator><author>大熊猫</author><pubDate>Mon, 12 Mar 2007 11:27:00 GMT</pubDate><guid>http://www.cppblog.com/mrcplusplus/archive/2007/03/12/19649.html</guid><wfw:comment>http://www.cppblog.com/mrcplusplus/comments/19649.html</wfw:comment><comments>http://www.cppblog.com/mrcplusplus/archive/2007/03/12/19649.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mrcplusplus/comments/commentRss/19649.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mrcplusplus/services/trackbacks/19649.html</trackback:ping><description><![CDATA[这次我们看看如何在SDL中处理键盘事件，每次事件发生以后，有关事件的所有信息都存储在SDL_Event类型的变量当中，查查手册我们可以知道，实际SDL_Event是一个联合体。<br />typedef union{<br />  Uint8 type;<br />  SDL_ActiveEvent active;<br />  SDL_KeyboardEvent key;<br />  SDL_MouseMotionEvent motion;<br />  SDL_MouseButtonEvent button;<br />  SDL_JoyAxisEvent jaxis;<br />  SDL_JoyBallEvent jball;<br />  SDL_JoyHatEvent jhat;<br />  SDL_JoyButtonEvent jbutton;<br />  SDL_ResizeEvent resize;<br />  SDL_ExposeEvent expose;<br />  SDL_QuitEvent quit;<br />  SDL_UserEvent user;<br />  SDL_SywWMEvent syswm;<br />} SDL_Event;<br />当发生键盘事件时，key变量就是有效的。<br />typedef struct{<br />  Uint8 type;<br />  Uint8 state;<br />  SDL_keysym keysym;<br />} SDL_KeyboardEvent;<br />key变量是一个结构体，其中keysym成员包含了按键信息。<br />typedef struct{<br />  Uint8 scancode;<br />  SDLKey sym;<br />  SDLMod mod;<br />  Uint16 unicode;<br />} SDL_keysym;<br />在keysym的成员当中，sym记录按键所对应的虚拟键。<br />比如说向上就是SDLK_UP；向下就是SDLK_DOWN；大家可以自己去查手册。<br /><br />下面就看一个处理键盘消息的实例吧。<br />该例子中，我们一旦发现有上下左右四个键被按下，就马上在屏幕上显示相对应的消息，这里用到了扩展类库SDL_TTF，如有不清楚的，参考一下前面的几篇文章。<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><font size="2"><font face="Courier New"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">#include </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">SDL.h</span><span style="COLOR: #000000">"</span></font></font><span style="COLOR: #000000"><br /><font face="Courier New" size="2"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </font></span><font size="2"><font face="Courier New"><span style="COLOR: #000000">"</span><span style="COLOR: #000000">SDL_ttf.h</span><span style="COLOR: #000000">"</span></font></font><span style="COLOR: #000000"><br /><font face="Courier New" size="2"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />SDL_Surface </font></span><font size="2"><font face="Courier New"><span style="COLOR: #000000">*</span><span style="COLOR: #000000">screen</span><span style="COLOR: #000000">=</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">NULL;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />SDL_Surface </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">up</span><span style="COLOR: #000000">=</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">NULL;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />SDL_Surface </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">down</span><span style="COLOR: #000000">=</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">NULL;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />SDL_Surface </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">left</span><span style="COLOR: #000000">=</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">NULL;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />SDL_Surface </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">right</span><span style="COLOR: #000000">=</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">NULL;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />SDL_Surface </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">message</span><span style="COLOR: #000000">=</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">NULL;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />TTF_Font </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">font</span><span style="COLOR: #000000">=</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">NULL;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">screen to show on window</span></font></font><span style="COLOR: #008000"><br /><font face="Courier New" size="2"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></font></span><font size="2"><font face="Courier New"><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> SCREEN_BPP</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">32</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">;<br /><img id="Codehighlighter1_279_291_Open_Image" onclick="this.style.display='none'; Codehighlighter1_279_291_Open_Text.style.display='none'; Codehighlighter1_279_291_Closed_Image.style.display='inline'; Codehighlighter1_279_291_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_279_291_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_279_291_Closed_Text.style.display='none'; Codehighlighter1_279_291_Open_Image.style.display='inline'; Codehighlighter1_279_291_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />SDL_Color textColor</span><span style="COLOR: #000000">=</span><span id="Codehighlighter1_279_291_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span><span id="Codehighlighter1_279_291_Open_Text"><span style="COLOR: #000000">{</span><span style="COLOR: #000000">255</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">255</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">255</span><span style="COLOR: #000000">}</span></span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> main( </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> argc, </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">*</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000"> args[] )<br /><img id="Codehighlighter1_331_1514_Open_Image" onclick="this.style.display='none'; Codehighlighter1_331_1514_Open_Text.style.display='none'; Codehighlighter1_331_1514_Closed_Image.style.display='inline'; Codehighlighter1_331_1514_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_331_1514_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_331_1514_Closed_Text.style.display='none'; Codehighlighter1_331_1514_Open_Image.style.display='inline'; Codehighlighter1_331_1514_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_331_1514_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span></font></font><span id="Codehighlighter1_331_1514_Open_Text"><font size="2"><font face="Courier New"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Start SDL</span></font></font><span style="COLOR: #008000"><br /><font face="Courier New" size="2"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></font></span><font size="2"><font face="Courier New"><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000"> quit</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">false</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    SDL_Init( SDL_INIT_EVERYTHING );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(TTF_Init()</span><span style="COLOR: #000000">==-</span><span style="COLOR: #000000">1</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">false</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    screen </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> SDL_SetVideoMode( </span><span style="COLOR: #000000">600</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">480</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">, SCREEN_BPP, SDL_SWSURFACE );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(screen</span><span style="COLOR: #000000">==</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">NULL)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">false</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    font</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">TTF_OpenFont(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">tahoma.ttf</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">28</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    up </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> TTF_RenderText_Solid( font, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Up was pressed.</span><span style="COLOR: #000000">"</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">, textColor );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    down </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> TTF_RenderText_Solid( font, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Down was pressed.</span><span style="COLOR: #000000">"</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">, textColor );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    left </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> TTF_RenderText_Solid( font, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Left was pressed</span><span style="COLOR: #000000">"</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">, textColor );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    right </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> TTF_RenderText_Solid( font, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Right was pressed</span><span style="COLOR: #000000">"</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">, textColor );<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    SDL_Event </span><span style="COLOR: #0000ff">event</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">!</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">quit)<br /><img id="Codehighlighter1_882_1471_Open_Image" onclick="this.style.display='none'; Codehighlighter1_882_1471_Open_Text.style.display='none'; Codehighlighter1_882_1471_Closed_Image.style.display='inline'; Codehighlighter1_882_1471_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_882_1471_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_882_1471_Closed_Text.style.display='none'; Codehighlighter1_882_1471_Open_Image.style.display='inline'; Codehighlighter1_882_1471_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="Codehighlighter1_882_1471_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span></font></font><span id="Codehighlighter1_882_1471_Open_Text"><font size="2"><font face="Courier New"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(SDL_PollEvent(</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #0000ff">event</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">))<br /><img id="Codehighlighter1_914_1213_Open_Image" onclick="this.style.display='none'; Codehighlighter1_914_1213_Open_Text.style.display='none'; Codehighlighter1_914_1213_Closed_Image.style.display='inline'; Codehighlighter1_914_1213_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_914_1213_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_914_1213_Closed_Text.style.display='none'; Codehighlighter1_914_1213_Open_Image.style.display='inline'; Codehighlighter1_914_1213_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span id="Codehighlighter1_914_1213_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span></font></font><span id="Codehighlighter1_914_1213_Open_Text"><font size="2"><font face="Courier New"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">event</span><span style="COLOR: #000000">.type </span><span style="COLOR: #000000">==</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000"> SDL_KEYDOWN)<br /><img id="Codehighlighter1_952_1164_Open_Image" onclick="this.style.display='none'; Codehighlighter1_952_1164_Open_Text.style.display='none'; Codehighlighter1_952_1164_Closed_Image.style.display='inline'; Codehighlighter1_952_1164_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_952_1164_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_952_1164_Closed_Text.style.display='none'; Codehighlighter1_952_1164_Open_Image.style.display='inline'; Codehighlighter1_952_1164_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span><span id="Codehighlighter1_952_1164_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span></font></font><span id="Codehighlighter1_952_1164_Open_Text"><font size="2"><font face="Courier New"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                </span><span style="COLOR: #0000ff">switch</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">event</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">.key.keysym.sym)<br /><img id="Codehighlighter1_991_1159_Open_Image" onclick="this.style.display='none'; Codehighlighter1_991_1159_Open_Text.style.display='none'; Codehighlighter1_991_1159_Closed_Image.style.display='inline'; Codehighlighter1_991_1159_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_991_1159_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_991_1159_Closed_Text.style.display='none'; Codehighlighter1_991_1159_Open_Image.style.display='inline'; Codehighlighter1_991_1159_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />                </span><span id="Codehighlighter1_991_1159_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span></font></font><span id="Codehighlighter1_991_1159_Open_Text"><font size="2"><font face="Courier New"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                    </span><span style="COLOR: #0000ff">case</span><span style="COLOR: #000000"> SDLK_UP: message</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">up;</span><span style="COLOR: #0000ff">break</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                    </span><span style="COLOR: #0000ff">case</span><span style="COLOR: #000000"> SDLK_DOWN: message</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">down;</span><span style="COLOR: #0000ff">break</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                    </span><span style="COLOR: #0000ff">case</span><span style="COLOR: #000000"> SDLK_LEFT: message</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">left;</span><span style="COLOR: #0000ff">break</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                    </span><span style="COLOR: #0000ff">case</span><span style="COLOR: #000000"> SDLK_RIGHT: message</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">right;</span><span style="COLOR: #0000ff">break</span></font></font><span style="COLOR: #000000"><font face="Courier New" size="2">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />                }</font></span></span><span style="COLOR: #000000"><br /><font face="Courier New" size="2"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</font></span></span><span style="COLOR: #000000"><br /><font face="Courier New" size="2"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </font></span><font size="2"><font face="Courier New"><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">event</span><span style="COLOR: #000000">.type </span><span style="COLOR: #000000">==</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000"> SDL_QUIT)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                quit</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">true</span></font></font><span style="COLOR: #000000"><font face="Courier New" size="2">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</font></span></span><span style="COLOR: #000000"><br /><font face="Courier New" size="2"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </font></span><font size="2"><font face="Courier New"><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(message </span><span style="COLOR: #000000">!=</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000"> NULL)<br /><img id="Codehighlighter1_1239_1414_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1239_1414_Open_Text.style.display='none'; Codehighlighter1_1239_1414_Closed_Image.style.display='inline'; Codehighlighter1_1239_1414_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1239_1414_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1239_1414_Closed_Text.style.display='none'; Codehighlighter1_1239_1414_Open_Image.style.display='inline'; Codehighlighter1_1239_1414_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span id="Codehighlighter1_1239_1414_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span></font></font><span id="Codehighlighter1_1239_1414_Open_Text"><font size="2"><font face="Courier New"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            Uint32 colorVal</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">SDL_MapRGB(screen</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">format,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">0</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            SDL_FillRect(screen, </span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">screen</span><span style="COLOR: #000000">-&gt;</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">clip_rect,colorVal);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            SDL_BlitSurface(message,NULL,screen,NULL);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            message</span><span style="COLOR: #000000">=</span></font></font><span style="COLOR: #000000"><font face="Courier New" size="2">NULL;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</font></span></span><span style="COLOR: #000000"><br /><font face="Courier New" size="2"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </font></span><font size="2"><font face="Courier New"><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(SDL_Flip(screen) </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span></font></font><font size="2"><font face="Courier New"><span style="COLOR: #000000">)<br /><img id="Codehighlighter1_1447_1468_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1447_1468_Open_Text.style.display='none'; Codehighlighter1_1447_1468_Closed_Image.style.display='inline'; Codehighlighter1_1447_1468_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1447_1468_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1447_1468_Closed_Text.style.display='none'; Codehighlighter1_1447_1468_Open_Image.style.display='inline'; Codehighlighter1_1447_1468_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span id="Codehighlighter1_1447_1468_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/images/dot.gif" /></span></font></font><span id="Codehighlighter1_1447_1468_Open_Text"><font size="2"><font face="Courier New"><span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">false</span></font></font><span style="COLOR: #000000"><font face="Courier New" size="2">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</font></span></span><span style="COLOR: #000000"><br /><font face="Courier New" size="2"><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</font></span></span><span style="COLOR: #000000"><br /><font face="Courier New" size="2"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </font></span><font size="2"><font face="Courier New"><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Quit SDL</span></font></font><span style="COLOR: #008000"><br /><font face="Courier New" size="2"><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></font></span><font size="2"><font face="Courier New"><span style="COLOR: #000000">    SDL_Quit();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span></font></font><span style="COLOR: #000000"><font face="Courier New" size="2">;    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</font></span></span><span style="COLOR: #000000"><br /><font face="Courier New" size="2"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></font></span></div><img height="325" alt="a.jpg" src="http://www.cppblog.com/images/cppblog_com/mrcplusplus/a.jpg" width="422" border="0" /><img src ="http://www.cppblog.com/mrcplusplus/aggbug/19649.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mrcplusplus/" target="_blank">大熊猫</a> 2007-03-12 19:27 <a href="http://www.cppblog.com/mrcplusplus/archive/2007/03/12/19649.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C++面试题</title><link>http://www.cppblog.com/mrcplusplus/archive/2007/03/10/19557.html</link><dc:creator>大熊猫</dc:creator><author>大熊猫</author><pubDate>Sat, 10 Mar 2007 14:09:00 GMT</pubDate><guid>http://www.cppblog.com/mrcplusplus/archive/2007/03/10/19557.html</guid><wfw:comment>http://www.cppblog.com/mrcplusplus/comments/19557.html</wfw:comment><comments>http://www.cppblog.com/mrcplusplus/archive/2007/03/10/19557.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/mrcplusplus/comments/commentRss/19557.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/mrcplusplus/services/trackbacks/19557.html</trackback:ping><description><![CDATA[
		<p> </p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<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 /><img id="Codehighlighter1_37_325_Open_Image" onclick="this.style.display='none'; Codehighlighter1_37_325_Open_Text.style.display='none'; Codehighlighter1_37_325_Closed_Image.style.display='inline'; Codehighlighter1_37_325_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_37_325_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_37_325_Closed_Text.style.display='none'; Codehighlighter1_37_325_Open_Image.style.display='inline'; Codehighlighter1_37_325_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_37_325_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_37_325_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
						<span style="COLOR: #0000ff">char</span>
						<span style="COLOR: #000000"> str1[]       </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">abc</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
						<span style="COLOR: #0000ff">char</span>
						<span style="COLOR: #000000"> str2[]       </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">abc</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
						<span style="COLOR: #0000ff">const</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">char</span>
						<span style="COLOR: #000000"> str3[] </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">abc</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">; <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
						<span style="COLOR: #0000ff">const</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">char</span>
						<span style="COLOR: #000000"> str4[] </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">abc</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">; <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
						<span style="COLOR: #0000ff">const</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">char</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> str5  </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">abc</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
						<span style="COLOR: #0000ff">const</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">char</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> str6  </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">abc</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> cout</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">(str1</span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000">str2)</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">\n</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> cout</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">(str3</span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000">str4)</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">\n</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> cout</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">(str5</span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000">str6)</span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">\n</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> ::system(</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">pause</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
		</div>以上会输出什么呢，答案是0,0,1。<br />前面四个变量都在栈上分配了内存，故内存地址大家都不同，而str5和str6所指字符串在常量区，大家有者一样的地址。<img src ="http://www.cppblog.com/mrcplusplus/aggbug/19557.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/mrcplusplus/" target="_blank">大熊猫</a> 2007-03-10 22:09 <a href="http://www.cppblog.com/mrcplusplus/archive/2007/03/10/19557.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>