2

I am a delphi learner. I am having one Delphi Progect with "MainForm", "MinimizeTimer" and "RestoreTimer". I have defined the following codes.

Minimize Timer :

  if MainForm.AlphaBlendValue >= 225 then
  begin
    MinimizeTimer.Enabled := true;
    MainForm.AlphaBlendValue := MainForm.AlphaBlendValue - 5;
  end;

Restore Timer :

  if MainForm.AlphaBlendValue >= 0 then
  begin
    RestoreTimer.Enabled := true;
    MainForm.AlphaBlendValue := MainForm.AlphaBlendValue + 5;
  end;

My requirement is that the MainForm will be first fadeout using "MinimizeTimer" and then will be minimized when "_" Button on Caption Bar is pressed. And also be fadein using "RestoreTimer" and then will be restored after clicking on taskbar. So I defined again the following codes:

  private
    { Private declarations }
    procedure WMSysCommand(var Msg: TWMSysCommand) ; message WM_SYSCOMMAND;
..
..
..
..
..
procedure TMainForm.WMSysCommand(var Msg: TWMSysCommand) ;
begin
  if Msg.CmdType = SC_MINIMIZE then MinimizeTimer.Enabled := true;
  DefaultHandler(Msg);
  if Msg.CmdType = SC_RESTORE then RestoreTimer.Enabled := true;
  DefaultHandler(Msg);
end;

But I am not getting the expected result. The MainForm is Minimized and Restored as in regular way. Please remember in my project I have one "FormCloseQuery" event also.

Please help me.

4

1 回答 1

4

您对您的要求使用了错误的逻辑。试试这个:

procedure TMainForm.MinimizeTimerTimer(Sender: TObject);
begin
  if AlphaBlendValue > 0 then
  begin
    AlphaBlendValue := AlphaBlendValue - 5;
  end
  else
  begin
    MinimizeTimer.Enabled := False;
    Perform(WM_SYSCOMMAND, SC_MINIMIZE, 0);
  end;
end;

procedure TMainForm.RestoreTimerTimer(Sender: TObject);
begin
  if AlphaBlendValue < 255 then
  begin
    AlphaBlendValue := AlphaBlendValue + 5;
  end else begin
    RestoreTimer.Enabled := False;
  end;
end;

procedure TMainForm.WMSysCommand(var Msg: TWMSysCommand);
begin
  case Msg.CmdType of
    SC_MINIMIZE: begin
      if AlphaBlendValue > 0 then
      begin
        MinimizeTimer.Enabled := True;
        Exit;
      end;
    end;
    SC_RESTORE: begin
      if AlphaBlendValue < 255 then begin
        RestoreTimer.Enabled := True;
      end;
    end;
  end;
  inherited;
end;
于 2012-07-26T20:49:55.167 回答