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
11 #include <afs/param.h>
26 This function takes three main arguements, the stringtable ID, the button types
27 to be displayed (default = MB_OK) and the help table reference (default = 0, no
28 help) and then a variable amount of arguements. The variable list does not need
29 a special ending flag/character/number. The list is read only as needed, which
30 is defined by the string table and the presence of any "%X" characters, where X
31 is one of the printf format types. The order of the variable list MUST
32 correspond to the order of types in the string table entry. If the string table
33 calls for INT INT UINT CHAR* DOUBLE, then the arguement list had better be INT
34 INT UINT CHAR* DOUBLE or else there will be serious problems (stack will be
35 misread, general protection faults, garbage output, and other errors).
37 This function takes the arguements passed in the list and inserts them by
38 parsing and pszcut/pszpaste the string table entry to add all the arguements passed
39 in. This allows for any generic message to be created.
43 %x,X = Hex (takes an integer arguement, pszconverts it)
50 %a = String Table Ref. (UINT)
51 %o = CString object (prints the string of the object)
52 default = prints out string so far, with error message attached at place of error.
54 Return type is the button pressed in the message box.
58 UINT ShowMessageBox (UINT Id, UINT Button, UINT Help, ...) {
74 pszconvert = new char[255];
75 va_start(params, Help);
76 LoadString (temp, Id);
77 pszstring = temp.GetBuffer(512);
78 strcpy(pszstring,pszstring);
80 // Look and see - is there a need to insert chars (95% of the time, there won't)
81 if (!strstr(pszstring, "%")) {
83 return AfxMessageBox(pszstring, Button, Help);
86 x = strcspn(pszstring, "%");
87 pszdone = new char[512];
88 pszcut = new char[512];
89 pszpaste = new char[512];
90 strcpy(pszcut, &pszstring[x+2]);
91 strncpy(pszpaste, pszstring, x);
93 chread = pszstring[x+1];
101 int anint = va_arg(params, int);
102 _itoa( anint, pszconvert, 10);
107 UINT anuint = va_arg(params, UINT);
108 _itoa( anuint, pszconvert, 10);
115 int ahex = va_arg(params, int);
116 _itoa( ahex, pszconvert, 16);
123 double adbl = va_arg(params, double);
124 _gcvt( adbl, 10, pszconvert);
129 char *pStr = va_arg(params, char*);
130 ASSERT(strlen(pStr) <= 255);
131 strcpy(pszconvert, pStr);
136 chread = pszdone[x+2];
140 long int alhex = va_arg(params, long int);
141 _ltoa(alhex, pszconvert, 16);
142 strcpy(pszcut, &pszcut[1]);
148 long int along = va_arg(params, long int);
149 _ltoa( along, pszconvert, 10);
150 // For the L, there will be one character after it,
151 // so move ahead another letter
152 strcpy(pszcut, &pszcut[1]);
161 int letter = va_arg(params, int);
162 pszconvert[0] = (char)letter;
163 pszconvert[1] = '\0';
170 UINT ls = va_arg(params, UINT);
171 LoadString (zeta, ls);
172 lsc = zeta.GetBuffer(255);
173 strcpy(pszconvert, lsc);
174 zeta.ReleaseBuffer();
179 CString get = va_arg(params, CString);
180 char* ex = get.GetBuffer(255);
181 strcpy(pszconvert,ex);
187 strcpy(pszconvert, " Could not load message. Invalid %type in string table entry. ");
189 pszdone = new char[strlen(pszpaste)+strlen(pszcut)+strlen(pszconvert)+5];
190 strcpy(pszdone, pszpaste);
191 strcat(pszdone, pszconvert);
192 strcat(pszdone, pszcut);
193 AfxMessageBox(pszdone, Button, Help);
204 pszdone = new char[strlen(pszpaste)+strlen(pszcut)+strlen(pszconvert)+5];
205 strcpy(pszdone, pszpaste);
206 strcat(pszdone, pszconvert);
207 strcat(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 (!strstr(pszdone, "%")) {
212 UINT rt_type = AfxMessageBox(pszdone, Button, Help);
220 // there are more insertions to make, prepare the strings to use.
221 x = strcspn(pszdone, "%");
222 strcpy(pszcut, &pszdone[x+2]);
223 strncpy(pszpaste, pszdone, x);
225 chread = pszdone[x+1];
233 CString GetMessageString(UINT Id, ...)
250 pszconvert = new char[255];
251 va_start(params, Id);
252 LoadString (temp, Id);
253 pszstring = temp.GetBuffer(512);
254 strcpy(pszconvert,pszstring);
255 temp.ReleaseBuffer();
257 // Look and see - is there a need to insert chars (95% of the time, there won't)
258 if (!strstr(pszstring, "%")) {
264 x = strcspn(pszstring, "%");
265 pszdone = new char[512];
266 pszcut = new char[512];
267 pszpaste = new char[512];
268 strcpy(pszcut, &pszstring[x+2]);
269 strncpy(pszpaste, pszstring, x);
271 chread = pszstring[x+1];
279 int anint = va_arg(params, int);
280 _itoa( anint, pszconvert, 10);
285 UINT anuint = va_arg(params, UINT);
286 _itoa( anuint, pszconvert, 10);
293 int ahex = va_arg(params, int);
294 _itoa( ahex, pszconvert, 16);
301 double adbl = va_arg(params, double);
302 _gcvt( adbl, 10, pszconvert);
307 char *pStr = va_arg(params, char*);
308 ASSERT(strlen(pStr) <= 255);
309 strcpy(pszconvert, pStr);
314 chread = pszdone[x+2];
318 long int alhex = va_arg(params, long int);
319 _ltoa(alhex, pszconvert, 16);
320 strcpy(pszcut, &pszcut[1]);
326 long int along = va_arg(params, long int);
327 _ltoa( along, pszconvert, 10);
328 // For the L, there will be one character after it,
329 // so move ahead another letter
330 strcpy(pszcut, &pszcut[1]);
339 int letter = va_arg(params, int);
340 pszconvert[0] = (char)letter;
341 pszconvert[1] = '\0';
348 UINT ls = va_arg(params, UINT);
349 LoadString (zeta, ls);
350 lsc = zeta.GetBuffer(255);
351 strcpy(pszconvert, lsc);
352 zeta.ReleaseBuffer();
357 CString get = va_arg(params, CString);
358 char* ex = get.GetBuffer(255);
359 strcpy(pszconvert,ex);
365 strcpy(pszconvert, " Could not load message. Invalid %type in string table entry. ");
367 pszdone = new char[strlen(pszpaste)+strlen(pszcut)+strlen(pszconvert)+5];
368 strcpy(pszdone, pszpaste);
369 strcat(pszdone, pszconvert);
370 strcat(pszdone, pszcut);
382 pszdone = new char[strlen(pszpaste)+strlen(pszcut)+strlen(pszconvert)+5];
383 strcpy(pszdone, pszpaste);
384 strcat(pszdone, pszconvert);
385 strcat(pszdone, pszcut);
386 // Now pszdone holds the entire message.
387 // Check to see if there are more insertions to be made or not
389 if (!strstr(pszdone, "%")) {
398 // there are more insertions to make, prepare the strings to use.
399 x = strcspn(pszdone, "%");
400 strcpy(pszcut, &pszdone[x+2]);
401 strncpy(pszpaste, pszdone, x);
403 chread = pszdone[x+1];
410 void LoadString (CString &Str, UINT id)
412 TCHAR szString[ 256 ];
413 GetString (szString, id);