Delphi应用程序窗体在启动时显示而不是隐藏

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.

请检查 Form4Visible 属性是否设置为 False - LaKraven
http://stackoverflow.com/questions/7071017/start-program-with-application-minimized - user496736
表单可见属性被设置为 false。 - Daniel
SilentD,我不知道那与我的问题有什么关系。 - Daniel
1个回答

5

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

Application.MainFormOnTaskbar := True;

现在这个应用似乎可以直接工作,而不需要将它最小化到桌面的左下角才能隐藏。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接