2

When I create a new VCL application in Delphi 2006 and run it (without adding any of my own code or refernce any of my own units), the application won't have all of menu items one would expect in the context menu of it's taskbar button. The application's system menu (the menu you get when left-clicking the form's icon), however, has all the regular menu items. As you can see in the following screenshots, Move (Verschieben), Size(Größe ändern) and Maximize(Maximieren) are missing from the former

enter image description here enter image description here

I could not reproduce this in Delphi XE (the only other vesion of Delphi I have access to) and I haven't found anybody else reporting this behavior, either.

I have also looked through the properties of TForm and TApplication whether there was one to control these menus, but haven't found one.

All applications I know of have the same set of menu items in those two menus and I would like my application to do, too. How do I get these two menus to show the same set of items?

PersonalNexus
  • 1,292
  • 1
  • 9
  • 25
  • I would expect to see the smaller menu if the application was maximized. Is this the case? – Keith Miller Apr 14 '12 at 07:09
  • 1
    This is what [Application.MainFormOnTaskBar](http://docwiki.embarcadero.com/VCL/en/Forms.TApplication.MainFormOnTaskBar) does. – NGLN Apr 14 '12 at 07:16
  • @KeithMiller No, it's not maximized. – PersonalNexus Apr 14 '12 at 07:29
  • Back in the day, this used to be the standard "first way to check if your application was written in delphi". Since the window that you see on the taskbar is a special window that was used by Delphi only for the taskbar window. – Warren P Apr 14 '12 at 12:46

2 Answers2

6

The difference lies in Application.MainFormOnTaskBar, a property introduced in D2007 which is set automatically True.

To acquire the same effect in earlier versions, I always use the following approach:

Project.dpr:

uses
  Windows,
  ...

  Application.CreateForm(TMainForm, MainForm);
  ShowWindow(Application.Handle, SW_HIDE);
  Application.Run;

FMain.pas:

  TMainForm = class(TForm)
  private
    procedure WMSysCommand(var Message: TWMSysCommand);
      message WM_SYSCOMMAND;
  protected
    procedure CreateParams(var Params: TCreateParams); override;
  ...

procedure TMainForm.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  with Params do
  begin
    ExStyle := ExStyle or WS_EX_APPWINDOW;
    WndParent := GetDesktopWindow;
  end;
end;

procedure TMainForm.WMSysCommand(var Message: TWMSysCommand);
begin
  if Message.CmdType = SC_MINIMIZE then
    ShowWindow(Handle, SW_MINIMIZE)
  else
    inherited;
end;

This works only when MainForm.Visible is set True design time.

NGLN
  • 43,011
  • 8
  • 105
  • 200
1

In D2006, the taskbar button is owned by the TApplication window. Clicking on the Taskbar button displays the TApplication system menu, which is altered by the VCL to always remove the Maximize, Size, and Move menu items. When clicking on a TForm, on the other hand, the Form's system menu is displayed instead, which is altered by the VCL according to the Form's BorderStyle and BorderIcon properties. So you are really dealing with two separate menus for two separate windows.

In modern Delphi versions, with the new TApplication.ShowMainFormOnTaskbar property set to true, the taskbar is owned by TForm instead of TApplication, so clicking on the Taskbar button will display the Form's system menu instead of the the TApplication system menu. So in this case, you are really dealing with a single menu for a single window.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770