我无法在打开和保存对话框中获得 Delphi 上下文相关帮助

发布于 2024-09-27 09:09:37 字数 1044 浏览 7 评论 0原文

我有一个带有 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.

I have a Delphi 2006 app with a CHM help file. It all works OK except that I cannot get any help to connect to the "Help" button on the TOpenDialog and TSaveDialog.

A simple program demonstrating this is shown below. Clicking button 2 opens the help file and displays the correct page. Clicking button 1 opens the dialog, but clicking on the help button in the dialog has no effect.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

格子衫的從容 2024-10-04 09:09:37

使用默认设置,TOpenDialog 的帮助消息处理不起作用(您应该将其提交到 Quality Central)。

具体原因是因为 Windows 将帮助消息发送到对话框的父级,而不是对话框本身,因此除非将表单设置为处理它,否则它只会被忽略。

解决方法是将 Application.ModalPopupMode 设置为 pmAuto 而不是默认值下午没有。您可以在正常启动代码期间或在显示对话框之前执行一次此操作。设置完成后,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.

With default settings TOpenDialog's help message handling doesn't work (you should submit it to Quality Central).

The specific reason is because Windows sends the help message to the dialog's parent, rather than the dialog itself, so unless your form is set up to process it it just gets ignored.

The fix is to set Application.ModalPopupMode to pmAuto instead of the default of pmNone. You can do that once during your normal startup code, or just before you show the dialog. When that's set Delphi creates an intermediate window (Dialogs.pas::TRedirectorWindow) which handles the message correctly.

If for some reason you can't change the ModalPopupMode then, as I said, you need to handle the message on your form:

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文