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 键?
基础教程推荐
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- c++ STL设置差异 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
