Question

I am trying to use MSFT HTML Help to provide Help System for one of our applications.

I encounter a problem and couldn't find any clue in any documentation. I believe it's a simple problem with easy solution, just need to know it:).

HTML Help keyword file allow users to create multiple level of keywords. After opening the Help Window and enter the "Index" tab, there is a "Type in the keyword to find:" area where user can input keywords, all available keywords are also showed below. While typing, the correct hit keyword will be scrolled into the window and highlighted.

The problem is second level keyword is not scrolled and high lighted correctly. After typing the first level keyword and finding the keyword, then next no matter pressing what key the second level keyword cannot be highlighted correctly. As an result, the topic relating to the second key cannot be displayed correctly.

Anyone know what is the separator key between the different level of keywords to use to continue to search in next level of keyword? This problem also happens using HTML Help API, where an F1 key should find the second level keyword but actually could not.

For example, I have the following keywords:

key1

key2

   x_subkey_of_key2

   y_subkey_of_key2

   z_subkey_of_key2

key3

key4

After typing key2 and hilights key2, then no matter which key I press, it cannot highlight y_subkey_of_key2. Many key will high lights z_subkey_of_key2 which is the last subkey of key2.

Any ideas?

Thanks a lot.

No correct solution

OTHER TIPS

Ahaa!!! After one hours' typing and trying, I figured out that TWO SPACES are needed between the first level keyword and second level keyword, and an Enter key is needed at last to show the topic linked from the second keyword!!!!

Remember, exactly two spaces! one or three does not work. The trick is, while typing the second space and second keyword, some other keyword get highlighted in the list of keywords, which can make you think you have already made a mistake and would not continue to finish typing the second keyword! Is this a hoax by Microsoft engineer?

However, although manually it works, seems the software API does not work immediately with the TWO spaces. If I call the following API in C# upon F1 key pressed:

System.Windows.Forms.Help.ShowHelp(this, "file:///C:/apps/MyHelpContentNew/QACT.chm",
     System.Windows.Forms.HelpNavigator.KeywordIndex, "key2  x_subkey_of_key2");

it does not show the topic linked from x_subkey_of_key2. But it's almost there, the Help Window shows up with correct two levels' keywords put in the search TextBox, only missing a "Car-Return"!

Then I tried to add the car-return like this:

System.Windows.Forms.Help.ShowHelp(this, "file:///C:/apps/MyHelpContentNew/QACT.chm",
      System.Windows.Forms.HelpNavigator.KeywordIndex, "key2  x_subkey_of_key2\n");

It doesn't work either. So I guess I need send a car-return key to the Help Window programmingly. Will post if I once I implement it.

Now I made it work also in the program in handling F1 key. Upon handling F1 key, I called this API to launch the Help Window and populate the keyword textbox with two levels keywords separated with two spaces:

{
 System.Windows.Forms.Help.ShowHelp(this, "file:///C:/apps/MyHelpContentNew/QACT.chm",
 System.Windows.Forms.HelpNavigator.KeywordIndex, "key2  x_subkey_of_key2");
}

Then, I need send a "ENTER" key to that Help Window. I read some MSDN doc and figured out the following ways to send the "ENTER" key to that window:

First we need call Win32 function EnumChildWindows() to lookup all open windows. The Win32 function will callback to C# for processing of each open window. So when calling the Win32 function, we need pass a C# function as callback. This C# function is defined as a Delegate and inside it we can filter out the HTML Help Window and send "ENTER" key to it. The HTML Help Window is usually called Your-App-Name+Help. For example, if you application is named "XYZ", then the HTML Help window launched by ShowHelp() is called "XYZ Help". Here is the code:

using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;

class YourClass {
  [DllImport("user32.dll")]
  public static extern bool SetForegroundWindow(IntPtr hWnd);

  // declare the delegate
  public delegate bool WindowEnumDelegate(IntPtr hwnd,
                                           int lParam);

  // declare the API function to enumerate child windows
  [DllImport("user32.dll")]
  public static extern int EnumChildWindows(IntPtr hwnd,
                                            WindowEnumDelegate del,
                                            int lParam);

  // declare the GetWindowText API function
  [DllImport("user32.dll")]
  public static extern int GetWindowText(IntPtr hwnd,
                                         StringBuilder bld, int size);

  //define your callback function:
  public static bool WindowEnumProc(IntPtr hwnd, int lParam)
  {
     // get the text from the window
     StringBuilder bld = new StringBuilder(256);
     GetWindowText(hwnd, bld, 256);
     string text = bld.ToString();

     if (text.Length > 0 )
     {
        if (text == "XYZ Help")
        {
           //IntPtr h = p.MainWindowHandle;
           SetForegroundWindow(hwnd);
           SendKeys.Send("{ENTER}");
        }
     }
     return true;
  }

//In your F1 key handler, after launch the Help Window by calling ShowHelp(), instantiate the //callback function delegate and invoke the EnumChildWindows():

  private void GenericTreeView_KeyDown(object sender, KeyEventArgs e)
  {
     if (e.KeyCode == Keys.F1)
     {
        System.Windows.Forms.Help.ShowHelp(this, "file:///C:/apps/MyHelpContentNew/QACT.chm",
            System.Windows.Forms.HelpNavigator.KeywordIndex, "key2  x_subkey_of_key2");
              // instantiate the delegate
              WindowEnumDelegate del
                      = new WindowEnumDelegate(WindowEnumProc);

              // call the win32 function
              EnumChildWindows(IntPtr.Zero, del, 0);
     }
  }

}

Voila!

You will see that upon pressing F1 key, the Help Window nicely opens the correct HTML file and slides to the anchor that is pointed to by the two level keywords!

BTW, I found putting the index inside the HTML file does not help (even if I enable the option of using keyword inside HTML file). I have to put the keyword in the keyword file explicitly.

Enjoy!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top