Link to home
Start Free TrialLog in
Avatar of skynergy
skynergy

asked on

Start application hidden

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.
Avatar of Jaymol
Jaymol

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.
ASKER CERTIFIED SOLUTION
Avatar of Colin_Dawson
Colin_Dawson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of skynergy

ASKER

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.