C # generate a CHM File (entry)

Source: Internet
Author: User

HTML Help Workshop Introduction: Microsoft'sHTML Help WorkShopThe best tool for creating chm files.

In this article, we will use programming methods to compile html files into CHM files. Before starting programming, we need to know how HTML Help Workshop generates CHM.

The following three files are required for compiling HTML Help Workshop into a CHM File: hhp, hhc, and hhk file suffix.

Hhp: In the CHM project file, the parameters of CHM target file attribute 95% are determined here.
Hhc, list file, determine the content under the "directory" tab in the left-side tree list of the target file.
Hhk, index file, determine the content under the "Index" tab in the left-side tree list of the target file.
Hhp is almost a standard INI file. It is divided into three sections: Option, Windows, Files.

The typical configuration file (hhp) structure is as follows:

[OPTIONS]
Compatibility = 1.1 Or later
Default window = Main
Default font =, 9, 1
Contents file = test. hhc
Index file = test. hhk
Display compile progress = Yes
Full-text search = Yes
Language = 0X804 Chinese (China)

[WINDOWS]
Main =, "test. hhc "," test. hhk ", 0x20, 0xB4, 0x104E, [80, 60, 720,540], 0x0 0, 0

[FILES]
NewTopic.html

 

To explain it a bit:

Default window = Main: Default display mode, which is displayed on the home page.

Default font =, 9, 1: Default font

Contents file = test. hhc: Content file

Index file = test. hhk: Index file

Display compile progress = Yes: whether to Display the compilation process

Full-text search = Yes: Full-text search

Language = 0X804 Chinese (China): default Language

 

The index file (hhk) is also an HTML file that contains several keywords. When you open the chm File, click the index tag and enter a keyword, the chm file displays a list of topics related to this keyword, so that you can easily find related topics. The typical file structure is as follows:
 
Code
 
 Doctype html public "-// IETF // dtd html // EN">
<HTML>
<HEAD>
<Meta name = "GENERATOR" content = "Microsoft HTML Help Workshop 4.1">

Doctype html public "-// IETF // dtd html // EN">
<HTML>
<HEAD>
<Meta name = "GENERATOR" content = "Microsoft HTML Help Workshop 4.1">

Process helpCompileProcess = new Process (); // create a new Process and use Process to start HHC. EXE to Compile a CHM File
Try
{
// Determine whether a file exists and is not occupied
Try
{
String path = _ chmFile; // chm generation path
If (File. Exists (path ))
{
File. Delete (path );
}
}
Catch
{
Throw new Exception ("file opened! ");
}

ProcessStartInfo processStartInfo = new ProcessStartInfo ();
ProcessStartInfo. WindowStyle = ProcessWindowStyle. Hidden;
ProcessStartInfo. FileName = hhcFile; // call the HHC. EXE file.
ProcessStartInfo. Arguments = "\" "+ Path. GetFullPath (GetPathToProjectFile () +" \ ""; // obtain an empty HHP File
ProcessStartInfo. UseShellExecute = false;
HelpCompileProcess. StartInfo = processStartInfo;
HelpCompileProcess. Start ();
HelpCompileProcess. WaitForExit (); // The component waits for the associated process to exit indefinitely.

If (helpCompileProcess. ExitCode = 0)
{
MessageBox. Show (new Exception (). Message );
Return false;
}
}
Finally
{
HelpCompileProcess. Close ();
}
Return true;

 

 

The attachment is a project in. Net4.0. If you are interested, you can copy the file to another version.

For vs2010, run the project directly. Before running the project, delete all the hhp, hhc, hhk, and chm files in the CreateChm \ bin \ Debug directory, these files are generated after the program is run.

PS: when I try to compile some html files that reference js files and images into chm files, these js files and images can be automatically included in chm files, in this way, you can create a variety of chm files. For example, in the demo I gave, the pointer is a beautiful clock. For more complex CHM programming, I will bring it later.

 

PS: If you think it is good, please click the recommendation. If it is worth the favorites, click favorites, 3Q

 

C # create a simple CHM File Demo

 

 

 
 
 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.