最小化子模态形式时最小化整个应用程序

问题描述 投票:4回答:2

在接近这个问题的另一个问题中,我得到的答案是将模态形式保留在mainform中的工作区内。我能做到这一点的方式(再次感谢David)正在捕捉WMSizing,WMMoving,WMGetMaxMinInfo以及我的porpuose WMShowwindow消息。我并不关闭消息处理,我认为这可能是我管理消息的方式,因为我没有得到我需要的结果。

我的应用程序中的所有表单都是模态的。但是你可以在同一个执行线程中打开很多东西。 (Mainform,form1,form2,form3 ... formN)。所有表格(1..N)都在我的主要形式的工作区内移动。最大化,恢复,调整大小,移动...在工作区域的限制之间。

但我无法管理如何最小化整个应用程序,然后单击活动模式窗体最小化按钮,然后单击任务栏按钮。该应用程序将用于XP和W7 ...我正在DelphiXE中开发。

该项目可以从这里下载(Project files - Mainform,面板,按钮,SecondaryForm,单位,仅此而已),只是为了看到我尝试所有的建议,我在问这里之前。

这是原始单元的源代码,它将模态形式保留在工作区内。

unit uFormularios;

interface

uses Classes, SysUtils, Windows, Messages, Forms, DBGrids, StdCtrls, Menus, Graphics, ComCtrls, Math;

type
  TForm_en_ventana = class(TForm)
  private
    inicializada: boolean;
    bCentrada     : boolean;
    bMaximizada   : boolean;
    ancho_original: integer;
    alto_original : integer;
    procedure WMShowWindow(var Message: TWMShowWindow); message WM_SHOWWINDOW;
    procedure WMSizing(var msg: TMessage); message WM_SIZING;
    procedure WMMoving(Var msg: TMessage); message WM_MOVING;
    procedure WMGetMinMaxInfo(Var msg: TWMGetMinMaxInfo); message WM_GETMINMAXINFO;
  public
    constructor Create(AOwner: TComponent); override;
    property centrada: boolean read bCentrada write bCentrada;
    property maximizada: boolean read bMaximizada write bMaximizada;
  end;

procedure MaximizarFormulario(var F; MaximaAltura: integer = 0; MaximoAncho: integer = 0; Centrado: boolean = TRUE);
procedure InicializarVentanaTrabajo(const izq, der, arr, aba: integer);

var
  ESPACIO_DE_TRABAJO, VENTANA_DE_TRABAJO: TRect;

implementation

constructor TForm_en_ventana.Create(AOwner: TComponent);
begin
  inherited;
  centrada     := TRUE;
  maximizada   := false;
  inicializada := false;
end;

Procedure TForm_en_ventana.WMGetMinMaxInfo(Var msg: TWMGetMinMaxInfo);
begin
  inherited;
  with msg.MinMaxInfo^.ptMaxPosition do
    begin
      x := VENTANA_DE_TRABAJO.Left;
      y := VENTANA_DE_TRABAJO.Top;
    end;
  with msg.MinMaxInfo^.ptMaxSize do
    begin
      x := VENTANA_DE_TRABAJO.Right - VENTANA_DE_TRABAJO.Left;
      y := VENTANA_DE_TRABAJO.Bottom - VENTANA_DE_TRABAJO.Top;
    end;
  with msg.MinMaxInfo^.ptMaxTrackSize do
    begin
      x := VENTANA_DE_TRABAJO.Right - VENTANA_DE_TRABAJO.Left;
      y := VENTANA_DE_TRABAJO.Bottom - VENTANA_DE_TRABAJO.Top;
    end;
  with msg.MinMaxInfo^.ptMinTrackSize do
    begin
      x := ancho_original;
      y := alto_original;
    end;
end;

procedure TForm_en_ventana.WMSizing(var msg: TMessage);
var
  R: PRect;
begin
  R        := PRect(msg.LParam);
  R.Left   := Max(R.Left, VENTANA_DE_TRABAJO.Left);
  R.Right  := Min(R.Right, VENTANA_DE_TRABAJO.Right);
  R.Top    := Max(R.Top, VENTANA_DE_TRABAJO.Top);
  R.Bottom := Min(R.Bottom, VENTANA_DE_TRABAJO.Bottom);
  Caption  := 'Ancho: ' + inttostr(ancho_original) + ' - Alto: ' + inttostr(alto_original);
end;

procedure TForm_en_ventana.WMMoving(var msg: TMessage);
var
  R     : PRect;
  dx, dy: integer;
