3422 Old Capitol Trail – Suite 1125, Wilmington – DE 19808, United States

Why is it that in certain Delphi applications, minimized windows get lost?

    New here? Read more about why software developers are adopting Thinfinity VirtualUI
    to increase the value of their Windows applications.

 
Thinfinity VirtualUI: Minimized windows get lost when working with Delphi appsWhen the main window is minimized in a Windows application, it is usually replaced by a button on the taskbar.

Minimization in Thinfinity VirtualUI works in a similar fashion, replacing the application window with an icon in the lower left corner of the page. But a problem is found in certain Delphi applications: when minimized, the window is hidden away and the taskbar shows no such icon.

While VirtualUI behaves correctly in this regard, applications developed in this language present the following problem: when the Application.MainFormOnTaskBar property is set to False and an application main window is minimized, this window is in fact hidden but it is not done the proper way.

This is the TApplication.Minimize code:

procedure TApplication.Minimize;
begin
  if not IsIconic(Handle) then
  begin
    NormalizeTopMosts;
    if not MainFormOnTaskBar then
      SetActiveWindow(Handle); // WM_ACTIVATEAPP can set AppIconic to False
      FAppIconic := True;      // Set AppIconic here just to be safe
      DoShowOwnedPopups(False);
      if FMainFormOnTaskBar then
      begin
        if FMainForm <> nil then
          FMainForm.WindowState := wsMinimized
        else
          FInitialMainFormState := wsMinimized;
      end
    else
    begin
      if (FMainForm <> nil) and (ShowMainForm or FMainForm.Visible)
      and IsWindowEnabled(FMainForm.Handle) then
      begin
        SetWindowPos(Handle, FMainForm.Handle, FMainForm.Left, FMainForm.Top,
          FMainForm.Width, 0, SWP_SHOWWINDOW);
        DefWindowProc(Handle, WM_SYSCOMMAND, SC_MINIMIZE, 0);
      end
      else
        ShowWinNoAnimate(Handle, SW_MINIMIZE);
    end;
    if Assigned(FOnMinimize) then FOnMinimize(Self);
  end;
end;

To fix this problem, the value of this property must be set to True.

program MinimExample;
uses
  Forms,
  VirtualUI_AutoRun,
  MainForm in 'MainForm.pas' {FormMain};

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TFormMain, FormMain);
  Application.MainFormOnTaskbar := True;
  Application.Run;
end.

 

With this correction in place, Delphi properly minimizes the application window and the icon is shown on the taskbar as expected.

 

Related Posts

Leave a comment