How can I handle the Return key in a CEdit control?(如何处理 CEdit 控件中的 Return 键?)
问题描述
如何处理 CEdit 控件中的 Return 键 (VK_RETURN)?CEdit 控件的父级是 CDialog.
How can I handle the Return key (VK_RETURN) in a CEdit control? The CEdit control is parented to a CDialog.
推荐答案
您还可以在对话框的 PreTranslateMessage 中过滤键.如果您得到 VK_RETURN 的 WM_KEYDOWN,请调用 GetFocus.如果焦点在您的编辑控件上,请调用您对编辑控件中按下的返回的处理.
You could also filter for the key in your dialog's PreTranslateMessage. If you get WM_KEYDOWN for VK_RETURN, call GetFocus. If focus is on your edit control, call your handling for return pressed in the edit control.
注意 if 中的子句顺序依赖于短路是有效的.
Note the order of clauses in the if relies on short-circuiting to be efficient.
BOOL CMyDialog::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN &&
pMsg->wParam == VK_RETURN &&
GetFocus() == m_EditControl)
{
// handle return pressed in edit control
return TRUE; // this doesn't need processing anymore
}
return FALSE; // all other cases still need default processing
}
这篇关于如何处理 CEdit 控件中的 Return 键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何处理 CEdit 控件中的 Return 键?
基础教程推荐
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- CString 到 char* 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
