无法从 Windows 任务栏恢复最小化的程序
Cannot restore minimized program from Windows Taskbar
我的程序是用Delphi10写的。它在实际启动前显示了一个登录对话框,一切正常。
但是,如果我通过单击 Windows 任务栏(登录对话框处于活动状态)来最小化程序,它将永远保持最小化状态。
有谁知道解决办法吗?
Unit1.pas
class function TForm1.Execute: Boolean;
var
Dlg:TForm1;
begin
Dlg:=TForm1.Create(nil);
try
Result:=Dlg.ShowModal=mrOk;
finally
Dlg.Free;
end;
end;
Project1.dpr
begin
if not TForm1.Execute then //if i press on task bar, window will remain minimized forever.
Exit;
Application.Initialize;
Application.MainFormOnTaskbar := True;
//Moving TForm1.Execute here has no effect
Application.CreateForm(TForm1, Form1);
Application.Run;
end
我制作了一个示例代码,展示了如何在主窗体之前显示登录窗体。我检查了 (Win10) 通过单击任务栏最小化 window,它可以通过单击任务栏重新激活。
在登录表单中,我只用了两个按钮,一个用于登录成功,一个用于登录失败,没有实际检查任何 usercode/password。我以为你能做到那部分。
项目文件:
program LoginDemo;
uses
Vcl.Forms, Vcl.Dialogs, Vcl.Controls,
LoginDemoMain in 'LoginDemoMain.pas' {DemoMainForm},
LoginDemoDialog in 'LoginDemoDialog.pas' {DemoLoginForm};
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TDemoLoginForm, DemoLoginForm);
try
if DemoLoginForm.ShowModal <> mrOK then begin
ShowMessage('Invalid login, sorry...');
Exit;
end;
finally
DemoLoginForm.Free;
end;
Application.CreateForm(TDemoMainForm, DemoMainForm);
Application.Run;
end.
登录对话框:
unit LoginDemoDialog;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TDemoLoginForm = class(TForm)
LoginOKButton: TButton;
LoginFailedButton: TButton;
Label1: TLabel;
procedure LoginFailedButtonClick(Sender: TObject);
procedure LoginOKButtonClick(Sender: TObject);
end;
var
DemoLoginForm: TDemoLoginForm;
implementation
{$R *.dfm}
procedure TDemoLoginForm.LoginFailedButtonClick(Sender: TObject);
begin
Close;
ModalResult := mrCancel;
end;
procedure TDemoLoginForm.LoginOKButtonClick(Sender: TObject);
begin
Close;
ModalResult := mrOK;
end;
end.
主要形式:
unit LoginDemoMain;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TDemoMainForm = class(TForm)
Label1: TLabel;
ExitButton: TButton;
procedure ExitButtonClick(Sender: TObject);
end;
var
DemoMainForm: TDemoMainForm;
implementation
{$R *.dfm}
procedure TDemoMainForm.ExitButtonClick(Sender: TObject);
begin
Close;
end;
end.
我的程序是用Delphi10写的。它在实际启动前显示了一个登录对话框,一切正常。
但是,如果我通过单击 Windows 任务栏(登录对话框处于活动状态)来最小化程序,它将永远保持最小化状态。
有谁知道解决办法吗?
Unit1.pas
class function TForm1.Execute: Boolean;
var
Dlg:TForm1;
begin
Dlg:=TForm1.Create(nil);
try
Result:=Dlg.ShowModal=mrOk;
finally
Dlg.Free;
end;
end;
Project1.dpr
begin
if not TForm1.Execute then //if i press on task bar, window will remain minimized forever.
Exit;
Application.Initialize;
Application.MainFormOnTaskbar := True;
//Moving TForm1.Execute here has no effect
Application.CreateForm(TForm1, Form1);
Application.Run;
end
我制作了一个示例代码,展示了如何在主窗体之前显示登录窗体。我检查了 (Win10) 通过单击任务栏最小化 window,它可以通过单击任务栏重新激活。
在登录表单中,我只用了两个按钮,一个用于登录成功,一个用于登录失败,没有实际检查任何 usercode/password。我以为你能做到那部分。
项目文件:
program LoginDemo;
uses
Vcl.Forms, Vcl.Dialogs, Vcl.Controls,
LoginDemoMain in 'LoginDemoMain.pas' {DemoMainForm},
LoginDemoDialog in 'LoginDemoDialog.pas' {DemoLoginForm};
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TDemoLoginForm, DemoLoginForm);
try
if DemoLoginForm.ShowModal <> mrOK then begin
ShowMessage('Invalid login, sorry...');
Exit;
end;
finally
DemoLoginForm.Free;
end;
Application.CreateForm(TDemoMainForm, DemoMainForm);
Application.Run;
end.
登录对话框:
unit LoginDemoDialog;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TDemoLoginForm = class(TForm)
LoginOKButton: TButton;
LoginFailedButton: TButton;
Label1: TLabel;
procedure LoginFailedButtonClick(Sender: TObject);
procedure LoginOKButtonClick(Sender: TObject);
end;
var
DemoLoginForm: TDemoLoginForm;
implementation
{$R *.dfm}
procedure TDemoLoginForm.LoginFailedButtonClick(Sender: TObject);
begin
Close;
ModalResult := mrCancel;
end;
procedure TDemoLoginForm.LoginOKButtonClick(Sender: TObject);
begin
Close;
ModalResult := mrOK;
end;
end.
主要形式:
unit LoginDemoMain;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TDemoMainForm = class(TForm)
Label1: TLabel;
ExitButton: TButton;
procedure ExitButtonClick(Sender: TObject);
end;
var
DemoMainForm: TDemoMainForm;
implementation
{$R *.dfm}
procedure TDemoMainForm.ExitButtonClick(Sender: TObject);
begin
Close;
end;
end.