繁体   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