2 * winhelp.c: centralised functions to launch Windows help files,
\r
3 * and to decide whether to use .HLP or .CHM help in any given
\r
14 #include <htmlhelp.h>
\r
16 typedef HWND (CALLBACK *htmlhelp_t)(HWND, LPCSTR, UINT, DWORD);
\r
18 static char *help_path, *chm_path;
\r
19 static int help_has_contents;
\r
20 static int requested_help;
\r
21 static DWORD html_help_cookie;
\r
22 static htmlhelp_t htmlhelp;
\r
24 void init_help(void)
\r
26 char b[2048], *p, *q, *r;
\r
29 GetModuleFileName(NULL, b, sizeof(b) - 1);
\r
31 p = strrchr(b, '\\');
\r
32 if (p && p >= r) r = p+1;
\r
33 q = strrchr(b, ':');
\r
34 if (q && q >= r) r = q+1;
\r
35 strcpy(r, PUTTY_HELP_FILE);
\r
36 if ( (fp = fopen(b, "r")) != NULL) {
\r
37 help_path = dupstr(b);
\r
41 strcpy(r, PUTTY_HELP_CONTENTS);
\r
42 if ( (fp = fopen(b, "r")) != NULL) {
\r
43 help_has_contents = TRUE;
\r
46 help_has_contents = FALSE;
\r
48 strcpy(r, PUTTY_CHM_FILE);
\r
49 if ( (fp = fopen(b, "r")) != NULL) {
\r
50 chm_path = dupstr(b);
\r
55 HINSTANCE dllHH = LoadLibrary("hhctrl.ocx");
\r
57 htmlhelp = (htmlhelp_t)GetProcAddress(dllHH, "HtmlHelpA");
\r
62 htmlhelp(NULL, NULL, HH_INITIALIZE, (DWORD)&html_help_cookie);
\r
68 void shutdown_help(void)
\r
71 htmlhelp(NULL, NULL, HH_UNINITIALIZE, html_help_cookie);
\r
77 * FIXME: it would be nice here to disregard help_path on
\r
78 * platforms that didn't have WINHLP32. But that's probably
\r
79 * unrealistic, since even Vista will have it if the user
\r
80 * specifically downloads it.
\r
82 return (help_path || chm_path);
\r
85 void launch_help(HWND hwnd, const char *topic)
\r
88 int colonpos = strcspn(topic, ":");
\r
92 assert(topic[colonpos] != '\0');
\r
93 fname = dupprintf("%s::/%s.html>main", chm_path,
\r
94 topic + colonpos + 1);
\r
95 htmlhelp(hwnd, fname, HH_DISPLAY_TOPIC, 0);
\r
97 } else if (help_path) {
\r
98 char *cmd = dupprintf("JI(`',`%.*s')", colonpos, topic);
\r
99 WinHelp(hwnd, help_path, HELP_COMMAND, (DWORD)cmd);
\r
104 htmlhelp(hwnd, chm_path, HH_DISPLAY_TOPIC, 0);
\r
105 } else if (help_path) {
\r
106 WinHelp(hwnd, help_path,
\r
107 help_has_contents ? HELP_FINDER : HELP_CONTENTS, 0);
\r
110 requested_help = TRUE;
\r
113 void quit_help(HWND hwnd)
\r
115 if (requested_help) {
\r
117 htmlhelp(NULL, NULL, HH_CLOSE_ALL, 0);
\r
118 } else if (help_path) {
\r
119 WinHelp(hwnd, help_path, HELP_QUIT, 0);
\r
121 requested_help = FALSE;
\r