2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
15 #include <afs/param.h>
23 #include <WINNT\talocale.h>
30 This function takes three main arguements, the stringtable ID, the button types
31 to be displayed (default = MB_OK) and the help table reference (default = 0, no
32 help) and then a variable amount of arguements. The variable list does not need
33 a special ending flag/character/number. The list is read only as needed, which
34 is defined by the string table and the presence of any "%X" characters, where X
35 is one of the printf format types. The order of the variable list MUST
36 correspond to the order of types in the string table entry. If the string table
37 calls for INT INT UINT CHAR* DOUBLE, then the arguement list had better be INT
38 INT UINT CHAR* DOUBLE or else there will be serious problems (stack will be
39 misread, general protection faults, garbage output, and other errors).
41 This function takes the arguements passed in the list and inserts them by
42 parsing and pszcut/pszpaste the string table entry to add all the arguements passed
43 in. This allows for any generic message to be created.
47 %x,X = Hex (takes an integer arguement, pszconverts it)
54 %a = String Table Ref. (UINT)
55 %o = CString object (prints the string of the object)
56 default = prints out string so far, with error message attached at place of error.
58 Return type is the button pressed in the message box.
62 UINT
ShowMessageBox (UINT Id
, UINT Button
, UINT Help
, ...) {
74 pszconvert
= new TCHAR
[255];
75 va_start(params
, Help
);
76 LoadString (temp
, Id
);
77 pszstring
= temp
.GetBuffer(512);
78 _tcscpy(pszstring
,pszstring
);
80 // Look and see - is there a need to insert chars (95% of the time, there won't)
81 if (!_tcsstr(pszstring
, _T("%"))) {
83 return AfxMessageBox(pszstring
, Button
, Help
);
86 x
= _tcscspn(pszstring
, _T("%"));
87 pszdone
= new TCHAR
[512];
88 pszcut
= new TCHAR
[512];
89 pszpaste
= new TCHAR
[512];
90 _tcscpy(pszcut
, &pszstring
[x
+2]);
91 _tcsncpy(pszpaste
, pszstring
, x
);
92 pszpaste
[x
] = _T('\0');
93 chread
= pszstring
[x
+1];
101 int anint
= va_arg(params
, int);
102 _itot( anint
, pszconvert
, 10);
107 UINT anuint
= va_arg(params
, UINT
);
108 _itot( anuint
, pszconvert
, 10);
115 int ahex
= va_arg(params
, int);
116 _itot( ahex
, pszconvert
, 16);
123 double adbl
= va_arg(params
, double);
124 _stprintf(pszconvert
, _T("%g"), adbl
);
129 TCHAR
*pStr
= va_arg(params
, TCHAR
*);
130 ASSERT(_tcslen(pStr
) <= 255);
131 _tcscpy(pszconvert
, pStr
);
136 chread
= pszdone
[x
+2];
140 long int alhex
= va_arg(params
, long int);
141 _ltot(alhex
, pszconvert
, 16);
142 _tcscpy(pszcut
, &pszcut
[1]);
148 long int along
= va_arg(params
, long int);
149 _ltot( along
, pszconvert
, 10);
150 // For the L, there will be one character after it,
151 // so move ahead another letter
152 _tcscpy(pszcut
, &pszcut
[1]);
161 int letter
= va_arg(params
, int);
162 pszconvert
[0] = (TCHAR
)letter
;
163 pszconvert
[1] = '\0';
170 UINT ls
= va_arg(params
, UINT
);
171 LoadString (zeta
, ls
);
172 lsc
= zeta
.GetBuffer(255);
173 _tcscpy(pszconvert
, lsc
);
174 zeta
.ReleaseBuffer();
179 CString get
= va_arg(params
, CString
);
180 TCHAR
* ex
= get
.GetBuffer(255);
181 _tcscpy(pszconvert
,ex
);
187 _tcscpy(pszconvert
, _T(" Could not load message. Invalid %type in string table entry. "));
189 pszdone
= new TCHAR
[_tcslen(pszpaste
)+_tcslen(pszcut
)+_tcslen(pszconvert
)+5];
190 _tcscpy(pszdone
, pszpaste
);
191 _tcscat(pszdone
, pszconvert
);
192 _tcscat(pszdone
, pszcut
);
193 AfxMessageBox(pszdone
, Button
, Help
);
204 pszdone
= new TCHAR
[_tcslen(pszpaste
)+_tcslen(pszcut
)+_tcslen(pszconvert
)+5];
205 _tcscpy(pszdone
, pszpaste
);
206 _tcscat(pszdone
, pszconvert
);
207 _tcscat(pszdone
, pszcut
);
208 // Now pszdone holds the entire message.
209 // Check to see if there are more insertions to be made or not
211 if (!_tcsstr(pszdone
, _T("%"))) {
212 UINT rt_type
= AfxMessageBox(pszdone
, Button
, Help
);
220 // there are more insertions to make, prepare the strings to use.
221 x
= _tcscspn(pszdone
, _T("%"));
222 _tcscpy(pszcut
, &pszdone
[x
+2]);
223 _tcsncpy(pszpaste
, pszdone
, x
);
224 pszpaste
[x
] = _T('\0');
225 chread
= pszdone
[x
+1];
233 CString
GetMessageString(UINT Id
, ...)
246 pszconvert
= new TCHAR
[255];
247 va_start(params
, Id
);
248 LoadString (temp
, Id
);
249 pszstring
= temp
.GetBuffer(512);
250 _tcscpy(pszconvert
,pszstring
);
251 temp
.ReleaseBuffer();
253 // Look and see - is there a need to insert chars (95% of the time, there won't)
254 if (!_tcsstr(pszstring
, _T("%"))) {
260 x
= _tcscspn(pszstring
, _T("%"));
261 pszdone
= new TCHAR
[512];
262 pszcut
= new TCHAR
[512];
263 pszpaste
= new TCHAR
[512];
264 _tcscpy(pszcut
, &pszstring
[x
+2]);
265 _tcsncpy(pszpaste
, pszstring
, x
);
266 pszpaste
[x
] = _T('\0');
267 chread
= pszstring
[x
+1];
275 int anint
= va_arg(params
, int);
276 _itot( anint
, pszconvert
, 10);
281 UINT anuint
= va_arg(params
, UINT
);
282 _itot( anuint
, pszconvert
, 10);
289 int ahex
= va_arg(params
, int);
290 _itot( ahex
, pszconvert
, 16);
297 double adbl
= va_arg(params
, double);
298 _stprintf(pszconvert
, _T("%g"), adbl
);
303 TCHAR
*pStr
= va_arg(params
, TCHAR
*);
304 ASSERT(_tcslen(pStr
) <= 255);
305 _tcscpy(pszconvert
, pStr
);
310 chread
= pszdone
[x
+2];
314 long int alhex
= va_arg(params
, long int);
315 _ltot(alhex
, pszconvert
, 16);
316 _tcscpy(pszcut
, &pszcut
[1]);
322 long int along
= va_arg(params
, long int);
323 _ltot( along
, pszconvert
, 10);
324 // For the L, there will be one character after it,
325 // so move ahead another letter
326 _tcscpy(pszcut
, &pszcut
[1]);
335 int letter
= va_arg(params
, int);
336 pszconvert
[0] = (TCHAR
)letter
;
337 pszconvert
[1] = _T('\0');
344 UINT ls
= va_arg(params
, UINT
);
345 LoadString (zeta
, ls
);
346 lsc
= zeta
.GetBuffer(255);
347 _tcscpy(pszconvert
, lsc
);
348 zeta
.ReleaseBuffer();
353 CString get
= va_arg(params
, CString
);
354 TCHAR
* ex
= get
.GetBuffer(255);
355 _tcscpy(pszconvert
,ex
);
361 _tcscpy(pszconvert
, _T(" Could not load message. Invalid %type in string table entry. "));
363 pszdone
= new TCHAR
[_tcslen(pszpaste
)+_tcslen(pszcut
)+_tcslen(pszconvert
)+5];
364 _tcscpy(pszdone
, pszpaste
);
365 _tcscat(pszdone
, pszconvert
);
366 _tcscat(pszdone
, pszcut
);
378 pszdone
= new TCHAR
[_tcslen(pszpaste
)+_tcslen(pszcut
)+_tcslen(pszconvert
)+5];
379 _tcscpy(pszdone
, pszpaste
);
380 _tcscat(pszdone
, pszconvert
);
381 _tcscat(pszdone
, pszcut
);
382 // Now pszdone holds the entire message.
383 // Check to see if there are more insertions to be made or not
385 if (!_tcsstr(pszdone
, _T("%"))) {
394 // there are more insertions to make, prepare the strings to use.
395 x
= _tcscspn(pszdone
, _T("%"));
396 _tcscpy(pszcut
, &pszdone
[x
+2]);
397 _tcsncpy(pszpaste
, pszdone
, x
);
398 pszpaste
[x
] = _T('\0');
399 chread
= pszdone
[x
+1];
406 void LoadString (CString
&Str
, UINT id
)
408 TCHAR szString
[ 256 ];
409 GetString (szString
, id
);
411 CString
wstr(szString
);