DevMaster.net Forums
[[ Home | Forums | 3D Engines Database | Wiki | Articles/Tutorials | Game Dev Jobs | IRC Chat Network | Contact Us ]]

Go Back   DevMaster.net Forums > Programming & Development > General Development
User Name
Password
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
Old 06-03-2004, 04:50 AM   #1
SpreeTree
Valued Member
 
SpreeTree's Avatar
 
Join Date: Jan 2004
Location: England
Posts: 265
Default

Hi guys

Is it possible for a window to recive mouse move messages when the mouse pointer is outside the client area? I know about WM_NCMOUSEMOVE, but that doesnt solve the problem of detecting movement when the cursor is totally out of the area of the window.

SetCapture only seems to work if the left mouse button is down, but this isnt good enough for what I'm after. It needs to detect it regardless of the mouse state

Thanks
Spree
SpreeTree is offline   Reply With Quote
Old 06-04-2004, 01:39 AM   #2
anubis
DevMaster Staff
 
anubis's Avatar
 
Join Date: Apr 2003
Location: Germany
Posts: 2,328
Default

i tihnk you have the option to either totally direct all input to the window, then you will get mouse movements even if the position is beyond the window boundaries. or you share the input. in the second case you have no way to catch the input. i might be wrong though...
___________________________________________
If Prolog is the answer, what is the question ?
anubis is offline   Reply With Quote
Old 06-04-2004, 08:38 AM   #3
Dia Kharrat
DevMaster Staff
 
Join Date: Jan 2003
Posts: 1,201
Default

Have you tried out the TrackMouseEvent function? You can call it to tell it to send the WM_MOUSELEAVE message when the mouse leaves your window. Also, the function GetCursorPos() gives you the mouse's position regardless of the which app has the focus. You can easily use it to make your own mouse-move detection scheme.
Dia Kharrat is offline   Reply With Quote
Old 06-04-2004, 09:30 AM   #4
anubis
DevMaster Staff
 
anubis's Avatar
 
Join Date: Apr 2003
Location: Germany
Posts: 2,328
Default

oh, i only thought about directx
normally you onyl direct messages to your window that are meant for it. however you can peek the windows message stack at any time. this will allow you to intercept any mouse movement, even outside of your window
___________________________________________
If Prolog is the answer, what is the question ?
anubis is offline   Reply With Quote
Old 07-27-2004, 02:04 AM   #5
Mashhack
New Member
 
Join Date: Jul 2004
Posts: 1
Arrow

This below code does the trick.

Also, on a related note... When a user holds down the mouse button (WM_LBUTTONDOWN), then drags the mouse out of the window and lets the mouse button up, you don't get the WM_LBUTTONUP message unless you use SetCapture() and ReleaseCapture() in your OnLButtonDown() and OnLButtonUp() functions respectively.


Code to detect the mouse leaving your window follows:


1. Add a timer UINT to your view class:

Code:
UINT m_uiMyTimer;


2. Initialise the timer UINT in your constructor:

Code:
void CMyView::CMyView() {  m_uiMyTimer = 0; }


3. When the mouse is initally in your window, start the timer:

Code:
void CMyView::OnMouseMove(UINT nFlags, CPoint point) {  if( m_uiMyTimer == 0 )   m_uiMyTimer = SetTimer(1, 100, NULL);  CView::OnMouseMove(nFlags, point); }


4. In OnTimer, detect if the mouse has left your window and post a message:

Code:
void CMyView::OnTimer(UINT nIDEvent) {  RECT rect;  POINT pt;  GetClientRect(&rect);  MapWindowPoints(NULL,&rect);  GetCursorPos(&pt);  if (!PtInRect(&rect,pt) || (WindowFromPoint(pt) != this))  {   if (!KillTimer(m_uiMyTimer))   {    ASSERT(0); // Error killing the timer!   }   m_uiMyTimer = 0;   PostMessage(WM_MOUSELEAVE,0,0);  }  CView::OnTimer(nIDEvent); }


5. Add a OnMouseLeave(..) handler:

(i) In your afx message map, in the .h file:
Code:
afx_msg LONG OnMouseLeave(WPARAM wParam, LPARAM lParam);

(ii) In your message map:
Code:
ON_MESSAGE(WM_MOUSELEAVE,OnMouseLeave)

(iii) OnMouseLeave Function
Code:
LONG CARCodeEditorView::OnMouseLeave(WPARAM wParam, LPARAM lParam) { TRACE( "MouseLeave\n" ); return 0; }


.... and that, is that.
Mashhack is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Forum Jump


All times are GMT -7. The time now is 12:06 PM.


Powered by vBulletin
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.