several small fixes
[xboard.git] / winboard / help.c
1 /*\r
2  * help.h\r
3  *\r
4  * Copyright 2009 Free Software Foundation, Inc.\r
5  * ------------------------------------------------------------------------\r
6  *\r
7  * GNU XBoard is free software: you can redistribute it and/or modify\r
8  * it under the terms of the GNU General Public License as published by\r
9  * the Free Software Foundation, either version 3 of the License, or (at\r
10  * your option) any later version.\r
11  *\r
12  * GNU XBoard is distributed in the hope that it will be useful, but\r
13  * WITHOUT ANY WARRANTY; without even the implied warranty of\r
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
15  * General Public License for more details.\r
16  *\r
17  * You should have received a copy of the GNU General Public License\r
18  * along with this program. If not, see http://www.gnu.org/licenses/.  *\r
19  *\r
20  *------------------------------------------------------------------------\r
21  ** See the file ChangeLog for a revision history.  */\r
22 \r
23 /* Windows html help function to avoid having to link with the htmlhlp.lib  */\r
24 \r
25 #include <windows.h>\r
26 #include <stdio.h>\r
27 \r
28 FILE *debugFP;\r
29 \r
30 int\r
31 HtmlHelp( HWND hwnd, LPCSTR helpFile, UINT action, DWORD data )\r
32 {\r
33         PROCESS_INFORMATION helpProcInfo;\r
34         STARTUPINFO siStartInfo;\r
35         char buf[100];\r
36         static int status = 0;\r
37         FILE *f;\r
38 \r
39         if(status < 0) return 0;\r
40 \r
41         if(!status) {\r
42                 f = fopen(helpFile, "r");\r
43                 if(f == NULL) {\r
44                         status = -1;\r
45                         return 0;\r
46                 }\r
47                 status = 1;\r
48                 fclose(f);\r
49         }\r
50 \r
51         siStartInfo.cb = sizeof(STARTUPINFO);\r
52         siStartInfo.lpReserved = NULL;\r
53         siStartInfo.lpDesktop = NULL;\r
54         siStartInfo.lpTitle = NULL;\r
55         siStartInfo.dwFlags = STARTF_USESTDHANDLES;\r
56         siStartInfo.cbReserved2 = 0;\r
57         siStartInfo.lpReserved2 = NULL;\r
58         siStartInfo.hStdInput = NULL;\r
59         siStartInfo.hStdOutput = NULL;\r
60         siStartInfo.hStdError = debugFP;\r
61 \r
62         sprintf(buf, "Hh.exe %s", helpFile);\r
63 \r
64         // ignore the other parameters; just start the viewer with the help file\r
65         return CreateProcess(NULL,\r
66                            buf,            /* command line */\r
67                            NULL,           /* process security attributes */\r
68                            NULL,           /* primary thread security attrs */\r
69                            FALSE,          /* handles are inherited */\r
70                            DETACHED_PROCESS|CREATE_NEW_PROCESS_GROUP,\r
71                            NULL,           /* use parent's environment */\r
72                            NULL,\r
73                            &siStartInfo,   /* STARTUPINFO pointer */\r
74                            &helpProcInfo); /* receives PROCESS_INFORMATION */\r
75 }\r
76 \r
77 //HWND WINAPI\r
78 int\r
79 MyHelp(HWND hwnd, LPSTR helpFile, UINT action, DWORD data)\r
80 {\r
81         static int status = 0;\r
82         FILE *f;\r
83 \r
84         if(status < 0) return 0;\r
85 \r
86         if(!status) {\r
87                 f = fopen(helpFile, "r");\r
88                 if(f == NULL) {\r
89                         status = -1;\r
90                         return 0;\r
91                 }\r
92                 status = 1;\r
93                 fclose(f);\r
94         }\r
95         return WinHelp(hwnd, helpFile, action, data);\r
96 }\r