Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 667
raj Avatar asked Feb 13 '23 11:02

raj


2 Answers

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);
    }
like image 137
rrirower Avatar answered Feb 16 '23 01:02

rrirower


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;

}

like image 37
raj Avatar answered Feb 16 '23 01:02

raj