代替showmodal其他两种方法procedure TForm1.Button1Click(Sender: TObject);
begin
enablewindow(handle,false);//窗口一不可用
form2.show;end;
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
enablewindow(form1.handle,true);//可用
end;或var
Form1: TForm1;
WindowList: Pointer;
implementationuses Unit2;{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
begin
WindowList:= DisableTaskWindows(self.handle);
form2.show;end;uses Unit1;{$R *.DFM}procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
EnableTaskWindows(unit1.WindowList);
end;
begin
enablewindow(handle,false);//窗口一不可用
form2.show;end;
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
enablewindow(form1.handle,true);//可用
end;或var
Form1: TForm1;
WindowList: Pointer;
implementationuses Unit2;{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
begin
WindowList:= DisableTaskWindows(self.handle);
form2.show;end;uses Unit1;{$R *.DFM}procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
EnableTaskWindows(unit1.WindowList);
end;
show只是显示,可以切换界面
只是试下就知道了
没必要用enablewindow,这个是api函数,showmodal是vcl函数,里面就是调用了eanablewindow。
你只需要考虑什么场景用show或showmodal,后者模态窗口,占据在该进程中所有窗口的顶层,模态窗口提示用户介入,当返回后自动销毁窗口。
// ShowModal 源码
function TCustomForm.ShowModal: Integer;
var
WindowList: TTaskWindowList;
LSaveFocusState: TFocusState;
SaveCursor: TCursor;
SaveCount: Integer;
ActiveWindow: HWnd;
begin
CancelDrag;
if Visible or not Enabled or (fsModal in FFormState) or
(FormStyle = fsMDIChild) then
raise EInvalidOperation.Create(SCannotShowModal);
if GetCapture <> 0 then SendMessage(GetCapture, WM_CANCELMODE, 0, 0);
ReleaseCapture;
Application.ModalStarted;
try
{ RecreateWnd could change the active window }
ActiveWindow := GetActiveWindow;
Include(FFormState, fsModal);
if (PopupMode = pmNone) and (Application.ModalPopupMode <> pmNone) then
begin
RecreateWnd;
HandleNeeded;
{ The active window might have become invalid, refresh it }
if (ActiveWindow = 0) or not IsWindow(ActiveWindow) then
ActiveWindow := GetActiveWindow;
end;
LSaveFocusState := SaveFocusState;
Screen.SaveFocusedList.Insert(0, Screen.FocusedForm);
Screen.FocusedForm := Self;
SaveCursor := Screen.Cursor;
Screen.Cursor := crDefault;
SaveCount := Screen.CursorCount;
WindowList := DisableTaskWindows(0);
try
Show;
try
SendMessage(Handle, CM_ACTIVATE, 0, 0);
ModalResult := 0;
repeat
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;
{ 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;
原来EnableTaskWindow里就包装了EnableWindow。