我有一个带有CHM帮助文件的Delphi 2006应用程序.一切正常,除了我无法获得任何帮助连接到TOpenDialog和TSaveDialog上的“帮助”按钮.
一个简单的程序演示如下所示.单击按钮2将打开帮助文件并显示正确的页面.单击按钮1将打开对话框,但单击对话框中的帮助按钮无效.
unit Unit22; interface uses Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs,StdCtrls,HTMLHelpViewer ; type TForm22 = class(TForm) OpenDialog1: TOpenDialog; Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form22: TForm22; implementation {$R *.dfm} procedure TForm22.Button1Click(Sender: TObject); begin OpenDialog1.HelpContext := 10410 ; OpenDialog1.Execute ; end; procedure TForm22.Button2Click(Sender: TObject); begin Application.HelpContext (10410) ; end; procedure TForm22.FormCreate(Sender: TObject); begin Application.HelpFile := 'c:\help.chm' ; end; end.
解决方法
使用默认设置时,TOpenDialog的帮助消息处理不起作用(您应该将其提交给Quality Central).
具体原因是因为Windows将帮助消息发送到对话框的父级而不是对话框本身,因此除非您的表单设置为处理它,否则它将被忽略.
修复是将Application.ModalPopupMode设置为pmAuto而不是默认值pmNone.您可以在正常启动代码期间或在显示对话框之前执行此操作.当设置时,Delphi创建了一个中间窗口(Dialogs.pas :: TRedirectorWindow),它正确处理消息.
如果由于某种原因你无法更改ModalPopupMode,正如我所说,你需要处理表单上的消息:
TForm22 = class(TForm) ... procedure WndProc(var Message: TMessage); override; end; initialization var HelpMsg: Cardinal; procedure TForm22.WndProc(var Message: TMessage); begin inherited; if (Message.Msg = HelpMsg) and (OpenDialog1.Handle <> 0) then Application.HelpContext(OpenDialog1.HelpContext); end; initialization HelpMsg := RegisterWindowMessage(HelpMsgString); end.