vbams-accesschmhtml-help

Ms Access CHM Help File Can't Get Focus


I'm opening a custom help file (CHM) using VBA and the api 'HtmlHelp', eg:

hWnd = HtmlHelp(Application.hWndAccessApp, sFile, HH_HELP_CONTEXT, context_id)

The Help file opens, but it's hidden behind the Access window, and although it's icon is displayed in the Taskbar, clicking the icon still does not bring it to the foreground - it remains hidden behind Access.

When I first started testing the Help file (on a Win8.1 machine), it opened correctly in front of the Access window, but now it won't. Does anyone have any suggestions as to what is causing this behaviour?


Solution

  • Some thoughts only - but be careful with the first hint:


    Which purpose does the file hh.dat serve?

    The hh.dat file stores user-specific information on all the HTMLHelp files (*.CHM) on your system (position, favourite topics, search history, etc.), and can cause a error if it has somehow been corrupted. Delete or rename the file hh.dat to reset all (!) CHM windows on your system to their default settings. You should find hh.dat in this directory:

    \Documents and Settings\%username%\Application Data\Microsoft\HTML Help

    Windows will create a new version of hh.dat when you next open any .chm file.


    According to Microsoft's HTML Help API documentation (http://msdn2.microsoft.com/en-us/library/ms644703(VS.85).aspx):

    Any help window that you create through the HTML Help API is owned by the calling, or parent, program. This allows the help window to stay on top of its parent, yet not be on top of any other program that has focus.

    So the fact that the help window retains focus is actually the standard behaviour.

    If you look at a typical HTML Help API call, you'll see that the first parameter specifies the "handle" of the window from which help is called:

     HtmlHelp(hwndCaller,"YourHelpFile.chm",HH_HELP_CONTEXT,1001); 
    

    If the developer passes "null" rather than the window handle as the first parameter of the call, the help window is no longer owned by the calling program, and so does not retain focus. Here is an example of a modified call:

    HtmlHelp(0,"YourHelpFile.chm",HH_HELP_CONTEXT,1001);
    

    There's a drawback to this, though: when called in this way, the help window is no longer bound by the actions of the calling program. So if the user closes or minimises the program, the help window isn't closed or minimised as well.