3

我有一个程序,它不会开始最小化,并在桌面上显示一个非常小的窗口。

图片:http: //i.imgur.com/j8xus.jpg

代码:

程序:

program Project4;

uses
  Forms,
  Unit4 in 'Unit4.pas' {Form4};

{$R *.res}

begin
  Application.Initialize;
  Application.MainFormOnTaskbar := false;
  Application.ShowMainForm:=false;
  Application.CreateForm(TForm4, Form4);
  Application.Run;
end.

单元:

unit Unit4;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, AppEvnts, ExtCtrls, Menus;

type
  TForm4 = class(TForm)
    TrayIcon1: TTrayIcon;
    ApplicationEvents1: TApplicationEvents;
    PopupMenu1: TPopupMenu;
    Exit1: TMenuItem;
    procedure TrayIcon1DblClick(Sender: TObject);
    procedure ApplicationEvents1Minimize(Sender: TObject);
    procedure ApplicationEvents1Restore(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure FormCreate(Sender: TObject);
    procedure Exit1Click(Sender: TObject);
  private
    { Private declarations }
    fCanClose: Boolean;
  public
    { Public declarations }
  end;

var
  Form4: TForm4;

implementation

{$R *.dfm}

procedure TForm4.ApplicationEvents1Minimize(Sender: TObject);
begin
  Hide();
  WindowState := wsMinimized;
end;

procedure TForm4.ApplicationEvents1Restore(Sender: TObject);
begin
  Show();
  WindowState := wsNormal;
  application.Bringtofront;
end;

procedure TForm4.Exit1Click(Sender: TObject);
begin
  fcanclose:=true;
  close;
end;

procedure TForm4.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  if not fCanClose then
    begin
      hide;
      windowstate:=wsminimized;
      CanClose:=false;
    end
      else
    CanCLose:=True;
end;

procedure TForm4.FormCreate(Sender: TObject);
begin
  fCanClose:=FALSE;
end;

procedure TForm4.TrayIcon1DblClick(Sender: TObject);
begin
  if (windowstate = wsminimized) then
    begin
      Show;
      windowstate := wsnormal;
      application.BringToFront;
    end
     else
    begin
      hide;
      windowstate:=wsminimized;
    end;
end;

end.
4

1 回答 1

5

我创建了您的项目并遇到了同样的问题,直到我将以下代码行更改为True

Application.MainFormOnTaskbar := True;

现在,该应用程序似乎可以正常工作,而无需在隐藏之前最小化到桌面的左下角。

于 2013-01-09T06:08:22.957 回答