Recent

Author Topic: Start App With Hidden Main Form  (Read 15236 times)

Marion

  • Full Member
  • ***
  • Posts: 125
Start App With Hidden Main Form
« on: March 19, 2012, 08:32:08 pm »
I need to have my app start with the main form hidden until the user double clicks on the sys tray icon. How do I do that?
Thank you,
Marion
(A recovering Windows programmer.)

tomek

  • Jr. Member
  • **
  • Posts: 85

Marion

  • Full Member
  • ***
  • Posts: 125
Re: Start App With Hidden Main Form
« Reply #2 on: March 19, 2012, 10:03:54 pm »
http://lazarus.freepascal.org/index.php/topic,12870.msg66721.html

Thank you for the link. Unfortunately, this doesn't work.

1. I already have Form.Visible := False;
2. Adding the Form.Hide in the OnShow event makes it impossible for the user to display the form when they double click the sys tray icon.

Is there anything else?
Thank you,
Marion
(A recovering Windows programmer.)

tomek

  • Jr. Member
  • **
  • Posts: 85
Re: Start App With Hidden Main Form
« Reply #3 on: March 19, 2012, 10:38:34 pm »
Thank you for the link. Unfortunately, this doesn't work.

1. I already have Form.Visible := False;
2. Adding the Form.Hide in the OnShow event makes it impossible for the user to display the form when they double click the sys tray icon.

Is there anything else?

I don't know how should behave OnShow, maybe it's a bug.
On Windows you can try this:
Code: [Select]
procedure TForm1.TrayIcon1Click(Sender: TObject);
begin
  ShowWindow(Application.MainFormHandle,SW_SHOW);
end;
and add windows to uses section in that case.
If you have more forms then replace MainFormHandle with handle to your form.

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Start App With Hidden Main Form
« Reply #4 on: March 19, 2012, 11:13:41 pm »
Open project source, and add line:

Code: [Select]
  Application.Initialize;
  Application.ShowMainForm := False; // Add this line, so mainform will not show at startup
  Application.CreateForm(TfrmMain, frmMain);

tomek

  • Jr. Member
  • **
  • Posts: 85
Re: Start App With Hidden Main Form
« Reply #5 on: March 19, 2012, 11:29:34 pm »
Yep, adding the Form.Hide in the OnShow event causes the problems, as the User137 writes use Application.ShowMainForm or Hide form when it's already visible.

Marion

  • Full Member
  • ***
  • Posts: 125
Re: Start App With Hidden Main Form
« Reply #6 on: March 19, 2012, 11:40:34 pm »
Thank you that got it!

Much appreciated.
Thank you,
Marion
(A recovering Windows programmer.)

 

TinyPortal © 2005-2018