Thread: How to know if my mouse left my main window app?

  1. #1
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    310

    Red face How to know if my mouse left my main window app?

    How?
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Maybe the TrackMouseEvent function
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    310
    Ok, this is my code:
    Code:
    LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    	static BOOL bLeave;
    	switch (uMsg)
    	{
    	case WM_CREATE:
    		{
    			return 0;
    		}
    	case WM_COMMAND:
    		{
    			return 0;
    		}
    	case WM_CLOSE:
    		{
    			DestroyWindow(hWnd);
    			return 0;
    		}
    	case WM_MOUSEMOVE:
    		{
    			TRACKMOUSEEVENT tme;
    			tme.cbSize = sizeof(TRACKMOUSEEVENT);
    			tme.dwFlags = TME_LEAVE|TME_HOVER;
    			tme.dwHoverTime = HOVER_DEFAULT;
    			tme.hwndTrack = hWnd;
    			_TrackMouseEvent(&tme); // WindowFromPoint
    
    			if (bLeave) {
    				POINTS pMouse;
    				char szMouse[24];
    
    				pMouse = MAKEPOINTS(lParam);
    				wsprintf(szMouse, "%i, %i", pMouse.x, pMouse.y);
    				SetWindowText(hWnd, szMouse); // display the mouse points
    			}
    			return 0;
    		}
    	case WM_MOUSEHOVER:
    		{
    			bLeave = FALSE;
    			return 0;
    		}
    	case WM_MOUSELEAVE:
    		{
    			bLeave = TRUE;
    			return 0;
    		}
    	case WM_DESTROY:
    		{
    			PostQuitMessage(0);
    			return 0;
    		}
    	}
    	return DefWindowProc(hWnd, uMsg, wParam, lParam);
    }
    My idea is that display the points only when the mouse is outside of my window, but instead it showed when is inside, any ideas?
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL rendering problem
    By JJFMJR in forum Game Programming
    Replies: 8
    Last Post: 08-31-2007, 07:26 PM
  2. Adding buttons, edit boxes, etc to the window
    By rainmanddw in forum Windows Programming
    Replies: 1
    Last Post: 04-10-2006, 03:07 PM
  3. Adding colour & bmps to a Win 32 Window??
    By carey_sizer in forum Windows Programming
    Replies: 4
    Last Post: 09-04-2004, 05:55 PM
  4. checking if mouse is over a window
    By canine in forum Windows Programming
    Replies: 14
    Last Post: 08-02-2002, 11:55 AM
  5. Please help me
    By teedee46 in forum C++ Programming
    Replies: 9
    Last Post: 05-06-2002, 11:28 PM