Recent

Author Topic: Problems in a small program with a tray icon.  (Read 5430 times)

idealis

  • New Member
  • *
  • Posts: 34
Problems in a small program with a tray icon.
« on: April 07, 2011, 06:44:52 pm »
Hi friends! I am working on a small program that should display an icon in the Windows system tray, without opening a "main window" on start. I do need, however, some windows (for the settings, mostly). What I did was:
1) Trying to set Visible to "False" (it was done already),
2) Setting WindowState to "Minimized",
3) Setting ShowInTaskBar is set to "stNever".
However, it doesn't seem to work. Is this due to some bug that I didn't read about? Or am I just doing things the wrong way?

Cheers! :)

DirkS

  • Sr. Member
  • ****
  • Posts: 251
Re: Problems in a small program with a tray icon.
« Reply #1 on: April 07, 2011, 07:00:35 pm »
Not a lot of information...

First of all you're not saying *what* is actually not working? Don't you see the icon in the system tray or does the program still show in the taskbar?

Gr.
Dirk.

garlar27

  • Hero Member
  • *****
  • Posts: 652
Re: Problems in a small program with a tray icon.
« Reply #2 on: April 07, 2011, 07:05:34 pm »
Try setting:
Code: Pascal  [Select][+][-]
  1. Form1.Visible := False;

idealis

  • New Member
  • *
  • Posts: 34
Re: Problems in a small program with a tray icon.
« Reply #3 on: April 07, 2011, 07:34:32 pm »
Sorry DirkS, I wrote the post twice, but forgot the explanation the second time :-[.

What happens is that the main form is still displayed, and the button in the taskbar appears as well.
Also, garlar27, I already had tried setting Visible to "False" manually, but it refuses to work...  :(


EDIT: setting Visible to "false" worked when I wrote this on the Activate event. When the program starts, the main window "flashes", then the only thing that remains is the tray icon. Is this the best solution?
« Last Edit: April 07, 2011, 08:31:05 pm by idealis »

garlar27

  • Hero Member
  • *****
  • Posts: 652
Re: Problems in a small program with a tray icon.
« Reply #4 on: April 07, 2011, 08:29:04 pm »
Well, I had to go back and look at what I did and it was like this:

Code: Pascal  [Select][+][-]
  1. {____________________________________________________________________ FormShow }
  2. procedure TForm1.FormShow(Sender: TObject);
  3. begin
  4.    // it didn't worked
  5.    //if fsFirstShow in FormState then begin
  6.    if IsFirstTime then begin
  7.       IsFirstTime := FALSE;
  8.       //Visible := False;
  9.       WindowState := wsMinimized;
  10.       Hide;
  11.    end;
  12. end; {<--- FormShow }
  13.  
  14.  
  15. {______________________________________________________________________________ FormWindowStateChange }
  16. procedure TForm1.FormWindowStateChange(Sender: TObject);
  17. begin
  18.    if WindowState = wsMinimized then begin
  19.       Hide;
  20.       Application.ShowMainForm := False;
  21.    end;
  22. end; {<--- FormWindowStateChange }
  23.  

that is how it worked for me.

garlar27

  • Hero Member
  • *****
  • Posts: 652
Re: Problems in a small program with a tray icon.
« Reply #5 on: April 07, 2011, 08:34:39 pm »
The key is the method "Hide".

The example I posted Hides the main form at startup, so there is no visible form when launching the app.

tested on windows XP and linux.-

 

TinyPortal © 2005-2018