begin
  R  := PRect(msg.LParam);
  dx := 0;
  dy := 0;
  if R.Left < VENTANA_DE_TRABAJO.Left then
    dx := VENTANA_DE_TRABAJO.Left - R.Left;
  if R.Right > VENTANA_DE_TRABAJO.Right then
    dx := VENTANA_DE_TRABAJO.Right - R.Right;
  if R.Top < VENTANA_DE_TRABAJO.Top then
    dy := VENTANA_DE_TRABAJO.Top - R.Top;
  if R.Bottom > VENTANA_DE_TRABAJO.Bottom then
    dy := VENTANA_DE_TRABAJO.Bottom - R.Bottom;
  OffsetRect(R^, dx, dy);
end;

procedure TForm_en_ventana.WMShowWindow(var Message: TWMShowWindow);
begin
  if inicializada then
    Exit;
  inicializada          := TRUE;
  ancho_original        := Width;
  alto_original         := Height;
  Constraints.MinHeight := Height;
  Constraints.MinWidth  := Width;
  if centrada then
    begin
      Left := (((VENTANA_DE_TRABAJO.Right - VENTANA_DE_TRABAJO.Left) - Width) div 2) + VENTANA_DE_TRABAJO.Left;
      Top  := (((VENTANA_DE_TRABAJO.Bottom - VENTANA_DE_TRABAJO.Top) - Height) div 2) + VENTANA_DE_TRABAJO.Top;
    end;
  if maximizada then
    SendMessage(Handle, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
end;

procedure InicializarVentanaTrabajo(const izq, der, arr, aba: integer);
begin
  VENTANA_DE_TRABAJO.Left   := izq;
  VENTANA_DE_TRABAJO.Right  := der;
  VENTANA_DE_TRABAJO.Top    := arr;
  VENTANA_DE_TRABAJO.Bottom := aba;
end;

procedure MaximizarFormulario(var F; MaximaAltura: integer = 0; MaximoAncho: integer = 0; Centrado: boolean = TRUE);
begin
  LockWindowUpdate(TForm(F).Handle);
  TForm(F).Left := ESPACIO_DE_TRABAJO.Left;
  if MaximoAncho = 0 then
    TForm(F).Width := ESPACIO_DE_TRABAJO.Right
  else
    begin
      if ESPACIO_DE_TRABAJO.Right < MaximoAncho then
        TForm(F).Width := ESPACIO_DE_TRABAJO.Right
      else
        TForm(F).Width := MaximoAncho;
    end;
  TForm(F).Top := ESPACIO_DE_TRABAJO.Top;
  if MaximaAltura = 0 then
    TForm(F).Height := ESPACIO_DE_TRABAJO.Bottom
  else
    begin
      if ESPACIO_DE_TRABAJO.Bottom < MaximaAltura then
        TForm(F).Height := ESPACIO_DE_TRABAJO.Bottom
      else
        TForm(F).Height := MaximaAltura;
    end;
  if ((MaximoAncho <> 0) or (MaximaAltura <> 0)) and (Centrado) then
    begin
      TForm(F).Left := (ESPACIO_DE_TRABAJO.Right - TForm(F).Width) div 2;
      TForm(F).Top  := (ESPACIO_DE_TRABAJO.Bottom - TForm(F).Height) div 2;
    end;
  LockWindowUpdate(0);
end;

initialization

SystemParametersInfo(SPI_GETWORKAREA, 0, @ESPACIO_DE_TRABAJO, 0);
VENTANA_DE_TRABAJO := ESPACIO_DE_TRABAJO;

end.

感谢任何可以帮助我的人!

forms delphi delphi-xe minimize
2个回答
1
投票

只需捕获模态表单中的最小化和还原消息,然后执行此操作...

procedure TTheModalForm.WMSysCommand(var Msg: TWMSysCommand);
begin
  if (fsModal in FormState) or not Application.MainForm.Visible then
  begin
    case Msg.CmdType of
      SC_MINIMIZE:
      begin
        ShowWindow(Application.Handle, SW_SHOWMINNOACTIVE);
      end;

      SC_RESTORE:
      begin
        ShowWindow(Application.Handle, SW_SHOWNORMAL);
        inherited;
      end;

    else
      inherited;
    end;
  end
  else
    inherited;
end;

0
投票

我也需要这个,我尝试了另一个答案,但它没有用。幸运的是我设法让它工作,像这样:

procedure TFoodsForm.WMSysCommand(var Msg: TWMSysCommand);
begin
 if (fsModal in FormState) and (Msg.CmdType and $FFF0 = SC_MINIMIZE)
  then Application.MainForm.WindowState:= wsMinimized
  else inherited;
end;
© www.soinside.com 2019 - 2024. All rights reserved.