Home » programming

MFC中屏蔽ESC和回车关闭对话框

By: Zhiqiang Ma On: Jul 4, 2009 Views: 83 No Comment Print Email
Tags: , ,

解决方法是在CDialog::PreTranslateMessage() 的重载函数中将ESC和回车按键的消息处理掉.
直接上代码:

BOOL
CResultCollectorDlg::PreTranslateMessage(MSG* pMsg)
{
  if(pMsg->message == WM_KEYDOWN) {
    switch(pMsg->wParam) {
      case VK_RETURN: //回车
        return TRUE;
      case VK_ESCAPE: //ESC
        return TRUE;
    }
  }
  return CDialog::PreTranslateMessage(pMsg);
}

Read more:

Digg del.icio.us Stumble Techorati Facebook Newsvine Reddit Twitter
Mixx LinkedIn Google Bookmark Yahoo Bookmark MySpace LiveJournal Blogger RSS feed

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.