簡體   English   中英

如何在基於 MFC 對話框的應用程序中為復選框捕獲 MouseMove 事件?

[英]How to capture MouseMove event in a MFC Dialog Based application for a checkbox?

我的應用程序是具有多個屬性頁的基於 VC6 MFC 對話框的應用程序。

我必須在控件上捕獲 mousemove 事件,例如復選框。

如何在 MFC 中的復選框上捕獲 mousemove 事件?

復選框是一個按鈕控件(例如 CWnd)。 從 CCheckBox 派生您自己的類並處理 OnMouseMove 事件。

每個請求......假設一個從 CButton 派生的類......

BEGIN_MESSAGE_MAP(CMyCheckBox, CButton)
    ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()


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

    CButton::OnMouseMove(nFlags, point);
    }

感謝您的回復.. 我找到了一種方法來為我的應用程序獲取 mousemove 事件。

WM_SETCURSOR windows 消息使鼠標移動。 它返回控件和對話框的 Cwnd 指針。

在下面找到我的代碼。

BOOL CMyDialog::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
CWnd* pWndtooltip = GetDlgItem(IDC_STATIC_TOOLTIP); 

if (pWnd != this)
{
    if  (IDC_SN_START_ON == pWnd->GetDlgCtrlID())
        pWndtooltip->ShowWindow(SW_SHOW);

}
else
    pWndtooltip->ShowWindow(SW_HIDE);   

SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));


return true;

}

我在OnSetCursor()OnSetCursor()代碼中發現,IDC_STATIC_TOOLTIP 的關聯成員變量是您分配所需工具提示文本的變量。 例如,如果關聯變量是 m_strToolTip,則分配所需的文本以在懸停事件期間顯示,如下所示:

m_strToolTip.Format("%s", "Tool tip text goes here");

我還發現UpdateData()在進入事件處理程序,所以需要UpdateData(FALSE)返回之前需要。 SetCursor()調用在評論時似乎沒有效果。

您還可以覆蓋CDialog::PreTranslateMessage

BOOL CSomeDlg::PreTranslateMessage(MSG* pMsg)
{
  if (pMsg->message == WM_MOUSEMOVE && pMsg->hwnd == m_checkBox->m_hWnd)
  {
    ...
  }

  return CDialog::PreTranslateMessage(pMsg);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM