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 DECL_WINDOWS_FUNCTION(static, HWND, HtmlHelpA, (HWND, LPCSTR, UINT, DWORD));
23 static char *chm_path;
24 #endif /* NO_HTMLHELP */
28 char b[2048], *p, *q, *r;
31 GetModuleFileName(NULL, b, sizeof(b) - 1);
34 if (p && p >= r) r = p+1;
36 if (q && q >= r) r = q+1;
37 strcpy(r, PUTTY_HELP_FILE);
38 if ( (fp = fopen(b, "r")) != NULL) {
39 help_path = dupstr(b);
43 strcpy(r, PUTTY_HELP_CONTENTS);
44 if ( (fp = fopen(b, "r")) != NULL) {
45 help_has_contents = TRUE;
48 help_has_contents = FALSE;
51 strcpy(r, PUTTY_CHM_FILE);
52 if ( (fp = fopen(b, "r")) != NULL) {
58 HINSTANCE dllHH = load_system32_dll("hhctrl.ocx");
59 GET_WINDOWS_FUNCTION(dllHH, HtmlHelpA);
67 #endif /* NO_HTMLHELP */
70 void shutdown_help(void)
72 /* Nothing to do currently.
73 * (If we were running HTML Help single-threaded, this is where we'd
74 * call HH_UNINITIALIZE.) */
80 * FIXME: it would be nice here to disregard help_path on
81 * platforms that didn't have WINHLP32. But that's probably
82 * unrealistic, since even Vista will have it if the user
83 * specifically downloads it.
85 return (help_path != NULL
88 #endif /* NO_HTMLHELP */
92 void launch_help(HWND hwnd, const char *topic)
95 int colonpos = strcspn(topic, ":");
100 assert(topic[colonpos] != '\0');
101 fname = dupprintf("%s::/%s.html>main", chm_path,
102 topic + colonpos + 1);
103 p_HtmlHelpA(hwnd, fname, HH_DISPLAY_TOPIC, 0);
106 #endif /* NO_HTMLHELP */
108 char *cmd = dupprintf("JI(`',`%.*s')", colonpos, topic);
109 WinHelp(hwnd, help_path, HELP_COMMAND, (ULONG_PTR)cmd);
115 p_HtmlHelpA(hwnd, chm_path, HH_DISPLAY_TOPIC, 0);
117 #endif /* NO_HTMLHELP */
119 WinHelp(hwnd, help_path,
120 help_has_contents ? HELP_FINDER : HELP_CONTENTS, 0);
123 requested_help = TRUE;
126 void quit_help(HWND hwnd)
128 if (requested_help) {
131 p_HtmlHelpA(NULL, NULL, HH_CLOSE_ALL, 0);
133 #endif /* NO_HTMLHELP */
135 WinHelp(hwnd, help_path, HELP_QUIT, 0);
137 requested_help = FALSE;