// VCL.Forms.pas 7352
function TCustomForm.ShowModal: Integer;
var
WindowList: TTaskWindowList;
LSaveFocusState: TFocusState;
SaveCursor: TCursor;
SaveCount: Integer;
ActiveWindow: HWnd;
begin
// ... schnipp ...
Application.ModalStarted;
try
{ RecreateWnd could change the active window }
ActiveWindow := GetActiveWindow;
// ... schnipp ...
WindowList := DisableTaskWindows(0);
try
Show;
try
SendMessage(
Handle, CM_ACTIVATE, 0, 0);
ModalResult := 0;
repeat // Message-Loop zum Verarbeiten der Messages
Application.HandleMessage;
if Application.Terminated
then ModalResult := mrCancel
else
if ModalResult <> 0
then CloseModal;
until ModalResult <> 0;
Result := ModalResult;
SendMessage(
Handle, CM_DEACTIVATE, 0, 0);
if GetActiveWindow <>
Handle then ActiveWindow := 0;
finally
Hide;
end;
finally
if Screen.CursorCount = SaveCount
then
Screen.Cursor := SaveCursor
else Screen.Cursor := crDefault;
EnableTaskWindows(WindowList);
if Screen.SaveFocusedList.Count > 0
then
begin
Screen.FocusedForm := TCustomForm(Screen.SaveFocusedList.First);
Screen.SaveFocusedList.Remove(Screen.FocusedForm);
end else Screen.FocusedForm :=
nil;
// Hier wird jetzt versucht das alte Fenster wieder zu aktivieren
{ ActiveWindow might have been destroyed and using it as active window will
force Windows to activate another application }
if (ActiveWindow <> 0)
and not IsWindow(ActiveWindow)
then
ActiveWindow := FindTopMostWindow(0);
if ActiveWindow <> 0
then
SetActiveWindow(ActiveWindow);
RestoreFocusState(LSaveFocusState);
Exclude(FFormState, fsModal);
end;
finally
Application.ModalFinished;
end;
end;