<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Timothy&#039;s Space &#187; Enter</title>
	<atom:link href="http://www.xiaozhou.net/tag/enter/feed" rel="self" type="application/rss+xml" />
	<link>http://www.xiaozhou.net</link>
	<description>君看一叶舟，出没风波里</description>
	<lastBuildDate>Thu, 02 Sep 2010 15:10:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Blog评论功能再次改进</title>
		<link>http://www.xiaozhou.net/aboutsite/wordpress/modify_blog_comment_again-2010-02-04.htm</link>
		<comments>http://www.xiaozhou.net/aboutsite/wordpress/modify_blog_comment_again-2010-02-04.htm#comments</comments>
		<pubDate>Thu, 04 Feb 2010 14:11:00 +0000</pubDate>
		<dc:creator>Timothy</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[Comment]]></category>
		<category><![CDATA[ctrl]]></category>
		<category><![CDATA[Enter]]></category>

		<guid isPermaLink="false">http://www.xiaozhou.net/aboutsite/wordpress/blog%e8%af%84%e8%ae%ba%e5%8a%9f%e8%83%bd%e5%86%8d%e6%ac%a1%e6%94%b9%e8%bf%9b-2010-02-04.htm</guid>
		<description><![CDATA[自从实现了Ajax的评论后，俺还是对评论部分有点不太满意，于是又开始拿评论开刀了。 1.首先想到的，是评论没有分页显示的功能，如果评论数量太多，会把页面拖得很长，在google搜索了一下，原来WordPress原生已经支持评论分页的功能了，所以一不做二不休，继续改动。 其实改动很简单，打开模板的comments.php，在类似wp_list_comments();列出评论的代码后面，加入下面的代码即可: ?View Code PHP1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 &#38;lt;?php // 如果用户在后台选择要显示评论分页 if &#40;get_option&#40;'page_comments'&#41;&#41; &#123; // 获取评论分页的 HTML $comment_pages = paginate_comments_links&#40;'echo=0'&#41;; // 如果评论分页的 HTML 不为空, 显示导航式分页 if &#40;$comment_pages&#41; &#123; ?&#38;gt; &#160; &#60;div id=&#34;commentnavi&#34;&#62; &#38;lt;?php echo $comment_pages; ?&#38;gt;&#60;/div&#62; &#160; &#160; &#38;lt;?php [...]]]></description>
			<content:encoded><![CDATA[<p>自从实现了Ajax的评论后，俺还是对评论部分有点不太满意，于是又开始拿评论开刀了。</p>
<p>1.首先想到的，是评论没有分页显示的功能，如果评论数量太多，会把页面拖得很长，在google搜索了一下，原来WordPress原生已经支持评论分页的功能了，所以一不做二不休，继续改动。<br />
其实改动很简单，打开模板的comments.php，在类似wp_list_comments();列出评论的代码后面，加入下面的代码即可:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p525code5'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5255"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code" id="p525code5"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>?php
	<span style="color: #666666; font-style: italic;">// 如果用户在后台选择要显示评论分页</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'page_comments'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// 获取评论分页的 HTML</span>
		<span style="color: #000088;">$comment_pages</span> <span style="color: #339933;">=</span> paginate_comments_links<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'echo=0'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// 如果评论分页的 HTML 不为空, 显示导航式分页</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$comment_pages</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;commentnavi&quot;</span><span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>?php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$comment_pages</span><span style="color: #339933;">;</span> ?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
&nbsp;
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>?php
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>2. 实现Enter+Ctrl快捷回复，这个比较简单，用jQuery实现，正好这两天也在学jQuery，就当练练手吧。为了增加代码可读性，方便以后维护，将这部分自定义的jQuery代码放在单独的js文件中：timothy.js</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p525code6'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5256"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p525code6"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//Ctrl+Enter for fast submit</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#comment&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">keydown</span><span style="color: #009900;">&#40;</span>
    	<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>event.<span style="color: #660066;">ctrlKey</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> event.<span style="color: #660066;">keyCode</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">13</span><span style="color: #009900;">&#41;</span>
        	<span style="color: #009900;">&#123;</span>
            		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#submit&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        	<span style="color: #009900;">&#125;</span>
    	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>代码比较简单，检测评论框的keydown时间，并判断是否同时按下了Ctrl键和Enter键，如果条件成立，则直接出发提交按钮的点击事件。将此部分js代码上传，并在header.php引入此脚本文件，效果立马就有了。这下同学们可以通过Ctrl+Enter快捷提交评论了。不过后来发现一个问题，这种用Ctrl+Enter快捷提交的评论，不会触发Ajax评论的效果，后来仔细找了找原因，发现Ajax评论的jQuery脚本中，并没有绑定提交按钮的点击事件，而是绑定的整个Form的submit事件，所以把刚才的脚本小小修改一下即可：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p525code7'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5257"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p525code7"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//Ctrl+Enter for fast submit</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#comment&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">keydown</span><span style="color: #009900;">&#40;</span>
    	<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>event.<span style="color: #660066;">ctrlKey</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> event.<span style="color: #660066;">keyCode</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">13</span><span style="color: #009900;">&#41;</span>
        	<span style="color: #009900;">&#123;</span>
            		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#commentform&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        	<span style="color: #009900;">&#125;</span>
    	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>这下就搞定了，支持Ctrl+Enter提交的Ajax评论，呵呵。</p>
<p>3.这个修改源自<a href="http://zww.me" target="_blank">Zww</a>同学的提议，在每条评论中增加”回复”按钮，原以为我的皮肤不支持嵌套评论的，尝试着在WordPress的设置项中，把嵌套评论给Enable了，这样的话，每条评论就自动有了个回复按钮。接下来，想实现点击回复的时候，自动把评论的同学的名字填入到评论框中，也就是类似 @XXX: 的形式。大体思路是通过jQuery来实现，绑定这些回复按钮的click事件，获取评论的同学的名称，设置到评论框中。其实<a href="http://zww.me" target="_blank">Zww</a>同学早就实现了这样的功能(<a href="http://zww.me/archives/24817" target="_blank">前去围观</a>)，所以jQuery也可以偷师过来了：</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p525code8'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5258"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p525code8"><pre class="javascript" style="font-family:monospace;">    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.reply&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span>
	<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> <span style="color: #000066;">name</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">prevAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;cite:first&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#comment&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;@&quot;</span><span style="color: #339933;">+</span><span style="color: #000066;">name</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;:&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">focus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>同样，放在$(document).ready里面即可。这次改动，俺意外的发现，原来我的皮肤支持嵌套评论……或许是加入了Ajax评论组件的原因，嘿嘿。</p>
<p>此文很菜，没啥技术含量， 算是学习jQuery的一点心得吧，前路茫茫，吾将继续折腾下去……</p>
<h3  class="related_post_title">你可能也对下列文章感兴趣</h3><ul class="related_post"><li>2010年02月1日 -- <a href="http://www.xiaozhou.net/aboutsite/wordpress/blog_modification_ajax_comment_enabled-2010-02-01.htm" title="Blog再次改动&#8211;启用Ajax评论">Blog再次改动&#8211;启用Ajax评论</a> (20)</li><li>2010年07月22日 -- <a href="http://www.xiaozhou.net/aboutsite/wordpress/modification_of_wp-reader-wall_to_fit_wordpress-3-0-2010-07-22.htm" title="WP-Reader-Wall 插件兼容 WordPress 3.0的修改">WP-Reader-Wall 插件兼容 WordPress 3.0的修改</a> (10)</li><li>2010年07月3日 -- <a href="http://www.xiaozhou.net/aboutsite/wordpress/wordpress_auto_add_keyword_optimize-2010-07-03.htm" title="Wordpress自动添加关键词优化的代码">Wordpress自动添加关键词优化的代码</a> (8)</li><li>2010年07月2日 -- <a href="http://www.xiaozhou.net/ittech/vps-ittech/wordpress_data_backup_shell_script-2010-07-02.htm" title="WordPress数据自动备份脚本">WordPress数据自动备份脚本</a> (4)</li><li>2010年05月21日 -- <a href="http://www.xiaozhou.net/aboutsite/wordpress/introduce_of_wp_codebox-2010-05-21.htm" title="WordPress插件介绍:WP-CodeBox">WordPress插件介绍:WP-CodeBox</a> (8)</li><li>2010年02月17日 -- <a href="http://www.xiaozhou.net/aboutsite/wordpress/wordpress_local_test_environment_setup-2010-02-17.htm" title="WordPress本地测试环境搭建">WordPress本地测试环境搭建</a> (20)</li><li>2009年12月29日 -- <a href="http://www.xiaozhou.net/aboutsite/wordpress/new_blog_plugin_comment_info_detector-2009-12-29.htm" title="新增博客插件&#8211;Comment Info Detector">新增博客插件&#8211;Comment Info Detector</a> (8)</li><li>2009年12月2日 -- <a href="http://www.xiaozhou.net/aboutsite/wordpress/blog_skin_download_minyx_lite-2009-12-02.htm" title="Blog 皮肤下载&mdash;Minyx 2.0 Lite">Blog 皮肤下载&mdash;Minyx 2.0 Lite</a> (4)</li><li>2009年10月25日 -- <a href="http://www.xiaozhou.net/aboutsite/wordpress/first_article_on_wordpress-2009-10-25.htm" title="WordPress下的第一篇日志 :-)">WordPress下的第一篇日志 :-)</a> (7)</li><li>2004年09月25日 -- <a href="http://www.xiaozhou.net/vcdevelopment/procedures-to-prevent-the-dialog-box-press-enter-and-esc-to-quit-countermeasures-2004-09-25.htm" title="防止对话框程序按Enter和ESC退出的对策">防止对话框程序按Enter和ESC退出的对策</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.xiaozhou.net/aboutsite/wordpress/modify_blog_comment_again-2010-02-04.htm/feed</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>防止对话框程序按Enter和ESC退出的对策</title>
		<link>http://www.xiaozhou.net/vcdevelopment/procedures-to-prevent-the-dialog-box-press-enter-and-esc-to-quit-countermeasures-2004-09-25.htm</link>
		<comments>http://www.xiaozhou.net/vcdevelopment/procedures-to-prevent-the-dialog-box-press-enter-and-esc-to-quit-countermeasures-2004-09-25.htm#comments</comments>
		<pubDate>Sat, 25 Sep 2004 14:48:32 +0000</pubDate>
		<dc:creator>Timothy</dc:creator>
				<category><![CDATA[VC开发]]></category>
		<category><![CDATA[DialogBox]]></category>
		<category><![CDATA[Enter]]></category>
		<category><![CDATA[ESC]]></category>
		<category><![CDATA[Exit]]></category>

		<guid isPermaLink="false">http://localhost/wordpress/?p=24</guid>
		<description><![CDATA[在一般情况下编写的对话框程序，用户在运行的时候，如果不注意按下了ENTER或者ESC键，程序就会立刻退出，之所以会这样，是因为按下Enter键时，Windows就会自动去找输入焦点落在了哪一个按钮上，当获得焦点的按钮的四周将被点线矩形包围。如果所有按钮都没有获得输入焦点，Windows就会自动去寻找程序或资源所指定的默认按钮(默认按钮边框较粗)。如果对话框没有默认按钮，那么即使对话框中没有OK按钮，OnOK函数也会自动被调用，对于一个普通的对话框程序来说，OnOK函数的调用，以为着程序会立刻退出。为了使Enter键无效，最简单的办法就是将CExDlg的OnOK函数写成空函数，然后针对OK按钮写一个新的函数来响应。ESC键的原理也是如此，它是默认和OnCancel函数映射在一起的。对于ESC键，需要自己重载CDialog类的PreTranslateMessage函数，当发现是ESC键的时候，过滤掉这个消息或者是替换掉这个消息。 一下是简单的代码示例： [biggrin]【方法1】 可以先重载OnOK函数 voidCTestDlg::OnOK() { //里面什么也不写} 然后重载PreTranslateMessage函数 把ESC键的消息，用RETURN键的消息替换，这样，按ESC的时候，也会执行刚才的OnOK函数，这样问题就可以解决了。 BOOL CxxxDlg::PreTranslateMessage(MSG* pMsg) { if(pMsg->message==WM_KEYDOWN &#038;&#038; pMsg->wParam==VK_ESCAPE) { pMsg->wParam=VK_RETURN; //将ESC键的消息替换为回车键的消息，这样，按ESC的时候 //也会去调用OnOK函数，而OnOK什么也不做，这样ESC也被屏蔽 } return CDialog::PreTranslateMessage(pMsg); } [biggrin]【方法2】 直接在重载的PreTranslateMessage函数中屏蔽回车和ESC的消息，和以上方法大同小异： BOOL CxxxDlg::PreTranslateMessage(MSG* pMsg) { if(pMsg->message==WM_KEYDOWN &#038;&#038; pMsg->wParam==VK_ESCAPE) return TRUE; if(pMsg->message==WM_KEYDOWN &#038;&#038; pMsg->wParam==VK_RETURN) return TRUE; else return CDialog::PreTranslateMessage(pMsg); } 你可能也对下列文章感兴趣2010年02月4日 -- Blog评论功能再次改进 (20)]]></description>
			<content:encoded><![CDATA[<p>在一般情况下编写的对话框程序，用户在运行的时候，如果不注意按下了ENTER或者ESC键，程序就会立刻退出，之所以会这样，是因为按下Enter键时，Windows就会自动去找输入焦点落在了哪一个按钮上，当获得焦点的按钮的四周将被点线矩形包围。如果所有按钮都没有获得输入焦点，Windows就会自动去寻找程序或资源所指定的默认按钮(默认按钮边框较粗)。如果对话框没有默认按钮，那么即使对话框中没有OK按钮，OnOK函数也会自动被调用，对于一个普通的对话框程序来说，OnOK函数的调用，以为着程序会立刻退出。为了使Enter键无效，最简单的办法就是将CExDlg的OnOK函数写成空函数，然后针对OK按钮写一个新的函数来响应。ESC键的原理也是如此，它是默认和OnCancel函数映射在一起的。对于ESC键，需要自己重载CDialog类的PreTranslateMessage函数，当发现是ESC键的时候，过滤掉这个消息或者是替换掉这个消息。</p>
<p>一下是简单的代码示例：</p>
<p>[biggrin]【方法1】<br />
可以先重载OnOK函数<br />
voidCTestDlg::OnOK()<br />
{  //里面什么也不写}</p>
<p>然后重载PreTranslateMessage函数<br />
把ESC键的消息，用RETURN键的消息替换，这样，按ESC的时候，也会执行刚才的OnOK函数，这样问题就可以解决了。</p>
<p>BOOL CxxxDlg::PreTranslateMessage(MSG* pMsg)<br />
{<br />
 if(pMsg->message==WM_KEYDOWN &#038;&#038; pMsg->wParam==VK_ESCAPE)<br />
 {<br />
 pMsg->wParam=VK_RETURN; //将ESC键的消息替换为回车键的消息，这样，按ESC的时候<br />
                                          //也会去调用OnOK函数，而OnOK什么也不做，这样ESC也被屏蔽<br />
  }<br />
 return CDialog::PreTranslateMessage(pMsg);</p>
<p>}</p>
<p>[biggrin]【方法2】</p>
<p>直接在重载的PreTranslateMessage函数中屏蔽回车和ESC的消息，和以上方法大同小异：</p>
<p>BOOL CxxxDlg::PreTranslateMessage(MSG* pMsg)<br />
{<br />
 if(pMsg->message==WM_KEYDOWN &#038;&#038; pMsg->wParam==VK_ESCAPE)  return TRUE;<br />
 if(pMsg->message==WM_KEYDOWN &#038;&#038; pMsg->wParam==VK_RETURN) return TRUE;<br />
 else<br />
    return CDialog::PreTranslateMessage(pMsg);<br />
}</p>
<h3  class="related_post_title">你可能也对下列文章感兴趣</h3><ul class="related_post"><li>2010年02月4日 -- <a href="http://www.xiaozhou.net/aboutsite/wordpress/modify_blog_comment_again-2010-02-04.htm" title="Blog评论功能再次改进">Blog评论功能再次改进</a> (20)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.xiaozhou.net/vcdevelopment/procedures-to-prevent-the-dialog-box-press-enter-and-esc-to-quit-countermeasures-2004-09-25.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
