惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Stack Overflow Blog
Stack Overflow Blog
Simon Willison's Weblog
Simon Willison's Weblog
L
LINUX DO - 最新话题
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
Scott Helme
Scott Helme
L
Lohrmann on Cybersecurity
博客园 - 【当耐特】
P
Privacy & Cybersecurity Law Blog
V2EX - 技术
V2EX - 技术
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main
IT之家
IT之家
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Cloudbric
Cloudbric
云风的 BLOG
云风的 BLOG
K
Kaspersky official blog
T
Threat Research - Cisco Blogs
Webroot Blog
Webroot Blog
A
Arctic Wolf
C
CERT Recently Published Vulnerability Notes
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
G
Google Developers Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
The Hacker News
The Hacker News
MyScale Blog
MyScale Blog
Vercel News
Vercel News
B
Blog RSS Feed
F
Fortinet All Blogs
Google DeepMind News
Google DeepMind News
A
About on SuperTechFans
Microsoft Security Blog
Microsoft Security Blog
腾讯CDC
博客园 - 三生石上(FineUI控件)
D
Docker
O
OpenAI News
有赞技术团队
有赞技术团队
MongoDB | Blog
MongoDB | Blog
H
Help Net Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Help Net Security
Help Net Security
AI
AI
T
Tor Project blog
Project Zero
Project Zero
H
Heimdal Security Blog
Latest news
Latest news
NISL@THU
NISL@THU

博客园 - Mossan

UltraVNC 简体中文版 1.3.6(Win7以上系统) UltraVNC 简体中文版 1.2.4(WinXP最终版) 数据比较1.0(文本格式) 二代身份Zheng复印(手机正反面拍照生成1:1复印件图像) ownCloud安卓android客户端版本2.11.0 旧手机作为USB无线网卡使用(分享WIFI、蓝牙连接) 计算机开关损坏无法正常启动维修 限时授权复制文件 1.0(2015.9.2更新) Mysql自动备份工具1.0(2013年11月15日更新) Microsoft .NET Framework 3.5 Service Pack 1(完整软件包) 汶川地震感悟 C#模拟键盘登录网站 UltraBackup 1.5.1(2025-01-15更新) LanContain 1.2.2.3(2025-1-15更新) 利用c#开发一个telnet unix服务器或者防火墙的小工具(转) 微软推在线版Office可储存1000个Word文档 Fckeditor XML Request error:internal server error (500) 一例 网络管理员升级版LanContain(Web)源代码 蚂蚁
用C#实现将HTML文件转换为CHM文件(转)
Mossan · 2008-03-07 · via 博客园 - Mossan

这些天因为工作需要,要将一些html文件转换为chm文件,当然是需要和程序结合在一起。
后来找到NDoc,里头有一段代码是相关的,于是开始分析代码,写完之后,总结:主要是利用微软的hhc.exe来编译html文件,程序需要将具体的数据写入hhp和hhc文件。
主要代码如下:
复制C#代码保存代码public void CompileProject()
{
    Process helpCompileProcess = new Process();  //创建新的进程,NDOC采用Process启动HHC.EXE来Compile一个CHM文件

    try
    {
        ////判断文件是否存在并不被占用
        try
        {
            string path = _chmFile;  //chm生成路径

            if (File.Exists(path))
            {
                File.Delete(path);
            }
        }
        catch
        {
            throw new Exception("文件被打开!");
        }

        ProcessStartInfo processStartInfo = new ProcessStartInfo();
        processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        processStartInfo.FileName = hhcFile;  //调入HHC.EXE文件 
        processStartInfo.Arguments = "\"" + Path.GetFullPath(GetPathToProjectFile()) + "\"";//获取空的HHP文件

        helpCompileProcess.StartInfo = processStartInfo;

        //开始生成....
        helpCompileProcess.Start();

        helpCompileProcess.WaitForExit(); //组件无限期地等待关联进程退出

        if (helpCompileProcess.ExitCode == 0)
        {
            MessageBox.Show(new Exception().Message);
        }

    }
    finally
    {
        helpCompileProcess.Close();
    }
}
public void OpenProjectFile()
{
    FileStream fs = new FileStream(GetPathToProjectFile(), FileMode.Create);
    streamHtmlHelp = new System.IO.StreamWriter(fs, System.Text.Encoding.GetEncoding("GB18030"));
    streamHtmlHelp.WriteLine("[FILES]");
}
public void AddFileToProject(string filename)
{
    streamHtmlHelp.WriteLine(filename);
}
public void CloseProjectFile(string title)
{
    streamHtmlHelp.WriteLine();
    streamHtmlHelp.WriteLine("[OPTIONS]");
    streamHtmlHelp.WriteLine("Title=" + title);
    streamHtmlHelp.WriteLine("Compatibility=1.1 or later");
    streamHtmlHelp.WriteLine("Compiled file=" + GetCompiledHtmlFilename());  //chm文件名
    streamHtmlHelp.WriteLine("Contents file=" + GetContentsHtmlFilename());  //hhc文件名
    streamHtmlHelp.WriteLine("Default topic=" + _defaultTopic);  //默认页
    streamHtmlHelp.WriteLine("Display compile progress=No"); //是否显示编译过程
    streamHtmlHelp.WriteLine("Language=0x804 中文(中国)");  //chm文件语言

    streamHtmlHelp.WriteLine();
    streamHtmlHelp.WriteLine("[INFOTYPES]");

    streamHtmlHelp.Close();
}
转自:http://www.cnblogs.com/monthkey/archive/2004/06/15/15995.aspx