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