Helpfile opened from modal window unresponsive

后端 未结 1 645
孤独总比滥情好
孤独总比滥情好 2020-12-16 04:26

Using Delphi XE2, Win64.

So I have a large application with many forms and if I open the help file from the main form and open a modal window and then hit F1 to fire

相关标签:
1条回答
  • 2020-12-16 04:38

    This is a serious design flaw in HtmlHelpViewer. And it's easy to reproduce the behaviour you describe. Well done for specifying the problem so clearly. The issue afflicts both 32 and 64 bit programs equally.

    Personally I don't use HtmlHelpViewer because it just doesn't work. I implement a handler for TApplication.OnHelp. It looks like this:

    class function THelpWindowManager.ApplicationHelp(Command: Word; 
      Data: THelpEventData; var CallHelp: Boolean): Boolean;
    begin
      CallHelp := False;
      Result := True;
      //argh, WinHelp commands
      case Command of
      HELP_CONTEXT,HELP_CONTEXTPOPUP:
        HtmlHelp(GetDesktopWindow, Application.HelpFile, HH_HELP_CONTEXT, Data);
      end;
    end;
    

    Put that in in a class and assign it to Application.OnHelp on startup:

    Application.OnHelp := THelpWindowManager.ApplicationHelp;
    

    I've just tested that out on the trivial two form application and it works well. In real code you may wish to embellish this. For example, my actual code is more complex. It stores in user settings the position and window state of the help window when it is closed. And then when shown again, that position and window state are restored. So that the help window appears to remember where it last was on the screen.


    Thanks to @Sertac for dredging out the details in the comments below. In summary here's where the HtmlHelpViewer code goes wrong:

    1. It makes sends the HH_INITIALIZE command at help system startup.
    2. As described in the documentation this configures HTML Help to run on the same thread as the calling application instead of a secondary thread.
    3. When you call ShowModal that calls DisableTaskWindows which disables windows in the calling thread.
    4. Because the help viewer window was created by your app's main thread (because of the HH_INITIALIZE command), it gets disabled.

    And that's why you cannot interact with the a pre-existing help window whilst a Delphi modal form is active.

    0 讨论(0)
提交回复
热议问题