简体   繁体   English

初始化双击MFC中的编辑控件

[英]initialize double click on edit control in MFC

I am trying to set an mouse click event on editbox and when I am double clicking on edit box it should bring up a message box. 我试图在editbox上设置一个鼠标单击事件,当我双击edit box时,应该会弹出一个消息框。

ON_WM_LBUTTONDBLCLK(IDC_EDITItem, &MessageManage::OnItemDoubleClick)

void MessageManage::OnItemDoubleClick()
{
    MessageBox( m_strItemMsg, "Sample code", MB_OK | MB_ICONINFORMATION );
}

It's not taking double click event from edit box 它不接受来自编辑框的双击事件

One way to accomplish this is to derive your own class from CEdit and handle ON_WM_LBUTTONDBLCLK() . 一种实现方法是从CEdit派生您自己的类并处理ON_WM_LBUTTONDBLCLK() The following code responded to the double click on an edit control in a sample program. 下面的代码响应了示例程序中双击编辑控件。

BEGIN_MESSAGE_MAP(MyEdit, CEdit)
    ON_WM_LBUTTONDBLCLK()
END_MESSAGE_MAP()

// MyEdit message handlers

void MyEdit::OnLButtonDblClk(UINT nFlags, CPoint point)
{
    // TODO: Add your message handler code here and/or call default

    CEdit::OnLButtonDblClk(nFlags, point);
}

At alternative is to just use PreTranslateMessage on your dialog: 另外一种选择是在对话框上使用PreTranslateMessage

BOOL CMFCApplication1Dlg::PreTranslateMessage(MSG* pMsg)
{
    if (pMsg->message == WM_LBUTTONDBLCLK &&
        pMsg->hwnd == ::GetDlgItem(m_hWnd, IDC_EDIT1))
    {
        AfxMessageBox(_T("Run Code"));
        return TRUE; //Important!!! Message is handled
    }

    return CDialogEx::PreTranslateMessage(pMsg);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM