在做了一些进一步的挖掘之后,我遇到了这个问题。@Remy 请参见下文。
我正在使用 TActionMainMenuBar 代替父 MDI 表单上的 TMainMenu。TActionMainMenuBar 处理最小化/恢复/最大化按钮点击的方式与 TMainMenu 不同。下面的代码来自 Vcl.ActnMenus 文件:
type
TInternalMDIAction = class(TWindowAction)
private
{ Private declarations }
public
{ Public declarations }
procedure ExecuteTarget(Target: TObject); override;
end;
procedure TInternalMDIAction.ExecuteTarget(Target: TObject);
begin
case MDIAction of
maActivate: SendMessage(GetParent(Form.Handle), WM_MDIACTIVATE, Form.Handle, 0);
maClose: Form.Close;
maRestore: SendMessage(GetParent(Form.Handle), WM_MDIRESTORE, Form.Handle, 0);
maMinimize: ShowWindow(Form.Handle, SW_MINIMIZE);
end;
end;
我无法捕捉到最小化事件,因为 ShowWindow 从不调用 WMSysCommand。我在下面包含了我的修复:
type
TInternalMDIAction = class(TWindowAction)
private
{ Private declarations }
public
{ Public declarations }
procedure ExecuteTarget(Target: TObject); override;
end;
procedure TInternalMDIAction.ExecuteTarget(Target: TObject);
begin
case MDIAction of
maActivate: SendMessage(GetParent(Form.Handle), WM_MDIACTIVATE, Form.Handle, 0);
maClose: Form.Close;
//maRestore: SendMessage(GetParent(Form.Handle), WM_MDIRESTORE, Form.Handle, 0);
//maMinimize: ShowWindow(Form.Handle, SW_MINIMIZE);
maRestore: SendMessage(Form.Handle, WM_SYSCOMMAND, SC_RESTORE, 0);
maMinimize: SendMessage(Form.Handle, WM_SYSCOMMAND, SC_MINIMIZE, 0);
end;
end;
它现在的表现正如我所期望的那样。如果有人看到我可能遗漏的东西或解决由 VCL TActionMainMenuBar 引起的问题的更好方法,请告诉我。谢谢。