我有一个VCL表单,设置为bsDialog
且启用了biHelp
("?"应用栏中的图标)。该应用程序还使用自定义VCL样式(Aqua Light Slate)。
但是当我点击"?"时,我无法显示WMNCLBUTTONDOWN
Windows消息。按钮。仅当应用程序的VCL样式更改回Windows(默认)时,它才有效。
procedure TMainFrm.WMNCLButtonDown(var Msg: TWMNCLButtonDown);
begin
if Msg.HitTest = HTHELP then
begin
OutputDebugString('Help button down');
Msg.Result := 0;
end
else
inherited;
end;
procedure TMainFrm.WMNCLButtonUp(var Msg: TWMNCLButtonUp);
begin
if Msg.HitTest = HTHELP then
begin
OutputDebugString('Help button up');
Msg.Result := 0;
end
else
inherited;
end;
有没有办法通过自定义VCL样式启动这些事件?
答案 0 :(得分:1)
表单样式钩子处理该消息:
TFormStyleHook = class(TMouseTrackControlStyleHook)
....
procedure WMNCLButtonUp(var Message: TWMNCHitMessage); message WM_NCLBUTTONUP;
end;
实施包括此
else if (Message.HitTest = HTHELP) and (biHelp in Form.BorderIcons) then
Help;
这将调用表单样式钩子的虚拟Help
方法。这是这样实现的:
procedure TFormStyleHook.Help;
begin
SendMessage(Handle, WM_SYSCOMMAND, SC_CONTEXTHELP, 0)
end;
因此,您只需听取WM_SYSCOMMAND
并为wParam
测试SC_CONTEXTHELP
即可。像这样:
type
TMainFrm = class(TForm)
protected
procedure WMSysCommand(var Message: TWMSysCommand); message WM_SYSCOMMAND;
end;
....
procedure TMainFrm.WMSysCommand(var Message: TWMSysCommand);
begin
if Message.CmdType = SC_CONTEXTHELP then begin
OutputDebugString('Help requested');
Message.Result := 0;
end else begin
inherited;
end;
end;