[英]CHM file not displaying correctly when Delphi VCL style active
My Delphi application includes a help file that the user can call from anywhere in the application (well... that is, for all the parts I've written so far...) 我的Delphi应用程序包含一个帮助文件,用户可以从应用程序中的任何位置调用该文件(嗯……也就是说,对于我到目前为止编写的所有部分……)
It also includes the ability for the user to switch from the regular style to another VCL style from a list. 它还包括用户从列表中从常规样式切换到另一种VCL样式的能力。
When no style is applied, the help file displays normally like this : 当未应用任何样式时,帮助文件通常显示如下:
But as soon as a VCL style is active, the Help file does not display correctly anymore, like this : 但是,一旦激活了VCL样式,帮助文件就无法正确显示,如下所示:
Is this due to the way I declare the HelpFile on main Form creation like this (path being a global variable pointing to the main exe folder): 这是由于我这样在主窗体创建时声明HelpFile的方式造成的(路径是指向主exe文件夹的全局变量):
Application.HelpFile := path+'Help\D.R.A.M.A. 2.0 Help.chm';
or is this a known problem that can not be solved ? 还是这是一个无法解决的已知问题?
SIDE NOTE : the help is called on helpContext should that be important to mention and the HtmlHelpViewer is added to the uses clause. 旁注:应该提到的帮助在helpContext上调用帮助,并将HtmlHelpViewer添加到uses子句中。
This answer was taken from https://forums.embarcadero.com/thread.jspa?threadID=227785 and I've confirmed works very well. 这个答案来自https://forums.embarcadero.com/thread.jspa?threadID=227785 ,我已经确认效果很好。
Drop a TApplicationEvents component onto the applications main form. 将TApplicationEvents组件拖放到应用程序主窗体上。
Implement the OnHelp event of that component as this: 通过以下方式实现该组件的OnHelp事件:
function TfmMain.ApplicationEvents1Help(Command: Word; Data: NativeInt; var CallHelp: Boolean): Boolean;
begin
CloseHelpWnd;
Result := ShellExecute(0,'open','hh.exe',
PWideChar('-mapid '+IntToStr(Data)
+' ms-its:'+Application.HelpFile),
nil,SW_SHOW) = 32;
CallHelp := false;
end;
On the main form, implement the CloseHelpWnd method as this: 在主窗体上,按以下方式实现CloseHelpWnd方法:
procedure TfmMain.CloseHelpWnd;
var
HlpWind: HWND;
const
HelpTitle = 'Your help file title';
begin
HlpWind := FindWindow('HH Parent',HelpTitle);
if HlpWind <> 0 then PostMessage(HlpWind,WM_Close,0,0);
end;
You would replace ' Your help file title ' with the title of your help file. 您可以将“ 您的帮助文件标题 ”替换为帮助文件的标题 。 This is the window caption title when you open the help file directly.
直接打开帮助文件时,这是窗口标题。
In the FormDestroy event for the main form, include a call to 在主表单的FormDestroy事件中,包括一个对的调用。
CloseHelpWnd;
So far we've not seen any issues with the above method, and because we are running the help file in a separate process, it is not affected by the VCL Styles problems evident in Delphi 10.2 Tokyo. 到目前为止,我们还没有看到上述方法的任何问题,并且由于我们在单独的进程中运行帮助文件,因此不受Delphi 10.2 Tokyo中明显的VCL样式问题的影响。
NOTE : It does not have to be the applications main form, but it must be a form that is created before the help system is needed and remains instantiated while the application is running. 注意 :它不一定是应用程序的主表单,但必须是在需要帮助系统之前创建的表单,并且该表单在应用程序运行时保持实例化。 In our case, we did it on a common resources form and then all programs we rebuilt with the new form had the help problem resolved.
在我们的案例中,我们是在公共资源表单上完成的,然后使用新表单重建的所有程序都解决了帮助问题。
NOTE : You still need to set the Application.HelpFile property as normal, but you don't need to include the HtmlHelpViewer unit in the Uses clause. 注意 :您仍然需要正常设置Application.HelpFile属性,但不需要在Uses子句中包含HtmlHelpViewer单元。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.