1

我是德尔福学习者。A 有一个具有 2 个表单(“Form001”和“Form002”)的项目。“Form001”上有一个按钮(“BitBtn001”)。“Form001”和“Form002”都由“FadeInTimer”创建,并由“FadeOutTimer”使用“FormCloseQuery”关闭。两个表单都由“FormMinimizeTimer”最小化并由“FormRetoreTimer”恢复。如果我单击“BitBtn001”,则会显示“Form002”。

这是我的项目的下载链接:

以下是实现逻辑:

表格 001:

unit KoushikHalder001;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons, Vcl.ExtCtrls,
  Vcl.Imaging.pngimage;

type
  TForm001 = class(TForm)
    Edit001: TEdit;
    Background: TImage;
    BitBtn001: TBitBtn;
    BitBtn002: TBitBtn;
    FadeInTimer: TTimer;
    FadeOutTimer: TTimer;
    FormMinimizeTimer: TTimer;
    FormRestoreTimer: TTimer;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure FormCreate(Sender: TObject);
    procedure FormHide(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure BitBtn001Click(Sender: TObject);
    procedure BitBtn002Click(Sender: TObject);
    procedure FadeInTimerTimer(Sender: TObject);
    procedure FadeOutTimerTimer(Sender: TObject);
    procedure FormClosingTimerTimer(Sender: TObject);
    procedure FormMinimizeTimerTimer(Sender: TObject);
    procedure FormRestoreTimerTimer(Sender: TObject);
  private
    { Private declarations }
    CrossButtonClick: Boolean;
    procedure WMNCHitTest(var Msg: TWMNCHitTest) ; message WM_NCHitTest;
    procedure WMSysCommand(var Msg: TWMSysCommand) ; message WM_SysCommand;
  public
    { Public declarations }
  end;

var
  Form001: TForm001;

implementation

{$R *.dfm}

uses KoushikHalder002;

procedure TForm001.WMNCHitTest(var Msg: TWMNCHitTest);
begin
  inherited;
  if ControlAtPos(ScreenToClient(Msg.Pos), True, True, True)= nil
    then
      begin
        if Msg.Result=htClient then Msg.Result := htCaption;
      end;
end;

procedure TForm001.WMSysCommand(var Msg: TWMSysCommand);
begin
  case Msg.CmdType of
    SC_MINIMIZE:
      begin
        if Form001.AlphaBlendValue > 0 then
          begin
            FormMinimizeTimer.Enabled := true;
            Exit;
          end;
      end;
    SC_RESTORE:
      begin
        if Form001.AlphaBlendValue < 220 then
          begin
            FormRestoreTimer.Enabled := True;
          end;
      end;
  end;
  inherited;
end;

procedure TForm001.BitBtn001Click(Sender: TObject);
begin
  if Form002.WindowState = wsMinimized then
    begin
      Form002.FormRestoreTimer.Enabled := true;
    end
    else
    Form002.show;
end;

procedure TForm001.BitBtn002Click(Sender: TObject);
begin
  FadeOutTimer.Enabled := true;
end;

procedure TForm001.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  FadeOutTimer.Enabled := true;
end;

procedure TForm001.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  if CrossButtonClick = true
    then
      begin
        CanClose := true;
        Exit;
      end;
  CanClose := false;
  FadeOutTimer.Enabled := true;
end;

procedure TForm001.FormCreate(Sender: TObject);
begin
  FadeInTimer.Enabled := true;
end;

procedure TForm001.FormHide(Sender: TObject);
begin
  FadeOutTimer.Enabled := true;
end;

procedure TForm001.FormShow(Sender: TObject);
begin
  FadeInTimer.Enabled := true;
end;

procedure TForm001.FadeInTimerTimer(Sender: TObject);
begin
  if Form001.AlphaBlendValue >= 220
    then
      begin
        FadeInTimer.Enabled := false;
      end
    else
      begin
        Form001.AlphaBlendValue := Form001.AlphaBlendValue + 10;
        CrossButtonClick := false;
      end;
end;

procedure TForm001.FadeOutTimerTimer(Sender: TObject);
begin
  if Form001.AlphaBlendValue <= 0
    then
      begin
        FadeOutTimer.Enabled := false;
        CrossButtonClick := true;
        Self.Close;
      end
    else
      begin
        Form001.AlphaBlendValue := Form001.AlphaBlendValue - 10;
        CrossButtonClick := true;
      end;
end;

procedure TForm001.FormClosingTimerTimer(Sender: TObject);
begin
  DoubleBuffered := true;
end;

procedure TForm001.FormMinimizeTimerTimer(Sender: TObject);
begin
  if Form001.AlphaBlendValue > 0 then
    begin
      Form001.AlphaBlendValue := Form001.AlphaBlendValue - 10;
    end
  else
    begin
      FormMinimizeTimer.Enabled := false;
      Perform(WM_SYSCOMMAND, SC_MINIMIZE, 0);
    end;
end;

procedure TForm001.FormRestoreTimerTimer(Sender: TObject);
begin
  if Form001.AlphaBlendValue < 220 then
    begin
      Form001.AlphaBlendValue := Form001.AlphaBlendValue + 10;
    end
  else
    begin
      FormRestoreTimer.Enabled := false;
    end;
end;

end.

表格 002:

unit KoushikHalder002;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons, Vcl.ExtCtrls,
  Vcl.Imaging.pngimage;

type
  TForm002 = class(TForm)
    Edit001: TEdit;
    Background: TImage;
    BitBtn001: TBitBtn;
    BitBtn002: TBitBtn;
    FadeInTimer: TTimer;
    FadeOutTimer: TTimer;
    FormClosingTimer: TTimer;
    FormMinimizeTimer: TTimer;
    FormRestoreTimer: TTimer;
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure FormHide(Sender: TObject);
    procedure BitBtn001Click(Sender: TObject);
    procedure BitBtn002Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FadeInTimerTimer(Sender: TObject);
    procedure FadeOutTimerTimer(Sender: TObject);
    procedure FormClosingTimerTimer(Sender: TObject);
    procedure FormMinimizeTimerTimer(Sender: TObject);
    procedure FormRestoreTimerTimer(Sender: TObject);
  private
    { Private declarations }
    CrossButtonClick: Boolean;
    procedure WMNCHitTest(var Msg: TWMNCHitTest) ; message WM_NCHitTest;
    procedure WMSysCommand(var Msg: TWMSysCommand) ; message WM_SysCommand;
  public
    { Public declarations }
  end;

var
  Form002: TForm002;

implementation

{$R *.dfm}

uses KoushikHalder001;

procedure TForm002.WMNCHitTest(var Msg: TWMNCHitTest);
begin
  inherited;
  if ControlAtPos(ScreenToClient(Msg.Pos), True, True, True)= nil
    then
      begin
        if Msg.Result=htClient then Msg.Result := htCaption;
      end;
end;

procedure TForm002.WMSysCommand(var Msg: TWMSysCommand);
begin
  case Msg.CmdType of
    SC_MINIMIZE:
      begin
        if Form002.AlphaBlendValue > 0 then
          begin
            FormMinimizeTimer.Enabled := true;
            Exit;
          end;
      end;
    SC_RESTORE:
      begin
        if Form002.AlphaBlendValue < 220 then
          begin
            FormRestoreTimer.Enabled := True;
          end;
      end;
  end;
  inherited;
end;

procedure TForm002.BitBtn001Click(Sender: TObject);
begin
  FadeOutTimer.Enabled := true;
end;

procedure TForm002.BitBtn002Click(Sender: TObject);
begin
  FormClosingTimer.Enabled := true;
end;

procedure TForm002.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  if CrossButtonClick = true
    then
      begin
        CanClose := true;
        Exit;
      end;
  CanClose := false;
  FadeOutTimer.Enabled := true;
end;

procedure TForm002.FormHide(Sender: TObject);
begin
  FadeOutTimer.Enabled := true;
end;

procedure TForm002.FormShow(Sender: TObject);
begin
  FadeInTimer.Enabled := true;
end;

procedure TForm002.FadeInTimerTimer(Sender: TObject);
begin
  if Form002.AlphaBlendValue >= 220
    then
      begin
        FadeInTimer.Enabled := false;
      end
  else
    begin
      Form002.AlphaBlendValue := Form002.AlphaBlendValue + 10;
      CrossButtonClick := false;
    end;
end;

procedure TForm002.FadeOutTimerTimer(Sender: TObject);
begin
  if Form002.AlphaBlendValue <= 0
    then
      begin
       FadeOutTimer.Enabled := false;
       CrossButtonClick := true;
       Self.Close;
      end
    else
      begin
        Form002.AlphaBlendValue := Form002.AlphaBlendValue - 10;
        CrossButtonClick := false;
      end;
end;

procedure TForm002.FormClosingTimerTimer(Sender: TObject);
begin
  if Form002.AlphaBlendValue <= 0
    then
      begin
        FadeOutTimer.Enabled := false;
        CrossButtonClick := false;
        Form001.Close;
      end
    else
      begin
        Form002.AlphaBlendValue := Form002.AlphaBlendValue - 10;
        CrossButtonClick := false;
      end;
end;

procedure TForm002.FormMinimizeTimerTimer(Sender: TObject);
begin
  if Form002.AlphaBlendValue > 0 then
    begin
      Form002.AlphaBlendValue := Form002.AlphaBlendValue - 10;
    end
  else
    begin
      FormMinimizeTimer.Enabled := false;
      Perform(WM_SYSCOMMAND, SC_MINIMIZE, 0);
    end;
end;

procedure TForm002.FormRestoreTimerTimer(Sender: TObject);
begin
  if Form002.AlphaBlendValue < 220 then
    begin
      Form002.AlphaBlendValue := Form002.AlphaBlendValue + 10;
    end
  else
    begin
      FormRestoreTimer.Enabled := false;
    end;
end;

end.

这里“CrossButtonClick”是“FormClosingQuery”中使用的全局布尔变量。

除了两个问题外,一切都很好。

问题 01: 如果我使用标题栏上的“X”按钮关闭“Form002”并再次单击“BitBtn001”(如“Image001”所示)图片001 ,则“Form002”再次显示。但问题是,如果“Form002”正在最小化并由“BitBtn001”显示,然后通过单击“X”按钮将其关闭(如“Image002”所示)图片002 并再次按下“BitBtn001”以显示“Form002”但不幸的是“Form002”不再显示。

问题 02: 如果我使用标题中的“RestoreUp”按钮恢复“Form002”(如“Image003”所示)“FormRestoreTimer”没有任何作用。图片003它只是正常恢复。请帮我。请告诉我我的错误。

4

1 回答 1

1

错误是:

procedure TForm001.BitBtn001Click(Sender: TObject);
begin
  if Form002.WindowState = wsMinimized then
    begin
      Form002.Perform(WM_SYSCOMMAND, SC_RESTORE, 0);  // ! - missed in your code
//      Form002.FormRestoreTimer.Enabled := true;   - not needed anymore
    end
    else
    Form002.show;
end;

恢复 Form002 时可能看不到褪色效果,因为褪色太快。

于 2012-07-29T01:03:26.650 回答