如下:<br>function TApplication.MessageBox(const Text, Caption: PChar; Flags: Longint): Integer;<br>var<br> ActiveWindow: HWnd;<br> WindowList: Pointer;<br> MBMonitor, AppMonitor: HMonitor;<br> MonInfo: TMonitorInfo;<br> Rect: TRect;<br>begin<br> ActiveWindow := GetActiveWindow;<br> MBMonitor := MonitorFromWindow(ActiveWindow, MONITOR_DEFAULTTONEAREST);<br> AppMonitor := MonitorFromWindow(Handle, MONITOR_DEFAULTTONEAREST);<br> if MBMonitor <> AppMonitor then<br> begin<br> MonInfo.cbSize := Sizeof(TMonitorInfo);<br> GetMonitorInfo(MBMonitor, @MonInfo);<br> GetWindowRect(Handle, Rect);<br> SetWindowPos(Handle, 0,<br> MonInfo.rcMonitor.Left + ((MonInfo.rcMonitor.Right - MonInfo.rcMonitor.Left) div 2),<br> MonInfo.rcMonitor.Top + ((MonInfo.rcMonitor.Bottom - MonInfo.rcMonitor.Top) div 2),<br> 0, 0, SWP_NOACTIVATE or SWP_NOREDRAW or SWP_NOSIZE or SWP_NOZORDER);<br> end;<br> WindowList := DisableTaskWindows(0);<br> if UseRightToLeftReading then Flags := Flags or MB_RTLREADING;<br> try<br> Result := Windows.MessageBox(Handle, Text, Caption, Flags);<br> finally<br> if MBMonitor <> AppMonitor then<br> SetWindowPos(Handle, 0,<br> Rect.Left + ((Rect.Right - Rect.Left) div 2),<br> Rect.Top + ((Rect.Bottom - Rect.Top) div 2),<br> 0, 0, SWP_NOACTIVATE or SWP_NOREDRAW or SWP_NOSIZE or SWP_NOZORDER);<br> EnableTaskWindows(WindowList);<br> SetActiveWindow(ActiveWindow);<br> end;<br>end;<br>