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