We help IT Professionals succeed at work.

Start application hidden

skynergy
skynergy asked
on
I am writing a tray icon application that needs to start with windows startup but be hidden when it starts. I'm using I param for starting up from the startup folder to start it hidden and none for starting it normal. I can't seem to get it to start hidden. Does anyone know how to do this?
Thanx in advance, Magnus.
Comment
Watch Question

Commented:
Just put the mainform.windowstate to wsMinimized.

If it's a tray application, that's how you enable the tray icon.

Alternatively, simply use self.hide in the mainform.

John.
in your project source, add the line

Application.ShowMainForm := False;

before you create your main form.
Yo Skynergy,

try this :

In the application source file (dpr) :

program Program1

uses
  Windows,
  Forms,
  Unit1 in 'Unit1.pas' {Form1},

{$R *.RES}

begin
  Application.Initialize;
  Application.ShowMainForm := False;
  Application.CreateForm(TForm1, Form1);
  ShowWindow(Application.Handle, SW_HIDE);
  Application.Run;
end.

In unit1 do this :

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm1 = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}


initialization
 ShowWindow(Application.Handle, SW_HIDE);

end.

Good luck
/PL

Author

Commented:
Thanx guys! Peter I didn't try yours because Colin's solution worked for my application. Why did you add the extra lines of code though?
Thanks for the points.

The only extra line of code that the others suggested was

ShowWindow(Application.Handle, SW_HIDE);


This is supposed to hide the application thread. By not showing the main form in the first place, meant it's never shown, so this line is wasted.

Colin Dawson.

Author

Commented: