Reputation: 347
Is there anyway when mouse moving find the control mouse is over on it? I mean if you have a dialog with some labels and text boxes, and the mouse move to label, notify me that label name, after that if move it to text box notify the text box name.
Upvotes: 0
Views: 2346
Reputation: 11
After some research, I came to this code which let me know if the mouse cursor is over my control in a dialog box.
//Handling mouse move in mfc dialog
void CDialogRoll::OnMouseMove(UINT nFlags, CPoint point)
{
CRect rect1;
m_FrameArea.GetClientRect(&rect1); //control rectangle
m_FrameArea.ClientToScreen(&rect1)
ScreenToClient(&rect1); //dialog coordinates`
if (point.x >= rect1.left && point.x <= rect1.right && point.y >= rect1.top &&
point.y <= rect1.bottom) {
char str[100];
sprintf(str, "%d-%d", point.x - rect1.left, point.y - rect1.top);
}
CDialogEx::OnMouseMove(nFlags, point);
}
Upvotes: 1
Reputation: 4590
If you handle WM_MOUSEMOVE within your dialog, you can grab the mouse position, convert it to dialog coordinates, and determine what control lies underneath the cursor point.
Upvotes: 1