d90f791d863e3722bb6fd6d15301956ca51e3bae
[reactos.git] / reactos / lib / 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 /* $Id: winhelp.c,v 1.6 2004/01/23 23:38:26 ekohl Exp $
20 *
21 * PROJECT: ReactOS user32.dll
22 * FILE: lib/user32/misc/winhelp.c
23 * PURPOSE: WinHelp
24 * PROGRAMMER: Robert Dickenson(robd@reactos.org)
25 * UPDATE HISTORY:
26 * 23-08-2002 RDD Created from wine sources
27 */
28
29 /* INCLUDES ******************************************************************/
30
31 #include <string.h>
32 #include <windows.h>
33 #include <user32.h>
34 #include <debug.h>
35
36 /* WinHelp internal structure */
37 typedef struct
38 {
39 WORD size;
40 WORD command;
41 LONG data;
42 LONG reserved;
43 WORD ofsFilename;
44 WORD ofsData;
45 } WINHELP,*LPWINHELP;
46
47
48 /* FUNCTIONS *****************************************************************/
49
50 /*
51 * @unimplemented
52 */
53 BOOL
54 STDCALL
55 WinHelpA(HWND hWnd, LPCSTR lpszHelp, UINT uCommand, DWORD dwData)
56 {
57 static WORD WM_WINHELP = 0;
58 HWND hDest;
59 LPWINHELP lpwh;
60 HGLOBAL hwh;
61 int size,dsize,nlen;
62
63 if (!WM_WINHELP) {
64 WM_WINHELP = RegisterWindowMessageA("WM_WINHELP");
65 if (!WM_WINHELP)
66 return FALSE;
67 }
68
69 hDest = FindWindowA("MS_WINHELP", NULL);
70 if (!hDest) {
71 if (uCommand == HELP_QUIT) return TRUE;
72 if (WinExec("winhlp32.exe -x", SW_SHOWNORMAL) < 32) {
73 //ERR("can't start winhlp32.exe -x ?\n");
74 return FALSE;
75 }
76 if (!(hDest = FindWindowA("MS_WINHELP", NULL))) {
77 //FIXME("did not find MS_WINHELP (FindWindow() failed, maybe global window handling still unimplemented)\n");
78 return FALSE;
79 }
80 }
81 switch (uCommand) {
82 case HELP_CONTEXT:
83 case HELP_SETCONTENTS:
84 case HELP_CONTENTS:
85 case HELP_CONTEXTPOPUP:
86 case HELP_FORCEFILE:
87 case HELP_HELPONHELP:
88 case HELP_FINDER:
89 case HELP_QUIT:
90 dsize=0;
91 break;
92 case HELP_KEY:
93 case HELP_PARTIALKEY:
94 case HELP_COMMAND:
95 dsize = dwData ? strlen( (LPSTR)dwData )+1: 0;
96 break;
97 case HELP_MULTIKEY:
98 dsize = ((LPMULTIKEYHELPA)dwData)->mkSize;
99 break;
100 case HELP_SETWINPOS:
101 dsize = ((LPHELPWININFOA)dwData)->wStructSize;
102 break;
103 default:
104 //FIXME("Unknown help command %d\n",uCommand);
105 return FALSE;
106 }
107 if (lpszHelp)
108 nlen = strlen(lpszHelp)+1;
109 else
110 nlen = 0;
111 size = sizeof(WINHELP) + nlen + dsize;
112 hwh = GlobalAlloc(0,size);
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 STDCALL
139 WinHelpW(HWND hWnd, LPCWSTR lpszHelp, UINT uCommand, DWORD 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