Click here to Skip to main content
15,914,225 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionCFormView - Mouse over, mouse out? Pin
dazinith14-Oct-02 11:12
dazinith14-Oct-02 11:12 
AnswerRe: CFormView - Mouse over, mouse out? Pin
valikac14-Oct-02 11:47
valikac14-Oct-02 11:47 
GeneralRe: CFormView - Mouse over, mouse out? Pin
valikac14-Oct-02 11:54
valikac14-Oct-02 11:54 
GeneralRe: CFormView - Mouse over, mouse out? Pin
dazinith15-Oct-02 3:50
dazinith15-Oct-02 3:50 
GeneralRe: CFormView - Mouse over, mouse out? Pin
valikac15-Oct-02 4:34
valikac15-Oct-02 4:34 
AnswerRe: CFormView - Mouse over, mouse out? Pin
Joaquín M López Muñoz14-Oct-02 11:52
Joaquín M López Muñoz14-Oct-02 11:52 
GeneralRe: CFormView - Mouse over, mouse out? Pin
dazinith15-Oct-02 3:42
dazinith15-Oct-02 3:42 
AnswerRe: CFormView - Mouse over, mouse out? Pin
Roman Fadeyev14-Oct-02 19:59
Roman Fadeyev14-Oct-02 19:59 
To track mouse events use _TrackMouseEvent. It sends to wnd event WM_MOUSELEAVE, when mouse goes out.
Example:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static BOOL bMouseInside;

    switch (message) 
    {

        case WM_MOUSEMOVE:
            {
                TRACKMOUSEEVENT tme;
                tme.cbSize = sizeof(tme);
                tme.hwndTrack = hWnd;
                tme.dwFlags = TME_LEAVE;

                _TrackMouseEvent(&tme);

                if(!bMouseInside)
                {
                    bMouseInside = TRUE;
                    InvalidateRect(hWnd, NULL, FALSE);
                    UpdateWindow(hWnd);
                }
            }
            break;

        case WM_MOUSELEAVE:
            bMouseInside = FALSE;
            InvalidateRect(hWnd, NULL, FALSE);
            UpdateWindow(hWnd);
            break;


The second approach is to use timer for periodically checking mouse position. If you received WM_MOUSEMOVE for the first time, you should enable timer, until you detect mouse absence
Example:

BOOL CMouseEvent::OnMouseMove....
{
    if( m_uTimer != 0 )
        return TRUE;

    m_uTimer = ::SetTimer( pWnd->m_hWnd, IDS_TIMER_MOUSE_EVENT, 10, NULL ); 
    if( m_uTimer )
    {
        m_hWnd = pWnd->m_hWnd;
        ::SendMessage( pWnd->m_hWnd, UWM_MOUSE_ENTER, 0, 0 );
    }

    return m_uTimer != 0 ? TRUE : FALSE ;
}


BOOL CMouseEvent::OnTimer(CWnd *pWnd )
{
    CPoint pt;
    ::GetCursorPos( &pt );

    if( pWnd != CWnd::WindowFromPoint( pt ) )
    {
        ::KillTimer( pWnd->m_hWnd, m_uTimer );
        m_uTimer = 0;
        m_hWnd = NULL;
        //mouse came out
    }

    return TRUE;
}

QuestionWhy does the window i create in a function close when the function returns? Pin
Anonymous14-Oct-02 11:01
Anonymous14-Oct-02 11:01 
AnswerRe: Why does the window i create in a function close when the function returns? Pin
Joaquín M López Muñoz14-Oct-02 11:05
Joaquín M López Muñoz14-Oct-02 11:05 
GeneralRe: Why does the window i create in a function close when the function returns? Pin
Anonymous14-Oct-02 11:11
Anonymous14-Oct-02 11:11 
GeneralRe: Why does the window i create in a function close when the function returns? Pin
Joaquín M López Muñoz14-Oct-02 11:18
Joaquín M López Muñoz14-Oct-02 11:18 
GeneralComboBox Pin
MFC is the Best14-Oct-02 10:55
MFC is the Best14-Oct-02 10:55 
GeneralCSocket question! Pin
Anonymous14-Oct-02 10:44
Anonymous14-Oct-02 10:44 
GeneralRe: CSocket question! Pin
Joaquín M López Muñoz14-Oct-02 11:02
Joaquín M López Muñoz14-Oct-02 11:02 
GeneralProblem with CListCtrl::DeleteColumn(0) Pin
Cris14-Oct-02 10:29
Cris14-Oct-02 10:29 
GeneralRe: Problem with CListCtrl::DeleteColumn(0) Pin
valikac14-Oct-02 11:57
valikac14-Oct-02 11:57 
GeneralRe: Problem with CListCtrl::DeleteColumn(0) Pin
Cris15-Oct-02 1:41
Cris15-Oct-02 1:41 
GeneralRe: Problem with CListCtrl::DeleteColumn(0) Pin
valikac15-Oct-02 4:32
valikac15-Oct-02 4:32 
GeneralRe: Problem with CListCtrl::DeleteColumn(0) Pin
Cris15-Oct-02 4:42
Cris15-Oct-02 4:42 
GeneralRe: Problem with CListCtrl::DeleteColumn(0) Pin
Chris Richardson14-Oct-02 12:03
Chris Richardson14-Oct-02 12:03 
GeneralRe: Problem with CListCtrl::DeleteColumn(0) Pin
Cris15-Oct-02 1:39
Cris15-Oct-02 1:39 
GeneralRe: Problem with CListCtrl::DeleteColumn(0) Pin
Chris Richardson15-Oct-02 8:01
Chris Richardson15-Oct-02 8:01 
GeneralAccessing a dialog box's system menu Pin
smjones14-Oct-02 9:40
smjones14-Oct-02 9:40 
GeneralRe: Accessing a dialog box's system menu Pin
Joaquín M López Muñoz14-Oct-02 9:40
Joaquín M López Muñoz14-Oct-02 9:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.