[USER32]
[reactos.git] / reactos / dll / win32 / user32 / misc / winhelp.c
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: lib/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 /* INCLUDES ******************************************************************/
29
30 #include <user32.h>
31
32 #include <wine/debug.h>
33
34 /* WinHelp internal structure */
35 typedef struct
36 {
37 WORD size;
38 WORD command;
39 LONG data;
40 LONG reserved;
41 WORD ofsFilename;
42 WORD ofsData;
43 } WINHELP,*LPWINHELP;
44
45
46 /* FUNCTIONS *****************************************************************/
47
48 /*
49 * @unimplemented
50 */
51 BOOL
52 WINAPI
53 WinHelpA(HWND hWnd, LPCSTR lpszHelp, UINT uCommand, DWORD_PTR dwData)
54 {
55 static WORD WM_WINHELP = 0;
56 HWND hDest;
57 LPWINHELP lpwh;
58 HGLOBAL hwh;
59 int size,dsize,nlen;
60
61 if (!WM_WINHELP) {
62 WM_WINHELP = RegisterWindowMessageA("WM_WINHELP");
63 if (!WM_WINHELP)
64 return FALSE;
65 }
66
67 hDest = FindWindowA("MS_WINHELP", NULL);
68 if (!hDest) {
69 if (uCommand == HELP_QUIT) return TRUE;
70 if (WinExec("winhlp32.exe -x", SW_SHOWNORMAL) < 32) {
71 //ERR("can't start winhlp32.exe -x ?\n");
72 return FALSE;
73 }
74 if (!(hDest = FindWindowA("MS_WINHELP", NULL))) {
75 //FIXME("did not find MS_WINHELP (FindWindow() failed, maybe global window handling still unimplemented)\n");
76 return FALSE;
77 }
78 }
79 switch (uCommand) {
80 case HELP_CONTEXT:
81 case HELP_SETCONTENTS:
82 case HELP_CONTENTS:
83 case HELP_CONTEXTPOPUP:
84 case HELP_FORCEFILE:
85 case HELP_HELPONHELP:
86 case HELP_FINDER:
87 case HELP_QUIT:
88 dsize=0;
89 break;
90 case HELP_KEY:
91 case HELP_PARTIALKEY:
92 case HELP_COMMAND:
93 dsize = dwData ? strlen( (LPSTR)dwData )+1: 0;
94 break;
95 case HELP_MULTIKEY:
96 dsize = ((LPMULTIKEYHELPA)dwData)->mkSize;
97 break;
98 case HELP_SETWINPOS:
99 dsize = ((LPHELPWININFOA)dwData)->wStructSize;
100 break;
101 default:
102 //FIXME("Unknown help command %d\n",uCommand);
103 return FALSE;
104 }
105 if (lpszHelp)
106 nlen = strlen(lpszHelp)+1;
107 else
108 nlen = 0;
109 size = sizeof(WINHELP) + nlen + dsize;
110 hwh = GlobalAlloc(0,size);
111 if (hwh == NULL)
112 return FALSE;
113 lpwh = GlobalLock(hwh);
114 lpwh->size = size;
115 lpwh->command = uCommand;
116 lpwh->data = dwData;
117 if (nlen) {
118 strcpy(((char*)lpwh) + sizeof(WINHELP), lpszHelp);
119 lpwh->ofsFilename = sizeof(WINHELP);
120 } else {
121 lpwh->ofsFilename = 0;
122 }
123 if (dsize) {
124 memcpy(((char*)lpwh)+sizeof(WINHELP)+nlen,(LPSTR)dwData,dsize);
125 lpwh->ofsData = sizeof(WINHELP)+nlen;
126 } else {
127 lpwh->ofsData = 0;
128 }
129 GlobalUnlock(hwh);
130 return SendMessageA(hDest, WM_WINHELP, (WPARAM)hWnd, (LPARAM)hwh);
131 }
132
133
134 /*
135 * @unimplemented
136 */
137 BOOL
138 WINAPI
139 WinHelpW(HWND hWnd, LPCWSTR lpszHelp, UINT uCommand, DWORD_PTR dwData)
140 {
141 INT len;
142 LPSTR file;
143 BOOL ret = FALSE;
144
145 if (!lpszHelp) return WinHelpA(hWnd, NULL, uCommand, dwData);
146
147 len = WideCharToMultiByte(CP_ACP, 0, lpszHelp, -1, NULL, 0, NULL, NULL);
148 if ((file = HeapAlloc(GetProcessHeap(), 0, len))) {
149 WideCharToMultiByte(CP_ACP, 0, lpszHelp, -1, file, len, NULL, NULL);
150 ret = WinHelpA(hWnd, file, uCommand, dwData);
151 HeapFree(GetProcessHeap(), 0, file);
152 }
153 return ret;
154 }
155