怪事、窗口最小化后隐藏,再显示后,不能最小化了.(200)

bx59830

New Member
Member
#1
怪事、窗口最小化后隐藏,再显示后,不能最小化了.最小化按钮不起作用。代码如下unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;type TForm1 = class(TForm) Timer1: TTimer;
Button2: TButton;
procedure Timer1Timer(Sender: TObject);
procedure Button2Click(Sender: TObject);
private { Private declarations } public { Public declarations } end;
var Form1: TForm1;implementationuses Unit2;{$R *.dfm}procedure TForm1.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled := False;
Form2.Show;
//显示密码确认窗口 //如果当前Form1为最小化状态,隐藏再显示后就不能最小化。 //隐藏前使用 Form1.WindowState := wsMaximized;
无效 Form1.Hide;
//隐藏主窗口end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Timer1.Enabled := True;
end;
end.
unit Unit2;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,Unit1, StdCtrls;type TForm2 = class(TForm) Button1: TButton;
procedure Button1Click(Sender: TObject);
private { Private declarations } public { Public declarations } end;
var Form2: TForm2;implementation{$R *.dfm}procedure TForm2.Button1Click(Sender: TObject);
begin
Form1.Show;
//显示主窗口 Form2.Hide;
//隐藏当前窗口 end;
end.
 

bx59830

New Member
Member
#4
以上代吗在启动主窗口后,立即最小化主窗口,3秒钟后,Timer1会自动隐藏并显示主窗口,然后再最小化主窗口试试。
 

bx59830

New Member
Member
#5
Form1中有当前用户的工作数据、隐藏后再显示可以继续当前的工作,不想让无关人们看,隐藏主窗口后只显示form2窗口,特定的情况下再显示form1。
 

hs-kill

New Member
Member
#8
这个.....你可以理解成D7的BUG原因是你的form1为mainform 当你把form1最小化的时候,同时也把application最小化了(执行了TApplication.Minimize)而form1.show的时候却没有让application还原,所以你再次最小化的时候就出问题了看代码procedure TApplication.Minimize;
begin
if not IsIconic(FHandle) then
{问题出在这里,form1.show以后,application仍然是最小化状态,isiconic会返回true,从而导致不执行下面的代码} begin
NormalizeTopMosts;
SetActiveWindow(FHandle);
if (MainForm <> nil) and (ShowMainForm or MainForm.Visible) and IsWindowEnabled(MainForm.Handle) then
begin
SetWindowPos(FHandle, MainForm.Handle, MainForm.Left, MainForm.Top, MainForm.Width, 0, SWP_SHOWWINDOW);
DefWindowProc(FHandle, WM_SYSCOMMAND, SC_MINIMIZE, 0);
end else
ShowWinNoAnimate(FHandle, SW_MINIMIZE);
if Assigned(FOnMinimize) then
FOnMinimize(Self);
end;
end;
解决方法,加一句话就OK:begin
application.Restore;
{这个,先把application还原} Form1.Show;
//显示主窗口 Form2.Hide;
//隐藏当前窗口end;
 

Users Who Are Viewing This Thread (Users: 1, Guests: 0)