user32: Add wsprintfW %C tests.
[wine.git] / dlls / user32 / winhelp.c
blobc40b0fc8fcd400e8ace0be9d12c1a8b67d128968
1 /*
2 * Windows Help
4 * Copyright 1996 Martin von Loewis
5 * 2002 Eric Pouech
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
24 #include <stdlib.h>
25 #include <stdarg.h>
26 #include <stdio.h>
27 #include <string.h>
28 #ifdef HAVE_UNISTD_H
29 # include <unistd.h>
30 #endif
31 #include "wine/debug.h"
32 #include "windef.h"
33 #include "winbase.h"
34 #include "wingdi.h"
35 #include "winuser.h"
36 #include "winnls.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(win);
40 /* Wine doesn't use the way WinHelp API sends information in Windows, because:
41 * 1/ it's not consistent across Win9x, NT...
42 * 2/ NT implementation is not yet fully understood (and includes some shared
43 * memory mechanism)
44 * 3/ uses a dynamically allocated message number (WM_WINHELP), which
45 * obfuscates the code
47 * So we use (for now) the simple protocol:
48 * 1/ it's based on copy data
49 * 2/ we tag the message with a magic number, to make it a bit more robust
50 * (even if it's not 100% safe)
51 * 3/ data structure (WINHELP) has the same layout that the one used on Win95.
52 * This doesn't bring much, except not going to far away from real
53 * implementation.
55 * This means anyway that native winhelp.exe and winhlp32.exe cannot be
56 * called/manipulated from WinHelp API.
58 typedef struct
60 WORD size;
61 WORD command;
62 LONG data;
63 LONG reserved;
64 WORD ofsFilename;
65 WORD ofsData;
66 } WINHELP;
68 /* magic number for this message:
69 * aide means help is French ;-)
70 * SOS means ???
72 #define WINHELP_MAGIC 0xA1DE505
74 /**********************************************************************
75 * WinHelpA (USER32.@)
77 BOOL WINAPI WinHelpA( HWND hWnd, LPCSTR lpHelpFile, UINT wCommand, ULONG_PTR dwData )
79 COPYDATASTRUCT cds;
80 HWND hDest;
81 int size, dsize, nlen;
82 WINHELP* lpwh;
83 LRESULT ret;
85 hDest = FindWindowA("MS_WINHELP", NULL);
86 if (!hDest)
88 if (wCommand == HELP_QUIT) return TRUE;
89 if (WinExec("winhlp32.exe -x", SW_SHOWNORMAL) < 32)
91 ERR("can't start winhlp32.exe -x ?\n");
92 return FALSE;
94 if (!(hDest = FindWindowA("MS_WINHELP", NULL)))
96 FIXME("Did not find a MS_WINHELP Window\n");
97 return FALSE;
101 switch (wCommand)
103 case HELP_CONTEXT:
104 case HELP_SETCONTENTS:
105 case HELP_CONTENTS:
106 case HELP_CONTEXTPOPUP:
107 case HELP_FORCEFILE:
108 case HELP_HELPONHELP:
109 case HELP_FINDER:
110 case HELP_QUIT:
111 dsize = 0;
112 break;
113 case HELP_KEY:
114 case HELP_PARTIALKEY:
115 case HELP_COMMAND:
116 dsize = dwData ? strlen((LPSTR)dwData) + 1 : 0;
117 break;
118 case HELP_MULTIKEY:
119 dsize = ((LPMULTIKEYHELPA)dwData)->mkSize;
120 break;
121 case HELP_SETWINPOS:
122 dsize = ((LPHELPWININFOA)dwData)->wStructSize;
123 break;
124 default:
125 FIXME("Unknown help command %d\n", wCommand);
126 return FALSE;
128 if (lpHelpFile)
129 nlen = strlen(lpHelpFile) + 1;
130 else
131 nlen = 0;
132 size = sizeof(WINHELP) + nlen + dsize;
134 lpwh = HeapAlloc(GetProcessHeap(), 0, size);
135 if (!lpwh) return FALSE;
137 cds.dwData = WINHELP_MAGIC;
138 cds.cbData = size;
139 cds.lpData = (void*)lpwh;
141 lpwh->size = size;
142 lpwh->command = wCommand;
143 lpwh->data = dwData;
144 if (nlen)
146 strcpy(((char*)lpwh) + sizeof(WINHELP), lpHelpFile);
147 lpwh->ofsFilename = sizeof(WINHELP);
148 } else
149 lpwh->ofsFilename = 0;
150 if (dsize)
152 memcpy(((char*)lpwh) + sizeof(WINHELP) + nlen, (LPSTR)dwData, dsize);
153 lpwh->ofsData = sizeof(WINHELP) + nlen;
154 } else
155 lpwh->ofsData = 0;
156 TRACE("Sending[%u]: cmd=%u data=%08x fn=%s\n",
157 lpwh->size, lpwh->command, lpwh->data,
158 lpwh->ofsFilename ? (LPSTR)lpwh + lpwh->ofsFilename : "");
160 ret = SendMessageA(hDest, WM_COPYDATA, (WPARAM)hWnd, (LPARAM)&cds);
161 HeapFree(GetProcessHeap(), 0, lpwh);
162 return ret;
166 /**********************************************************************
167 * WinHelpW (USER32.@)
169 BOOL WINAPI WinHelpW( HWND hWnd, LPCWSTR helpFile, UINT command, ULONG_PTR dwData )
171 INT len;
172 LPSTR file;
173 BOOL ret = FALSE;
175 if (!helpFile) return WinHelpA( hWnd, NULL, command, dwData );
177 len = WideCharToMultiByte( CP_ACP, 0, helpFile, -1, NULL, 0, NULL, NULL );
178 if ((file = HeapAlloc( GetProcessHeap(), 0, len )))
180 WideCharToMultiByte( CP_ACP, 0, helpFile, -1, file, len, NULL, NULL );
181 ret = WinHelpA( hWnd, file, command, dwData );
182 HeapFree( GetProcessHeap(), 0, file );
184 return ret;