2 * winhelp.c: centralised functions to launch Windows help files,
3 * and to decide whether to use .HLP or .CHM help in any given
16 #endif /* NO_HTMLHELP */
18 static int requested_help;
19 static char *help_path;
20 static int help_has_contents;
22 typedef HWND (CALLBACK *htmlhelp_t)(HWND, LPCSTR, UINT, DWORD);
23 static char *chm_path;
24 static htmlhelp_t htmlhelp;
25 #endif /* NO_HTMLHELP */
29 char b[2048], *p, *q, *r;
32 GetModuleFileName(NULL, b, sizeof(b) - 1);
35 if (p && p >= r) r = p+1;
37 if (q && q >= r) r = q+1;
38 strcpy(r, PUTTY_HELP_FILE);
39 if ( (fp = fopen(b, "r")) != NULL) {
40 help_path = dupstr(b);
44 strcpy(r, PUTTY_HELP_CONTENTS);
45 if ( (fp = fopen(b, "r")) != NULL) {
46 help_has_contents = TRUE;
49 help_has_contents = FALSE;
52 strcpy(r, PUTTY_CHM_FILE);
53 if ( (fp = fopen(b, "r")) != NULL) {
59 HINSTANCE dllHH = LoadLibrary("hhctrl.ocx");
61 htmlhelp = (htmlhelp_t)GetProcAddress(dllHH, "HtmlHelpA");
68 #endif /* NO_HTMLHELP */
71 void shutdown_help(void)
73 /* Nothing to do currently.
74 * (If we were running HTML Help single-threaded, this is where we'd
75 * call HH_UNINITIALIZE.) */
81 * FIXME: it would be nice here to disregard help_path on
82 * platforms that didn't have WINHLP32. But that's probably
83 * unrealistic, since even Vista will have it if the user
84 * specifically downloads it.
89 #endif /* NO_HTMLHELP */
93 void launch_help(HWND hwnd, const char *topic)
96 int colonpos = strcspn(topic, ":");
101 assert(topic[colonpos] != '\0');
102 fname = dupprintf("%s::/%s.html>main", chm_path,
103 topic + colonpos + 1);
104 htmlhelp(hwnd, fname, HH_DISPLAY_TOPIC, 0);
107 #endif /* NO_HTMLHELP */
109 char *cmd = dupprintf("JI(`',`%.*s')", colonpos, topic);
110 WinHelp(hwnd, help_path, HELP_COMMAND, (DWORD)cmd);
116 htmlhelp(hwnd, chm_path, HH_DISPLAY_TOPIC, 0);
118 #endif /* NO_HTMLHELP */
120 WinHelp(hwnd, help_path,
121 help_has_contents ? HELP_FINDER : HELP_CONTENTS, 0);
124 requested_help = TRUE;
127 void quit_help(HWND hwnd)
129 if (requested_help) {
132 htmlhelp(NULL, NULL, HH_CLOSE_ALL, 0);
134 #endif /* NO_HTMLHELP */
136 WinHelp(hwnd, help_path, HELP_QUIT, 0);
138 requested_help = FALSE;