4
votes

My application is a VC6 MFC dialog based application with multiple property pages.

I have to capture a mousemove event over a control, for example Checkbox.

How can I capture the mousemove events over a checkbox in MFC?

4
Curious, Why would you need to capture the mouse move for a checkbox? anyway, you can try using _TrackMouseEvent (or OnMouseMove as rrirower answered).Max
Actually I supposed to do Tooltip feature for the checkbox. My application is an ActiveX MFC based with Multiple propertypages. There tooltip was not supported. So I was trying to do workaround for that. Hence I need to capture the mousemove for a checkboxraj

4 Answers

6
votes

A checkbox is a button control (eg. CWnd). Derive your own class from CCheckBox and handle the OnMouseMove event.

Per request...assuming a class derived from 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);
    }
2
votes

Thanks for your replies.. I found a way to get the mousemove event for my app.

WM_SETCURSOR windows message gets the mouse move. It returns the Cwnd pointer for a control and the dialog.

Find my code below.

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;

}

0
votes

I found in @raj's OnSetCursor() code, that the associated Member variable for IDC_STATIC_TOOLTIP is that variable to which you assign the desired tool tip text. For example, if the associated variable is m_strToolTip, assign the desired text to display during the hovering event as follows:

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

I also found that UpdateData() was required upon entry into the event handler and UpdateData(FALSE) was required before the return. The SetCursor() call seems to have no effect when commented.

0
votes

You can also override CDialog::PreTranslateMessage:

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

  return CDialog::PreTranslateMessage(pMsg);
}