procedure TWinControl.WMSysCommand(
var Message: TWMSysCommand);
var
Form: TCustomForm;
function TraverseControls(Container: TWinControl): Boolean;
var
I: Integer;
Control: TControl;
begin
{3} Result := False;
if Container.Showing
then
for I := 0
to Container.ControlCount - 1
do
begin
Control := Container.Controls[I];
if Control.Visible
and Control.Enabled
then
begin
if (csMenuEvents
in Control.ControlStyle)
and
{4} (Control.Perform(WM_SYSCOMMAND, TMessage(
Message).WParam,
TMessage(
Message).LParam) <> 0)
or (Control
is TWinControl)
and
TraverseControls(TWinControl(Control))
then
begin
Result := True;
Exit;
end;
end;
end;
end;
begin
with Message do
begin
{1}{5}if (CmdType
and $FFF0 = SC_KEYMENU)
and (Key <> VK_SPACE)
and
(Key <> Word('
-'))
and not IsIconic(FHandle)
and (GetCapture = 0)
and
(Application.MainForm <> Self)
then
begin
Form := GetParentForm(Self);
if (Form <>
nil)
and
{6} (Form.Perform(CM_APPSYSCOMMAND, 0, Longint(@
Message)) <> 0)
then
Exit;
end;
{ Broadcast WMSysCommand to all controls which have a csMenuEvents style. }
{2} if (CmdType
and $FFF0 = SC_KEYMENU)
and TraverseControls(Self)
then
Exit;
end;
inherited;
end;
procedure TCustomForm.CMAppSysCommand(
var Message: TMessage);
type
PWMSysCommand = ^TWMSysCommand;
begin
Message.Result := 0;
if (csDesigning
in ComponentState)
or (FormStyle = fsMDIChild)
or
(Menu =
nil)
or Menu.AutoMerge
then
with PWMSysCommand(
Message.lParam)^
do
begin
SendCancelMode(
nil);
{7} if SendAppMessage(CM_APPSYSCOMMAND, CmdType, Key) <> 0
then
Message.Result := 1;;
end;
end;
procedure TApplication.WndProc(
var Message: TMessage);
...
begin
...
with Message do
case Msg
of
...
CM_APPSYSCOMMAND:
if MainForm <>
nil then
with MainForm
do
if (
Handle <> 0)
and IsWindowEnabled(
Handle)
and
IsWindowVisible(
Handle)
then
begin
FocusMessages := False;
SaveFocus := GetFocus;
Windows.SetFocus(
Handle);
{8} Perform(WM_SYSCOMMAND, WParam, LParam);
Windows.SetFocus(SaveFocus);
FocusMessages := True;
Result := 1;
end;
...
end;