2004. november 17., szerda

Move a menu bar outside the visible screen


Problem/Question/Abstract:

Is there a way of hiding a TMainMenu?

Answer:

Yes, do not hide it. What you do is leave it visible (as well as caption bar and border) and then just size the whole window so that only the client area is visible, all the nonclient area, including the menu bar, simply lies outside the visible screen. The alternative is to use a toolbar menu instead of a standard menu bar.

{ ... }
private {in form declaration}

procedure WMGetMinMaxInfo(var msg: TWMGetMinMaxInfo); message WM_GETMINMAXINFO;
{ ... }

procedure TForm1.WMGetMinMaxInfo(var msg: TWMGetMinMaxInfo);
begin
  inherited;
  with msg.MinMaxInfo^.ptMaxTrackSize do
  begin
    X := GetDeviceCaps(Canvas.handle, HORZRES) + (Width - ClientWidth);
    Y := GetDeviceCaps(Canvas.handle, VERTRES) + (Height - ClientHeight);
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
const
  Rect: TRect = (Left: 0; Top: 0; Right: 0; Bottom: 0);
  FullScreen: Boolean = False;
begin
  FullScreen := not FullScreen;
  if FullScreen then
  begin
    Rect := BoundsRect;
    SetBounds(Left - ClientOrigin.X, Top - ClientOrigin.Y,
      GetDeviceCaps(Canvas.handle, HORZRES) + (Width - ClientWidth),
      GetDeviceCaps(Canvas.handle, VERTRES) + (Height - ClientHeight));
    { Label2.caption := IntToStr(GetDeviceCaps(Canvas.handle, VERTRES)); }
  end
  else
    BoundsRect := Rect;
end;

Nincsenek megjegyzések:

Megjegyzés küldése