diff --git a/lcl/interfaces/win32/win32callback.inc b/lcl/interfaces/win32/win32callback.inc
index 07431088a46c377a9fb9fd1cb525ac1d47d2a888..afd30c06b35c8d1aed51a0456afcc1afde8e3830 100644
--- a/lcl/interfaces/win32/win32callback.inc
+++ b/lcl/interfaces/win32/win32callback.inc
@@ -1987,7 +1987,7 @@ begin
 
   case Msg of
     WM_MOUSEFIRST..WM_MOUSELAST:
-    if Application.MouseControl<>lWinControl then
+    if (LastMouseTracking<>lWinControl) then
     begin
       // register for WM_MOUSELEAVE
       FillChar(LMouseEvent, SizeOf(TTRACKMOUSEEVENT), 0);
@@ -1996,6 +1996,7 @@ begin
       LMouseEvent.hwndTrack := Window;
       LMouseEvent.dwHoverTime := HOVER_DEFAULT;
       _TrackMouseEvent(@LMouseEvent);
+      LastMouseTracking := lWinControl;
     end;
   end;
 
@@ -2254,7 +2255,11 @@ begin
     begin
       NotifyUserInput := True;
       LMessage.Msg := LM_MOUSELEAVE;
-      Application.DoBeforeMouseMessage(nil);
+      if lWinControl=LastMouseTracking then
+      begin
+        Application.DoBeforeMouseMessage(nil);
+        LastMouseTracking := nil;
+      end;
     end;
     WM_MOUSEMOVE:  DoMsgMouseMove;
     WM_MOUSEWHEEL: if DoMsgMouseWheel(Result, False) then Exit;
diff --git a/lcl/interfaces/win32/win32int.pp b/lcl/interfaces/win32/win32int.pp
index 9d2250a3f95d2307ff70812d0046c626ddd045cc..7d76e70129b1bc8ca59b7ee267e431f6a744316b 100644
--- a/lcl/interfaces/win32/win32int.pp
+++ b/lcl/interfaces/win32/win32int.pp
@@ -274,6 +274,7 @@ type
 
 var
   LastMouse: TLastMouseInfo;
+  LastMouseTracking: TControl = nil;
   ComboBoxHandleSizeWindow: HWND = 0;
   IgnoreNextCharWindow: HWND = 0;  // ignore next WM_(SYS)CHAR message
   IgnoreKeyUp: Boolean = True; // ignore KeyUp after application start; issue #30836