worked on premove bug
[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 #include "help.h"
28 \r
29 FILE *debugFP;\r
30 \r
31 HWND WINAPI\r
32 HtmlHelp( HWND hwnd, LPCSTR helpFile, UINT action, DWORD_PTR data )\r
33 {\r
34         PROCESS_INFORMATION helpProcInfo;\r
35         STARTUPINFO siStartInfo;\r
36         char buf[100];\r
37         static int status = 0;\r
38         FILE *f;\r
39 \r
40         if(status < 0) return NULL;\r
41 \r
42         if(!status) {\r
43                 f = fopen(helpFile, "r");\r
44                 if(f == NULL) {\r
45                         status = -1;\r
46                         return NULL;\r
47                 }\r
48                 status = 1;\r
49                 fclose(f);\r
50         }\r
51 \r
52         siStartInfo.cb = sizeof(STARTUPINFO);\r
53         siStartInfo.lpReserved = NULL;\r
54         siStartInfo.lpDesktop = NULL;\r
55         siStartInfo.lpTitle = NULL;\r
56         siStartInfo.dwFlags = STARTF_USESTDHANDLES;\r
57         siStartInfo.cbReserved2 = 0;\r
58         siStartInfo.lpReserved2 = NULL;\r
59         siStartInfo.hStdInput = NULL;\r
60         siStartInfo.hStdOutput = NULL;\r
61         siStartInfo.hStdError = debugFP;\r
62 \r
63         sprintf(buf, "Hh.exe %s", helpFile);\r
64 \r
65         // ignore the other parameters; just start the viewer with the help file\r
66         if(  CreateProcess(NULL,\r
67                            buf,            /* command line */\r
68                            NULL,           /* process security attributes */\r
69                            NULL,           /* primary thread security attrs */\r
70                            FALSE,          /* handles are inherited */\r
71                            DETACHED_PROCESS|CREATE_NEW_PROCESS_GROUP,\r
72                            NULL,           /* use parent's environment */\r
73                            NULL,\r
74                            &siStartInfo,   /* STARTUPINFO pointer */\r
75                            &helpProcInfo)  /* receives PROCESS_INFORMATION */\r
76                 ) return hwnd; else return NULL;\r
77 }\r
78 \r
79 //HWND WINAPI\r
80 int\r
81 MyHelp(HWND hwnd, LPSTR helpFile, UINT action, DWORD_PTR data)\r
82 {\r
83         static int status = 0;\r
84         FILE *f;\r
85 \r
86         if(status < 0) return 0;\r
87 \r
88         if(!status) {\r
89                 f = fopen(helpFile, "r");\r
90                 if(f == NULL) {\r
91                         status = -1;\r
92                         return 0;\r
93                 }\r
94                 status = 1;\r
95                 fclose(f);\r
96         }\r
97         return WinHelp(hwnd, helpFile, action, data);\r
98 }\r