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 DWORD html_help_cookie;
25 static htmlhelp_t htmlhelp;
26 #endif /* NO_HTMLHELP */
30 char b[2048], *p, *q, *r;
33 GetModuleFileName(NULL, b, sizeof(b) - 1);
36 if (p && p >= r) r = p+1;
38 if (q && q >= r) r = q+1;
39 strcpy(r, PUTTY_HELP_FILE);
40 if ( (fp = fopen(b, "r")) != NULL) {
41 help_path = dupstr(b);
45 strcpy(r, PUTTY_HELP_CONTENTS);
46 if ( (fp = fopen(b, "r")) != NULL) {
47 help_has_contents = TRUE;
50 help_has_contents = FALSE;
53 strcpy(r, PUTTY_CHM_FILE);
54 if ( (fp = fopen(b, "r")) != NULL) {
60 HINSTANCE dllHH = LoadLibrary("hhctrl.ocx");
62 htmlhelp = (htmlhelp_t)GetProcAddress(dllHH, "HtmlHelpA");
67 htmlhelp(NULL, NULL, HH_INITIALIZE, (DWORD)&html_help_cookie);
71 #endif /* NO_HTMLHELP */
74 void shutdown_help(void)
78 htmlhelp(NULL, NULL, HH_UNINITIALIZE, html_help_cookie);
79 #endif /* NO_HTMLHELP */
85 * FIXME: it would be nice here to disregard help_path on
86 * platforms that didn't have WINHLP32. But that's probably
87 * unrealistic, since even Vista will have it if the user
88 * specifically downloads it.
93 #endif /* NO_HTMLHELP */
97 void launch_help(HWND hwnd, const char *topic)
100 int colonpos = strcspn(topic, ":");
105 assert(topic[colonpos] != '\0');
106 fname = dupprintf("%s::/%s.html>main", chm_path,
107 topic + colonpos + 1);
108 htmlhelp(hwnd, fname, HH_DISPLAY_TOPIC, 0);
111 #endif /* NO_HTMLHELP */
113 char *cmd = dupprintf("JI(`',`%.*s')", colonpos, topic);
114 WinHelp(hwnd, help_path, HELP_COMMAND, (DWORD)cmd);
120 htmlhelp(hwnd, chm_path, HH_DISPLAY_TOPIC, 0);
122 #endif /* NO_HTMLHELP */
124 WinHelp(hwnd, help_path,
125 help_has_contents ? HELP_FINDER : HELP_CONTENTS, 0);
128 requested_help = TRUE;
131 void quit_help(HWND hwnd)
133 if (requested_help) {
136 htmlhelp(NULL, NULL, HH_CLOSE_ALL, 0);
138 #endif /* NO_HTMLHELP */
140 WinHelp(hwnd, help_path, HELP_QUIT, 0);
142 requested_help = FALSE;