Вопрос

I have a program where it will not start minimized and shows a very small window on the dekstop.

Image: http://i.imgur.com/j8xus.jpg

Code:

program:

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:

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.
Это было полезно?

Решение

I created your project and had the same problems until I changed the following line of code to True:

Application.MainFormOnTaskbar := True;

Now the app seems to work just fine without an minimizing to the bottom left corner of the desktop before it is hidden.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top