Skip to content


Compile a CHM help file

Here's a short demonstration of how to compile a CHM help file using Python and a batch file.
print ("*******************************")
print ("We compile a CHM help file  ...")
print ("*******************************")
# First import the 'ctypes' module. 
# 'ctypes' provides C compatible data types and allows calling functions in DLLs or shared libraries.
import ctypes  # An included library with Python install.
# ctypes.windll.user32.MessageBoxW(0, "Open CHM", "Your title", 1) # OK only
messageBox = ctypes.windll.user32.MessageBoxA
# documentation:
# 1=OK Cancel, 2=Cancel, Retry, Ignore
returnValue = messageBox(None,"Compile Help Module (CHM) now?", "CHM and Python", 1) 

if returnValue == 1:
    print("Pressed OK")
    # How to compile a chm file in Python?
    # ---------------------------------
    import os   

elif returnValue == 2: 
    print("user pressed cancel button!")

Following batch file is used by the Python script.

@echo off
REM -----------------------------------------
REM batch file  is located in D:\_batch
REM HH project file is located in D:\_working
REM -----------------------------------------
cd ..\_working
echo '//--- HH Compiler start --------------------------------------
"C:\Program Files (x86)\HTML Help Workshop\hhc" foobar.hhp
echo '//--- HH Compiler end   --------------------------------------
echo '//--- errorlevel -------------------------------------------
echo %errorlevel%
echo '//------------------------------------------------------------
if not %errorlevel% == 1 exit /B 1