xref: /reactos/win32ss/user/user32/misc/winhelp.c (revision 3d93998d)
1 /*
2  *  ReactOS kernel
3  *  Copyright (C) 1998, 1999, 2000, 2001, 2002 ReactOS Team
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 /*
20  * PROJECT:         ReactOS user32.dll
21  * FILE:            win32ss/user/user32/misc/winhelp.c
22  * PURPOSE:         WinHelp
23  * PROGRAMMER:      Robert Dickenson(robd@reactos.org)
24  * UPDATE HISTORY:
25  *      23-08-2002  RDD  Created from wine sources
26  */
27 
28 #include <user32.h>
29 
30 /* WinHelp internal structure */
31 typedef struct
32 {
33     WORD size;
34     WORD command;
35     LONG data;
36     LONG reserved;
37     WORD ofsFilename;
38     WORD ofsData;
39 } WINHELP,*LPWINHELP;
40 
41 
42 /* FUNCTIONS *****************************************************************/
43 
44 /*
45  * @unimplemented
46  */
47 BOOL
48 WINAPI
WinHelpA(HWND hWnd,LPCSTR lpszHelp,UINT uCommand,DWORD_PTR dwData)49 WinHelpA(HWND hWnd, LPCSTR lpszHelp, UINT uCommand, DWORD_PTR dwData)
50 {
51 	static WORD WM_WINHELP = 0;
52 	HWND hDest;
53 	LPWINHELP lpwh;
54 	HGLOBAL hwh;
55 	int size,dsize,nlen;
56 
57 	if (!WM_WINHELP) {
58 	    WM_WINHELP = RegisterWindowMessageA("WM_WINHELP");
59 	    if (!WM_WINHELP)
60 	      return FALSE;
61     }
62 
63 	hDest = FindWindowA("MS_WINHELP", NULL);
64 	if (!hDest) {
65 	    if (uCommand == HELP_QUIT) return TRUE;
66         if (WinExec("winhlp32.exe -x", SW_SHOWNORMAL) < 32) {
67             //ERR("can't start winhlp32.exe -x ?\n");
68             return FALSE;
69         }
70 	    if (!(hDest = FindWindowA("MS_WINHELP", NULL))) {
71 	        //FIXME("did not find MS_WINHELP (FindWindow() failed, maybe global window handling still unimplemented)\n");
72 	        return FALSE;
73         }
74     }
75 	switch (uCommand) {
76 		case HELP_CONTEXT:
77 		case HELP_SETCONTENTS:
78 		case HELP_CONTENTS:
79 		case HELP_CONTEXTPOPUP:
80 		case HELP_FORCEFILE:
81 		case HELP_HELPONHELP:
82 		case HELP_FINDER:
83 		case HELP_QUIT:
84 			dsize=0;
85 			break;
86 		case HELP_KEY:
87 		case HELP_PARTIALKEY:
88 		case HELP_COMMAND:
89 			dsize = dwData ? strlen( (LPSTR)dwData )+1: 0;
90 			break;
91 		case HELP_MULTIKEY:
92 			dsize = ((LPMULTIKEYHELPA)dwData)->mkSize;
93 			break;
94 		case HELP_SETWINPOS:
95 			dsize = ((LPHELPWININFOA)dwData)->wStructSize;
96 			break;
97 		default:
98 			//FIXME("Unknown help command %d\n",uCommand);
99 			return FALSE;
100 	}
101 	if (lpszHelp)
102 		nlen = strlen(lpszHelp)+1;
103 	else
104 		nlen = 0;
105 	size = sizeof(WINHELP) + nlen + dsize;
106 	hwh = GlobalAlloc(0,size);
107 	if (hwh == NULL)
108 		return FALSE;
109 	lpwh = GlobalLock(hwh);
110 	lpwh->size = size;
111 	lpwh->command = uCommand;
112 	lpwh->data = dwData;
113 	if (nlen) {
114 		strcpy(((char*)lpwh) + sizeof(WINHELP), lpszHelp);
115 		lpwh->ofsFilename = sizeof(WINHELP);
116  	} else {
117 		lpwh->ofsFilename = 0;
118 	}
119 	if (dsize) {
120 		memcpy(((char*)lpwh)+sizeof(WINHELP)+nlen,(LPSTR)dwData,dsize);
121 		lpwh->ofsData = sizeof(WINHELP)+nlen;
122 	} else {
123 		lpwh->ofsData = 0;
124 	}
125 	GlobalUnlock(hwh);
126 	return SendMessageA(hDest, WM_WINHELP, (WPARAM)hWnd, (LPARAM)hwh);
127 }
128 
129 
130 /*
131  * @unimplemented
132  */
133 BOOL
134 WINAPI
WinHelpW(HWND hWnd,LPCWSTR lpszHelp,UINT uCommand,DWORD_PTR dwData)135 WinHelpW(HWND hWnd, LPCWSTR lpszHelp, UINT uCommand, DWORD_PTR dwData)
136 {
137     INT len;
138     LPSTR file;
139     BOOL ret = FALSE;
140 
141     if (!lpszHelp) return WinHelpA(hWnd, NULL, uCommand, dwData);
142 
143     len = WideCharToMultiByte(CP_ACP, 0, lpszHelp, -1, NULL, 0, NULL, NULL);
144     if ((file = HeapAlloc(GetProcessHeap(), 0, len))) {
145         WideCharToMultiByte(CP_ACP, 0, lpszHelp, -1, file, len, NULL, NULL);
146         ret = WinHelpA(hWnd, file, uCommand, dwData);
147         HeapFree(GetProcessHeap(), 0, file);
148     }
149     return ret;
150 }
151 
152