devxlogo

Don’t Show Form at Startup of System Tray App

Don’t Show Form at Startup of System Tray App

Question:
I tried your procedure for placing my application on the system tray and it works fine. My problem is that it opens the form1 when the application is executed, but I do not want to open it until the user clicks on the menu item on the right-click menu of the system tray icon.

Any help will be greatly welcome.

Answer:
The easiest way to have the form not show up is to do the following:

1) Define a Boolean variable in the private section of your form’s type declaration ?let’s call it FrmCreate.

2) In the Form’s OnCreate, set FrmCreate to True.

3) Next, drop a TTimer on the form and in its OnTimer event, write the following:

procedure TMainForm.Timer1Timer(Sender: TObject);begin  if FrmCreate then begin    ShowWindow(MainForm.Handle, SW_HIDE);    Timer1.Enabled := False;  end;end;

The timer is only active at create time so you can just hide the window as soon as it pops up. This will probably cause a bit of a flash, but that’s usually not a big deal.

See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist