function TApplication.DoMouseIdle: TControl; var CaptureControl: TControl; P: TPoint; begin GetCursorPos(P); //获取当前鼠标所在位置 Result := FindDragTarget(P, True); //获取当前位置座标的控件 CaptureControl := GetCaptureControl; if FMouseControl <> Result then //判断以前记录的鼠标所指向控件和当前位置的控件是否相同 begin if ((FMouseControl <> nil) and (CaptureControl = nil)) or ((CaptureControl <> nil) and (FMouseControl = CaptureControl)) then FMouseControl.Perform(CM_MOUSELEAVE, 0, 0); //发送鼠标离开消息 FMouseControl := Result; if ((FMouseControl <> nil) and (CaptureControl = nil)) or ((CaptureControl <> nil) and (FMouseControl = CaptureControl)) then FMouseControl.Perform(CM_MOUSEENTER, 0, 0); //发送鼠标进入消息 end; end;