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

Cookie Preferences
Privacy and Cookie Policies
Cybele Software implements specific policies to enhance your browsing experience while respecting your privacy. When you visit Cybele Software's website, the site uses cookies to personalize your experience. These small files remember your preferences and the details of your repeated visits, aligning closely with Cybele's Privacy Policy.

You have complete control over the cookies used during your visit:
- Accepting All Cookies: You can agree to the use of all cookies by clicking “Accept All.” This provides a smoother, more integrated experience.
- Customizing Cookie Settings: If you prefer to manage your preferences, you can click on "Cookie Settings." This allows you to give controlled consent by selecting which types of cookies you agree to activate.
- Opting Out: You also have the option to opt-out entirely from non-essential cookies. It's important to note that choosing this option might impact your experience on the website, potentially limiting certain functionalities and features.
These features ensure that you can tailor your browsing according to your personal preferences and privacy concerns.