[resolved]program created to start minimized fails to show up on taskbar lazarus / 31-LCL ---------------------------------------------------------------------- jw · 2015-08-27 23:53 I don't know if this is some sort of bug, or if there's just a check box somewhere I simply need to click My program is supposed to execute minimized and show up on the start bar.  However, when I attempt to do this my program never appears anywhere, yet taskmanager says that it's running.  I then tried both a windows xp and vista dev machine and even multiple versions of freepascal starting with the most recent laz 1.4.2 fpc 2.6.4 clear back to laz 1.0.2. They all produced the same results.  I figured I'd bypass the laz editor and put the form1.windowstate:=wsMinimized; command in the code directly.  Putting the form1.windowstate:=wsMinimized; command in the form.create procedure produced the same results as setting it in the editor. putting the form1.windowstate:=wsMinimized; command in the form.show procedure also produced the same results. Thus.... I wrote a timer designed to execute after one second and put the form1.windowstate:=wsMinimized; command in there.  The form then executed and minimized incorrectly.  The program did at least show up on the taskbar, like it should.  However the minimized form itself didn't hide behind the start bar, but instead became a little bar just above the start bar with restore, minimize, and close buttons. ---------------------------------------------------------------------- Trenatos · 2015-08-28 01:13 Tray icon? http://forum.lazarus.freepascal.org/index.php?topic=2194.0 ---------------------------------------------------------------------- ChrisF · 2015-08-28 02:00 For the last part (i.e. using a timer), you should use instead: Code: [Select]  Application.Minimize; Concerning your main question, apparently if the main form is minimized when starting, application interprets it as it should be hidden. You can also minimize the Application before running it (in the .lpr file), but when it's run this doesn't apply any more. There might a simple solution that I don't know, but in the worst case, you can still minimize it after it has started: but in this case the mainform is shown first and then minimized (the minimize animation is visible). Use Application.minimize (but not in the main form create event), or you can even use a Windows API call (not recommended, and not working if Application.MainFormOnTaskBar:=True): Code: [Select]uses ..., Windows, Interfacebase; procedure TForm1.FormCreate(Sender: TObject); begin   ...   PostMessage(WidgetSet.AppHandle, WM_SYSCOMMAND, SC_MINIMIZE, 0); end; ---------------------------------------------------------------------- derek.john.evans · 2015-08-28 02:57 Here is some code which reduces the minimize window flash using ideas from above: 1) Iconify the window using Application.Minimize in OnShow. 2) Minimize to the toolbar in OnPaint. (A timer would also work) 3) Detect when app is restored via Application.OnRestore 4) On first restore, maximize the window, then center window to screen. There must be a better way, but I cant find it. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1;{$mode objfpc}{$H+}interfaceuses Forms; type   TFormMain = class(TForm)    procedure FormPaint(Sender: TObject);    procedure FormShow(Sender: TObject);    procedure DoOnRestore(ASender: TObject);  end; var FormMain: TFormMain; implementation {$R *.lfm} procedure TFormMain.FormShow(Sender: TObject);begin  Application.Minimize;end; procedure TFormMain.DoOnRestore(ASender: TObject);begin  Application.OnRestore := nil;  WindowState := wsMaximized;  SetBounds((Screen.Width - 800) div 2, (Screen.Height - 600) div 2, 800, 600);end; procedure TFormMain.FormPaint(Sender: TObject);begin  OnPaint := nil;  Application.Minimize;  Application.OnRestore := @DoOnRestore;end; end. ---------------------------------------------------------------------- engkin · 2015-08-28 05:13 I would suggest that you don't show the main form: Code: [Select]  Application.ShowMainForm:=False; and that you minimize the application after creating the form: Code: [Select]  Application.CreateForm(TForm1, Form1);   Application.Minimize; and to add a handler to show the form when the app is restored: Code: [Select]  Application.AddOnRestoreHandler(@Form1.RestoreIt); The handler RestoreIt is something like: Code: [Select]procedure TForm1.RestoreIt(Sender: TObject); begin   Application.ShowMainForm:=True;   Show; end; The first three lines are in the project source file: Code: [Select]...   Application.Initialize;   Application.ShowMainForm:=False;  //<--- 1   Application.CreateForm(TForm1, Form1);   Application.Minimize;  //<--- 2   Application.AddOnRestoreHandler(@Form1.RestoreIt);  //<--- 3   Application.Run; ... This way the application will *not* have the focus momentarily, at least on my system. ---------------------------------------------------------------------- jw · 2015-09-03 19:27 Trenatos:  A tray icon certainly would have worked thank you. ChrisF, derek.john.evans, and engkin:  After evaluating all of your brilliant coding efforts I realized that, in my case, all I needed was the application.minimize command, coded in the right place, in combination with the odd behavior exhibited by the form.minimized command,coded in the right place, to produce a flicker free minimized program. Thus... Code: [Select]procedure TForm1.FormCreate(Sender: TObject); begin   form1.windowstate:=wsMinimized; end; procedure TForm1.FormActivate(Sender: TObject); begin   Application.Minimize; end;   To any who may be watching, my kludge will not work for applications with multiple forms because form.activate is called the first time an application receives focus and each time focus is changed from another window of the same application.  So, in order to avoid minimizing window calamity involving applications with multiple forms I suggest a global Boolean flag. Code: [Select]//At the var way up at the very beginning of the code var startflag : boolean; procedure TForm1.FormActivate(Sender: TObject); begin    if startflag = true then      begin        Application.Minimize;        startflag:=false;     end; end; procedure TForm1.FormCreate(Sender: TObject); begin   startflag:=true;   form1.windowstate:=wsMinimized; end;