[code]#coding: utf8
#################################### IMPORTS ###################################
#Std Libs
import ctypes
from ctypes.wintypes import BOOL
#################################### HELPERS ###################################
Force unicode for c_wchar_p
def W(s): return s.decode(‘utf8’) if isinstance(s, str) else s
################################ CTYPES WRAPPING ###############################
HtmlHelp = ctypes.windll.LoadLibrary(‘hhctrl.ocx’).HtmlHelpW
HH_KEYWORD_LOOKUP = 0x000D
class HH_AKLINK(ctypes.Structure):
fields = (
# sizeof this structure
(‘cbStruct’, ctypes.c_int),
# must be FALSE (really!)
('fReserved', BOOL),
# semi-colon separated keywords
('pszKeywords', ctypes.c_wchar_p),
# URL to jump to if no keywords found (may be NULL)
('pszUrl', ctypes.c_wchar_p),
# Message text to display in MessageBox if pszUrl is
('pszMsgText', ctypes.c_wchar_p),
('pszMsgTitle', ctypes.c_wchar_p),
# Window to display URL in
('pszWindow', ctypes.c_wchar_p),
# Displays index if keyword lookup fails.
('fIndexOnFail', BOOL)
)
############################## OPEN HELP FUNCTION ##############################
def open_help_for( key_words, # semi-colon separated keywords or sequence
help_file, # chm file
# URL to jump to if no keywords found
backup_url = u'',
# Displays index if keyword lookup fails.
display_index = True,
# 0 is fine; using sublime window handle will cause help
# to `stay on top`
hwnd=0 ):
key_words = ( u';'.join(key_words) if not isinstance(key_words, basestring)
else W(key_words) )
ak = HH_AKLINK ( ctypes.sizeof(HH_AKLINK), False, key_words,
(W(backup_url) if backup_url else None), None, None,
None, display_index )
HtmlHelp(hwnd, W(help_file), HH_KEYWORD_LOOKUP, ctypes.byref(ak))
################################################################################[/code]