I want to capture the WM_MOUSEMOVE message for a button so I can change the cursor when the mouse is over the button. Anyone know how I could do this?
I want to capture the WM_MOUSEMOVE message for a button so I can change the cursor when the mouse is over the button. Anyone know how I could do this?
You can have some simple collision detection to check for this. Make a bounding box around your cursor and a box around the button. Then use the API IntersectRect() to determine if they collide with one another. It will return true if a collision took place. Alternatively you can just check whether the coordinates given from WM_MOUSEMOVE are inside the rect that forms your button. When your application receives a WM_MOUSEMOVE message you can obtain the cursor's position by checking LOWORD and HIWORD of lParam.
Something like that. Hope this helped some.Code:COORD Pos; Pos.x = LOWORD(lParam); Pos.y = HIWORD(lParam);
"...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers
Yah, but the dialog won't send the WM_MOUSEMOVE message when it is over the button so I can't check if it is over the button or not. I don't know if I am missing something here cause this is what everyone keeps telling me to do and its not working. My code wich is posted below is giving me some wierd results. It changes the mouse cursor but not in the right spot.
Even if I put the following code in WM_INITDIALOG it changes the cursor but only when it is on the dialog , not over any controls.Code:case WM_MOUSEMOVE: POINT mousePos; RECT imagePos; mousePos.x = LOWORD(lParam); mousePos.y = HIWORD(lParam); GetWindowRect(GetDlgItem(hwnd, IDC_BANNERSITE), &imagePos); if(PtInRect(&imagePos, mousePos)) SetCursor(LoadCursor(NULL, IDC_HAND)); break;
I think if I can capture the WM_MOUSEMOVE message for the button then I could change the cursor and it would work.Code:Hand=LoadCursor(NULL,(IDC_HAND)); SetClassLong(hwnd,GCL_HCURSOR,(long)Hand); SetCursor(Hand);
Try
Hand=LoadCursor(NULL,(IDC_HAND));
SetClassLong(hWndButton,GCL_HCURSOR,(long)Hand);
SetCursor(Hand);
as a work around
PS
I think the problem is in how you created the button.
Its msgs are passed to the callback if you click on it?
Did you create it with the WS_CHILD?
Or is it from a resource editor?
"Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
Friedrich Nietzsche
"I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
George Best
"If you are going through hell....keep going."
Winston Churchill
Thank you so much, it worked except that the mouse cursor changes for every button. No, the messages are not sent to a callback, thats what I wanted to know how to do in the first post. The button is created with a resource editor.
Try the following:
Subclass the button control you want to change the cursor for. As you have noted SetClassLong will change the selected paramater for ALL windows of that class. Use SetWindowLong to change the WNDPROC for a specific control, handle the WM_SETCURSOR for that control and use SetCursor within that handler to attach any cursor you want to that control. All other messages should be sent to the default wnd proc for the control with CallWindowProc for default handling behaviour.
ok, I looked into SetWindowLong but you can only change the wndproc for a dialog. Isn't there anyway to just change the cursor of the one button instead of the whole class like SetClassLong does?
>>I looked into SetWindowLong but you can only change the wndproc for a dialog<<
You can change the wndproc for anything the SetWindowLong function will let you away with.
See attached code for an example of subclassed button with changed cursor.
CProgramming FAQ
Caution: this person may be a carrier of the misinformation virus.
THANK YOU SO MUCH, I have been trying to do this for weeks.