Click here to Skip to main content
13,768,043 members
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

7K views
191 downloads
18 bookmarked
Posted 6 Mar 2018
Licenced CPOL

A Programmable Desktop HTML Help Builder

, 6 Mar 2018
Rate this:
Please Sign up or sign in to vote.
A programmable desktop HTML help application in C#

Introduction

It is often desirable for desktop developers to include some sort of local help in order to demystify the use of an application for a user. This is particularly useful when there is no reliable internet connection available. There are a number of commercially available programs which propose to accomplish this, but most are not free. A freestanding, Microsoft HTML Help Workshop, is still available, but no longer is under active development, and works poorly (if at all) on Windows 10 systems. MFC C++ developers, used to be able to click on Context Sensitive Help in the Wizard to implement HTML Help, but as of Visual Studio 2017, this is no longer an option. The current application provides developers with a customizable, freestanding help application patterned after HTML Help Workshop, written entirely in C#, and which works on Windows 10.

Background

For developers who prefer .NET and C# for demonstrating proof of concept desktop applications, whether or not they are intended to ultimately be run via a network, the only user help options are to purchase a subscription to an app, for example, RoboHelp (C) Adobe Systems, or to provide HTML files on a server. While the latter makes it easy to update for all users, not all users have access to internet, or they operate in a network environment that prevents remote server access. It seems apparent that an economically feasible, customizable, locally-based HTML help system should be of considerable value to C# Windows developers.

Using the Code

The THtmlHelp window contains only two major components, a Tab Control, and a Web Browser. The Tab Control contains three pages, a Contents page with a TreeView that lists all the help files, an Index page that contains a list of key words, and a Search page that facilitates searching all of the help files for a particular word. The web browser component is a modified and stripped down version of that obtained from the CodeProject article "Web Browser in C# by Claudia Goga, 20 Feb 2010. The source code contains two separate applications, THelpViewer and KeyWordListBuilder which can be compiled and run separately. The THelpViewer executable is the actual HTML Help Viewer. The downloadable source has only rudimentary pages designed to serve as a template for developers to create their own help pages. In order to do that, a developer must utilize an HTML editor. In this respect, the application is similar to most other HTML help programs. Running THtmlHelp.exe in the correct directory structure will result in the application automatically populating the TabControl TreeView with all of the HTML help files. The Index Page needs to be handled separately in order to provide a list of key words and their respective links to appropriate help files. THtmlHelp.exe will automatically load the IndexData.xml file that contains the necessary information to populate the Index Page. In order to customize the IndexData.xml file, you can either do it by hand, or better yet, use the accompanying KeyWordListBuilder application. The builder app contains some simple instructions and will allow you to add key words and associate them with a particular file, then save the entire list as an XML file. Please note that both THtmlHelp.exe and the IndexData.xml file MUST be placed in the root directory of your application, and that directory MUST also contain the subdirectory 'hlp' which in turn contains all of your help htm files and a subdirectory for images if you choose to utilize any. Note further that the title bar of the THtmlViewer will contain the name of the HTML page as you have named it.

The code below shows how the viewer loads all of the files contained in the target directory, then loads the TreeView and the Browser. This assumes that there are files including a contents.htm in the hlp directory.

// Fields
    public ArrayList arList  = new ArrayList();
    public String Url = string.Empty;
    public String sPath = string.Empty;
    public String sFolderPath = string.Empty;

// Constructor
public Form1()
{
    sPath = GetFullPathName("hlp/contents.htm");
    Url = "file:///" + sPath;
    int n = sPath.LastIndexOf('\\');
    sFolderPath = Path.GetDirectoryName(sPath);

    ProcessDirectory(sFolderPath);
    myTreeView();
    myBrowser();

    //..
}

public void ProcessDirectory(string targetDirectory)
{
    string[] fileEntries = Directory.GetFiles(targetDirectory);
    foreach (string fileName in fileEntries)
         arList.Add(path);
}

The code below shows how the TreeView is populated.

