Reopening a minimized main window lazarus / 34-Windows ---------------------------------------------------------------------- RedGrittyBrick · 2013-07-09 14:16 I recently downloaded Lazarus (I used to use Delphi many years ago) and tried creating a simple program based on the "first project" tutorial. I eventually want this to periodically check email and provide a Windows 7 system-tray notification of unread messages. I added a TTrayIcon component from the "Additional" Tab and set it's onclick handler to execute a 'Form1.Visible=true;'.  The code does what I want so long as I don't minimise the Form1 window. The problem is that if I minimise the Form1 window, The app icon disappears from the task bar when I click my system-tray-icon and I am then unable to make the window reappear. Here's Unit1.pas (please scroll down to TForm1.TrayIcon1Click at bottom) Code: [Select]unit Unit1; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,   ExtCtrls; type   { TForm1 }   TForm1 = class(TForm)     Button1: TButton;     ExitButton: TButton;     TrayIcon1: TTrayIcon;     procedure Button1Click(Sender: TObject);     procedure ExitButtonClick(Sender: TObject);     procedure TrayIcon1Click(Sender: TObject);   private     { private declarations }   public     { public declarations }   end; var   Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject); begin   if Button1.tag = 0 then   begin     Button1.caption := 'Press again';     Button1.tag := 1;   end else   begin     Button1.caption := 'Press';     Button1.tag := 0;   end; end; procedure TForm1.ExitButtonClick(Sender: TObject); begin   Close; end; procedure TForm1.TrayIcon1Click(Sender: TObject); begin   if TrayIcon1.Tag = 0 then   begin     Form1.Visible:=false;     TrayIcon1.tag := 1   end else   begin     Form1.Visible:=true;     {Form1.Something_to_unMinimise?;}     TrayIcon1.tag := 0   end; end; end. How can I unminimize the Form1 window? ---------------------------------------------------------------------- taazz · 2013-07-09 14:55 1) Don't use the variable Form1 inside the instance of form1 use self or nothing at all 2) you need to restore the main window use the windowState property eg Code: [Select]  Self.Visible := True;   Self.WindowState := wsNormal;   BringToFront; I do not remember if all the above calls are required for example setting WindowState might bring it to front as well don't recall. ---------------------------------------------------------------------- User137 · 2013-07-10 12:23 I am using this code on 1 of my applications with tray, and it works well Code: [Select]procedure TfrmMain.TrayIcon1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin   if visible then begin     Hide;   end else begin     Show;   end; end;Only difference i see, is that i use MouseDown event. The project also has only 1 form possibly visible at the time. You can also try Application.Minimize and Application.Restore.