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
);
66 #endif /* NO_HTMLHELP */
69 void shutdown_help(void)
71 /* Nothing to do currently.
72 * (If we were running HTML Help single-threaded, this is where we'd
73 * call HH_UNINITIALIZE.) */
79 * FIXME: it would be nice here to disregard help_path on
80 * platforms that didn't have WINHLP32. But that's probably
81 * unrealistic, since even Vista will have it if the user
82 * specifically downloads it.
87 #endif /* NO_HTMLHELP */
91 void launch_help(HWND hwnd
, const char *topic
)
94 int colonpos
= strcspn(topic
, ":");
99 assert(topic
[colonpos
] != '\0');
100 fname
= dupprintf("%s::/%s.html>main", chm_path
,
101 topic
+ colonpos
+ 1);
102 p_HtmlHelpA(hwnd
, fname
, HH_DISPLAY_TOPIC
, 0);
105 #endif /* NO_HTMLHELP */
107 char *cmd
= dupprintf("JI(`',`%.*s')", colonpos
, topic
);
108 WinHelp(hwnd
, help_path
, HELP_COMMAND
, (DWORD
)cmd
);
114 p_HtmlHelpA(hwnd
, chm_path
, HH_DISPLAY_TOPIC
, 0);
116 #endif /* NO_HTMLHELP */
118 WinHelp(hwnd
, help_path
,
119 help_has_contents ? HELP_FINDER
: HELP_CONTENTS
, 0);
122 requested_help
= TRUE
;
125 void quit_help(HWND hwnd
)
127 if (requested_help
) {
130 p_HtmlHelpA(NULL
, NULL
, HH_CLOSE_ALL
, 0);
132 #endif /* NO_HTMLHELP */
134 WinHelp(hwnd
, help_path
, HELP_QUIT
, 0);
136 requested_help
= FALSE
;