private void myTreeView()
{
    string directoryName = GetFullPathName(sPath);
    int n1 = directoryName.LastIndexOf('/');
    int n2 = directoryName.Length;
    directoryName = directoryName.Remove(n1, n2 - n1);
    treeView1.Nodes.Clear();
    treeView1.BeginUpdate();
    string yourParentNode = "Contents";
    treeView1.Nodes.Add(yourParentNode);
    treeView1.EndUpdate();

    try
    {
        var txtFiles = Directory.EnumerateFiles(directoryName);
        foreach (string currentFile in txtFiles)
        {
            string fileName = currentFile.Substring(directoryName.Length + 1);
            n1 = fileName.LastIndexOf('.');
            n2 = fileName.Length;
            fileName = fileName.Remove(n1, n2 - n1);
            treeView1.Nodes[0].Nodes.Add(fileName);
        }
    catch (Exception e)
    {
        MessageBox.Show("Warning: " + e.Message);
    }

    treeView1.ExpandAll();
}

Populating the Index Page is facilitated by the accompanying KeywordListBuilder app.

  • Use New, Open, and Save to manage Index Page lists (IndexData.xml).
  • Tools / Add Keyword to add to a list
  • Associate each keyword with a file in the hlp directory
  • Tools / REmove a Keyword to delete a highlighted list element.
  • Save the list as 'IndexData.xml' in the app root directory (see above).

With the THtmlHelp.exe in your calling application root directory, together with the necessary accompanying IndexData.xml file and hlp folder, your calling application can use the following code to bring up the help application.

private void contentsToolStripMenuItem_Click(object sender, EventArgs e)
{
    Process p = Process.Start("THelpViewer.exe");
    p.WaitForInputIdle();
}

protected override bool ProcessCmdKey(Keys keyData)
{
    if (keyData == Keys.F1) 
    {
        Process p = Process.Start("THelpViewer.exe");
        p.WaitForInputIdle();
        return true;
    }

    // Call the base class
    return base.ProcessCmdKey(keyData);
}

Points of Interest

It strikes me as odd that Visual Studio no longer supports HTML Help Studio (HTMLS) and developers are left on their own to provide such help. There may exist some work-around to get HTMLS to work properly, but I have been unable to find it. That is why I was compelled to develop this application. Having spent a fair amount of time programming in C++, I have been pleasantly surprised to find how straightforward, efficient, and powerful Visual Studio C# is. While this current effort could use some refinement, perhaps the single best one would be to somehow compress all the necessary help files and the application itself into a single chm-like package. I considered simply zipping all the components together, but quickly realized that there are a number of different zip file formats and accessing the zipped application would not be easy. Additionally, there is undoubtedly a way to facilitate context sensitive help, but this would add considerable complexity to the program.

History

  • Version 2.2 March 05, 2018

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Michael B Pliam
Software Developer PliaTech
United States United States
Software developer with interests in mathematics and statistics, particularly as applied to health care. CTO and founder of PliaTech.

You may also be interested in...

Pro

Comments and Discussions

 
QuestionSource URL Pin
Deacs7-Mar-18 2:39
memberDeacs7-Mar-18 2:39 
AnswerRe: Source URL Pin
Jeff Law7-Mar-18 8:21
memberJeff Law7-Mar-18 8:21 
GeneralRe: Source URL Pin
Michael B Pliam7-Mar-18 10:43
memberMichael B Pliam7-Mar-18 10:43 
QuestionBad URL? Pin
Jeff Law6-Mar-18 22:28
memberJeff Law6-Mar-18 22:28 
AnswerRe: Bad URL? Pin
Member 24433066-Mar-18 22:55
memberMember 24433066-Mar-18 22:55 
GeneralRe: Bad URL? Pin
Jeff Law7-Mar-18 8:20
memberJeff Law7-Mar-18 8:20 
SuggestionWhat is it Pin
Member 24433066-Mar-18 11:23
memberMember 24433066-Mar-18 11:23 
GeneralRe: What is it Pin
Michael B Pliam7-Mar-18 9:40
memberMichael B Pliam7-Mar-18 9:40 
SuggestionRe: What is it Pin
Member 24433067-Mar-18 12:04
memberMember 24433067-Mar-18 12:04 
GeneralRe: What is it Pin
Michael B Pliam7-Mar-18 15:34
memberMichael B Pliam7-Mar-18 15:34 
GeneralRe: What is it Pin
Member 24433067-Mar-18 20:16
memberMember 24433067-Mar-18 20:16 
GeneralRe: What is it Pin
Michael B Pliam9-Mar-18 18:30
memberMichael B Pliam9-Mar-18 18:30 
GeneralRe: What is it Pin
Member 244330610-Mar-18 5:15
memberMember 244330610-Mar-18 5:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.181116.1 | Last Updated 6 Mar 2018
Article Copyright 2018 by Michael B Pliam
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid