_TrackMouseEvent not working
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: _TrackMouseEvent not working

Threaded View

  1. #1
    Join Date
    Dec 2004
    Posts
    61

    Unhappy _TrackMouseEvent not working

    Dear Gurus,

    I'm facing a problem with the _TrackMouseEvent
    Below is my coding:

    Code:
    void CMyDlg::OnMouseMove(UINT nFlags, CPoint point)
    {
     
    		if(!m_bStartTracking) //set the m_bStartTracking =FALSE in constructor
    		{
    			SetCapture();
    			m_bStartTracking = TRUE;
    			StartTrackMouseLeave();
    			printf("Start Tracking...\n");
    		}
    		
    		CDialog::OnMouseMove(nFlags, ptNorm);
    }
    
    BOOL CMyDlg::StartTrackMouseLeave()
    {
    	TRACKMOUSEEVENT tme;
    	ZeroMemory( &tme, sizeof(TRACKMOUSEEVENT));
    	tme.cbSize = sizeof(TRACKMOUSEEVENT);
    	tme.dwFlags = TME_LEAVE;
    	tme.hwndTrack = this->m_hWnd;
    	tme.dwHoverTime = HOVER_DEFAULT;
    	_TrackMouseEvent(&tme);
    
    	return TRUE;
    }
    
    LRESULT CMyDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
    {
    	if(message == WM_MOUSELEAVE)
    	{
    		m_bStartTracking = FALSE;
    		ReleaseCapture();
    		printf("Stop Tracking......1\n");
    	}
    
    	return CDialog::WindowProc(message, wParam, lParam);
    }
    as my mouse cursor move inside the dialog, i get this message:
    Start tracking...
    Stop tracking...1
    Start tracking...
    Stop tracking...1
    ...
    Start tracking...
    Stop tracking...1

    The message stop when my mouse leave the dialog client area.
    The above message repeat again when my mouse go inside the dialog client area.

    This is not what i want.
    The code able to detect when the mouse go inside the dialog client area.
    But it seem to be don't know when it leave the client area.
    It entering the dialog area and leave the client area at the same time(refer to the message above)
    That is why i get the message above.
    But the _TrackMouseEvent only will post the message WM_MOUSELEAVE when the mouse leave the
    client area but it did not work that way. Why?

    I have check the MSDN and found that the the default area of the mouse hover area just as the mouse click area.
    That is 4 pixels. so i have try to adjust the area to the dialog client are with the code below:
    But i'm still getting the same result.

    Code:
    void CMyDlg::OnMouseMove(UINT nFlags, CPoint point)
    {
     
    		if(!m_bStartTracking) //set the m_bStartTracking =FALSE in constructor
    		{	
                      CRect rcWnd(0,0,0,0);	
                      GetWindowRect(&rcWnd);
                      SystemParametersInfo(SPI_SETMOUSEHOVERHEIGHT,rcWnd.Height(), 0, 0);
    		  SystemParametersInfo(SPI_SETMOUSEHOVERWIDTH,rcWnd.Width(), 0, 0);
    
    
    			SetCapture();
    			m_bStartTracking = TRUE;
    			StartTrackMouseLeave();
    			printf("Start Tracking...\n");
    		}
    		
    		CDialog::OnMouseMove(nFlags, ptNorm);
    }
    I have search through the similar post in Codeguru but not luck, I did not found the solution there.
    Can somebody help me.
    Thanks.
    Last edited by VbEndUser; October 31st, 2012 at 12:23 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center