Click to See Complete Forum and Search --> : Don't get WM_MOUSEMOVE from button
slcoder
August 1st, 2005, 04:19 AM
I have a modal dialog box. I want the dialog's proc function to get the WM_MOUSEMOVE message from a the OK button.
I use SPY++ and see that the dialog proc doesn't get the WM_MOUSEMOVE message from its child buttons. Only the button itself gets this message.
How can I process this message?
philkr
August 1st, 2005, 05:02 AM
The dialog proc should get a WM_COMMAND message with the notification code in HIWORD(wParam). Don't know if that is also true for WM_MOUSEMOVE, but I think so.
slcoder
August 1st, 2005, 05:15 AM
The dialog proc should get a WM_COMMAND message with the notification code in HIWORD(wParam). Don't know if that is also true for WM_MOUSEMOVE, but I think so.
No, it isn't true for WM_MOUSEMOVE.
philkr
August 1st, 2005, 05:35 AM
OK, I did some testing with Spy++. There is a special message for it: WM_SETCURSOR with HIWORD(lParam) as WM_MOUSEMOVE and (HWND)wParam as the window handle of the window where the mouse currently is over.
slcoder
August 1st, 2005, 06:24 AM
OK, I did some testing with Spy++. There is a special message for it: WM_SETCURSOR with HIWORD(lParam) as WM_MOUSEMOVE and (HWND)wParam as the window handle of the window where the mouse currently is over.
I know that I get WM_SETCURSOR message, but I ask about WM_MOUSEMOVE!
philkr
August 1st, 2005, 06:37 AM
For what do you need WM_MOUSEMOVE then? I thought you wanted to chenge the mouse cursor. If you already handle WM_SETCURSOR, don't call DefWindowProc() and don't return FALSE for dialogs.
NoHero
August 2nd, 2005, 03:20 AM
To handle window messages from you must subclass the button and/or use _TrackMouseMessage() (I can't remember the proper name of it): Check this thread: http://www.codeguru.com/forum/showthread.php?t=321340
Ali Imran
August 3rd, 2005, 06:52 AM
btw I tried following in the subclass procedure and it did not work perfect, maybe someone can fix it.
case WM_MOUSEMOVE: {
PeekMessage(&msg,hwnd,0,0,PM_REMOVE);
return 0;
}
and yes gurus,
Isn't there any way we can forward the WM_MOUSEMOVE to the parent control this way ?
SendMessage(GetParent(hwnd),WM_MOUSEMOVE, wParam, lParam);
but unfortunately this sends wParam and lParam of current button which are definitely different in the parent window. e.g. button is on x:100 and y: 100, and mouse is moving on button and is currently on position 50, 50. So by above method if the WM_MOUSEMVOE is sent to parent window it will consider current mouse position 50, 50 through lParam and wParam, where the parent window must have 150, 150.
I am also in search of the same functionality, if possible please direct.
regards
philkr
August 3rd, 2005, 07:18 AM
Use ClientToScreen() with child window handle and then ScreenToClient() with parent windows handle. Now you have converted the coordinates to parent window coordinates.
Ali Imran
August 3rd, 2005, 11:57 AM
Function seems to be perfect but still no luck.
What I tried is I forwarded message WM_MOUSEMOVE to parent window when mouse was rolling over the child button, this way
case WM_MOUSEMOVE: {
POINT cp;
POINT cp={ LOWORD(lParam), HIWORD(lParam) }; //add x and y mouse coo
//convert current x, y mouse to parent x y mouse
ClientToScreen(hwnd,&cp);coordinates
//forward message to parent window so that parent processes the message
SendMessage(GetParent(hwnd),WM_MOUSEMOVE,0, MAKELONG(cp.x, cp.y));
return 0;
}
I want to get this method working since this one seems to be best to me, forwarding the message to parent is I think better than killing the message.
I hope sone guru gets it solved for us sooner.
btw thanks so much for kind replies.
regards
philkr
August 3rd, 2005, 12:06 PM
Where is the ScreenToClient() function?
Ali Imran
August 3rd, 2005, 12:18 PM
Am a bit confused now
doesn't folowing code convert the current mouse coordinates to parent window's mouse coordinates ?
//convert current x, y mouse to parent x y mouse
ClientToScreen(hwnd,&cp);
and then I want to forward those points to parent
SendMessage(GetParent(hwnd),WM_MOUSEMOVE,0, MAKELONG(cp.x, cp.y));
Am wondering, is there any need of using ScreenToClient() ?
regards
philkr
August 3rd, 2005, 12:42 PM
No. It converts to screen coordinates like the name says. The problem is that there is no direct conversion function in the windows API as far as I know. You will have to do it this way:
ClientToScreen(hwnd, &cp);
ScreenToClient(GetParent(hwnd), &cp);
Ali Imran
August 3rd, 2005, 12:47 PM
Perfect, Perfect, Perfect
following code worked 100% (and last problem of my resource editor is also fixed ;) )
here is code for subclass window procedure of the button, it may help others
case WM_MOUSEMOVE: {
POINT cp={ LOWORD(lParam), HIWORD(lParam) };
ClientToScreen(hwnd,&cp);
ScreenToClient(GetParent(hwnd), &cp);
SendMessage(GetParent(hwnd),WM_MOUSEMOVE,0,MAKELONG(cp.x, cp.y));
return 0;
}
You have been rated.
regards
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.