The example in this article describes how Delphi realizes the form's ability to sense the mouse over and automatically hide and display the window. Share it with everyone for your reference. The specific implementation method is as follows:
const WM_MouseEnter = $B013; WM_MouseLeave = $B014;type TfrmMain = class(TForm) . . Timer1: TTimer; procedure Timer1Timer(Sender: TObject); protected procedure WMMouseEnter(var Msg: TMessage); message WM_MouseEnter; end;implementation{$ R *.dfm}procedure TfrmMain.WMMouseEnter(var Msg: TMessage);begin if(Top<0) then begin Top := 0; //To ensure that the drop-down form is presented at the front SetWindowPos(Handle,HWND_TOPMOST,0,0,0,0, SWP_NOMOVE or SWP_NOSIZE); //Push the form to the front SetWindowPos(Handle,HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE or SWP_NOSIZE); //Then cancel the form to the front end; Timer1.Enabled := True;end;//Depend on timer Regularly check whether the mouse is still within the scope of the form, //This can avoid losing the MOUSELEAVE event procedure due to rapid movement of the mouse TfrmMain.Timer1Timer(Sender: TObject);var rc:TRECT; pt:TPOINT;begin GetWindowRect(self.Handle,rc); //Get the rectangular area of the form GetCursorPos(pt); //Get the current mouse position if( not PtInRect(rc,pt)) then //If the mouse is not within the scope of the form begin if(Top = 0) then //If the form is currently attached to the upper edge of the screen, move the hidden form up begin Top := 0-Height+2; end; Timer1.Enabled := False; //The timer is turned off after the form is hidden SetWindowPos(Handle ,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE or SWP_NOSIZE); //Push the form to the frontend;end;I hope this article will be helpful to everyone's Delphi programming.