如何处理CEdit控件中的Return键? [英] How can I handle the Return key in a CEdit control?

查看:92
本文介绍了如何处理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_RETURNWM_KEYDOWN,请调用GetFocus.如果重点放在您的编辑控件上,请致电您的处理方法以获取在编辑控件中按下的return.

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键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