0

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?

help-info.de
  • 6,695
  • 16
  • 39
  • 41
maxhugen
  • 1,870
  • 4
  • 22
  • 44
  • Are there any weird problems with other windows on the desktop? (If there are, try restarting PC first.) – miroxlav Sep 02 '15 at 04:39
  • @maxhugen : Are there any options changed in the CHM file compiling process e.g. like Extended Styles > TopMost after your first testing? – help-info.de Sep 04 '15 at 10:26

2 Answers2

2

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.

help-info.de
  • 6,695
  • 16
  • 39
  • 41
  • I renamed the hh.dat file as you suggested, and it appears to have fixed the probs. The Help file is behaving as expected now. Cheers! – maxhugen Sep 05 '15 at 03:11
0

I see you have hWnd – do you think you can add a code to send the help window to the foreground programmatically?

You can call SetForegroundWindow() to do the job. Someone has solved similar problem already, you just need to port call to SetForegroundWindow() or SetForegroundWindowNative() into the VBA.


EDIT: You report weird behavior that SetForegroundWindow() makes help window to flash only briefly.

Try issuing VBA's AppActivate command – it has helped someone else.

If this problem persists, you can try some workaround like resizing your app and help window to show them side-by-side.

Community
  • 1
  • 1
miroxlav
  • 11,796
  • 5
  • 58
  • 99
  • I've tried SetForegroundWindow(). I see the Help file briefly then it disappears behind Access. I've found that if I click into Access, the Help will re-appear! If I then click the the Help windows Title Bar, it disappears, but if I click in the 'body' of the window, the Help screen doesn't disappear, and I can navigate etc in Help. Very weird. :( – maxhugen Sep 02 '15 at 07:43