MFC 教程-回车时窗口退出问题

【问题描述】

MFC窗口默认时,按回车窗口会退出

【原因分析】

默认调用OnOK()

【解决办法】

重写虚函PreTranslateMessage

BOOL CTESTMFCDlg::PreTranslateMessage(MSG* pMsg)
{
	// TODO: 在此添加专用代码和/或调用基类
	//   修改回车键的操作反应 
	if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
	{
		UINT   nID;
		nID = GetFocus()->GetDlgCtrlID();
		if (IDC_EDIT == nID) {
			CString str;
			str.Format(_T("%d"), nID);
			AfxMessageBox(str);			
			return false;
		}
	}	
	return CDialogEx::PreTranslateMessage(pMsg);
}

相关推荐

  1. 控制台程序退出触发事件

    2024-06-09 02:14:03       35 阅读
  2. uni-app左上角退出,嵌套iframe退出异常问题

    2024-06-09 02:14:03       15 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-09 02:14:03       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-09 02:14:03       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-09 02:14:03       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-09 02:14:03       18 阅读

热门阅读

  1. Linux内核链表源代码

    2024-06-09 02:14:03       6 阅读
  2. IP路由基础&ospf

    2024-06-09 02:14:03       11 阅读
  3. 微信小程序的tabbar怎么配置

    2024-06-09 02:14:03       9 阅读
  4. zeppelin(kylin的可视化界面安装)(从头到尾安装)

    2024-06-09 02:14:03       11 阅读
  5. Hash & String 学习笔记

    2024-06-09 02:14:03       8 阅读
  6. creating an HTML file with SQL*Plus

    2024-06-09 02:14:03       9 阅读
  7. CVPR2024论文解读大盘点

    2024-06-09 02:14:03       9 阅读
  8. 新日本语教程 上册语法汇总

    2024-06-09 02:14:03       8 阅读
  9. Electric dust cart introduction

    2024-06-09 02:14:03       9 阅读