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

Delphi to Web

Review Thinfinity VirtualUI
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 usually collapses to the taskbar and is replaced by a button there.

 

did the window hide away?

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.

You may want to continue reading: https://www.cybelesoft.com/blog/how-to-virtualize-applications/

Any questions about this post? Do minimized windows still cause trouble to you? Just leave a comment below or sends us an email at [email protected].

Comments (2)

Dear Arek, I had to translate your comment and I’m not sure if you could resolve the Delphi collapse to the taskbar issue.
Did this post work for you?
Otherwise, please send an email to [email protected] so we can help you.

A mam jeszcze jeden problem z programem. Nie moge go zwinac bezpośrednio do paska. Chodzi o to że jak go zwijam to ładuje mi się nad menu start a nie do paska. Wiecie moze co z tym zrobic ?
delphi zwijanie do paska zadań

Leave a comment

Privacy Preferences
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.