在工具栏的按钮上检测 WM_LBUTTONDBLCLK

Detect WM_LBUTTONDBLCLK on a button of Toolbar

我们如何检测工具栏上按钮(例如 ID_FILE_NEW)上的 WM_LBUTTONDBLCLK

PreTranslateMessage() 这似乎很简单。我已经用这个代码片段进行了测试。

BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
{
    // Detect Clicks in Toolbar detektieren
    if (pMsg->hwnd == m_wndToolBar.GetSafeHwnd())
    {
        if (pMsg->message == WM_LBUTTONDBLCLK)
        {
            CPoint pt = pMsg->pt;
            m_wndToolBar.ScreenToClient(&pt);

            int nIdx = m_wndToolBar.CommandToIndex(ID_FILE_NEW);
            CRect rcIdx;
            m_wndToolBar.GetItemRect(nIdx, &rcIdx);
            if (rcIdx.PtInRect(pt))
            {
                MessageBox(_T("yupii double click detected"));
                return TRUE;
            }
        }
    }
    return CMDIFrameWndEx::PreTranslateMessage(pMsg);
}