Frage

I want to remove or disable the buttons inside the main menu, that controls the child form (minimize, restore), of my application.

remove buttons at red retangle

The application should look like a "browser", where the MDI child forms must stay maximized all the time.

I alreday tried to disable they, by setting

BoderIcons := [biSystemMenu];

But I got this:

buttons

I alreday tried to disable the menu commands at the WM_INITMENU message, but without success:

procedure WMInitMenu(var Message: TWMInitMenu); message WM_INITMENU;

procedure TMyMDIChildForm.WMInitMenu(var Message: TWMInitMenu);
begin
  inherited;
  EnableMenuItem(Message.Menu, SC_MAXIMIZE, MF_BYCOMMAND or MF_GRAYED);
  EnableMenuItem(Message.Menu, SC_MINIMIZE, MF_BYCOMMAND or MF_GRAYED);
end;

I'm using:

  • Delphi 7.1 Enterprise
  • Windows 7 Pro x64
War es hilfreich?

Lösung 2

I solved by intercepting the WM_COMMAND at the MainForm as the follow code shows:

type
  TMDIMainForm = class(TForm)
  protected
    procedure WMCommand(var Message: TWMCommand); message WM_COMMAND;
  end;

implementation

procedure TMDIMainForm.WMCommand(var Message: TWMCommand);
begin
  case Message.ItemID of
    SC_CLOSE, SC_MINIMIZE, SC_RESTORE, SC_MAXIMIZE:
      begin
        Message.Result := 0;
        Exit;
      end;
  else
    inherited;
  end;
end;

At the child forms, I simple placed this:

procedure TMDIChild.OnCreate(Sender: TObject);
begin
  WindowState := wsMaximized;
end;

Now my MDI childs stays maximized and the user isn't able to restore or minimize than.

Andere Tipps

You're going to end up fighting just about everything that makes MDI what it is. Instead of using MDI, consider using frames. Design a TFrame descendant to represent one screen of your UI. You can put instances on a TPageControl to help organize them. (Set each page's TabVisible property to false if you want to provide your own method of navigating between screens.)

MDI is exactly a mechanism for having a from (child) floating inside another form (parent). Can't see the point having it permanently maximized.

If you whant is to separate code and have it in other unit you can use frame (that can be inserted in design time or in runtime) or forms (using something the following code)

procedure TParentForm.FormCreate(ASender: TObject);
begin
  FEmbeddedForm := TEmbeddedForm.Create(self);
  FEmbeddedForm.Parent := Panel1;
  FEmbeddedForm.Align := alClient;
  FEmbeddedForm.BorderStyle := bsNone;
  FEmbeddedForm.Visible := True;
end; 

Somehow the accepted answer does not work me. This works for me instead: MDIChildForm.BorderIcons := MDIChildForm.BorderIcons - [biSystemMenu];

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top