Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!dewey.soe.berkeley.edu!oster From: oster@dewey.soe.berkeley.edu (David Phillip Oster) Newsgroups: comp.sys.mac.programmer Subject: Re: How to use ParamText's Message-ID: <28403@ucbvax.BERKELEY.EDU> Date: 15 Mar 89 02:42:39 GMT References: <8079@csli.STANFORD.EDU> <2110@helios.ee.lbl.gov> Sender: usenet@ucbvax.BERKELEY.EDU Reply-To: oster@dewey.soe.berkeley.edu.UUCP (David Phillip Oster) Organization: School of Education, UC-Berkeley Lines: 47 In article <2110@helios.ee.lbl.gov> beard@ux3.lbl.gov (Patrick C Beard) writes: _>In article <8079@csli.STANFORD.EDU> wilson@csli.stanford.edu (Nathan Wilson) writes: _>> _>>I was working on being a good person and switching all the strings in _>>my code to calls to GetIndString when I came across the following _>>problem. Under some conditions I would like to title a window (not a _>>dialog or alert) that displays a PICT resource something like _>> _>> ID = in _>> _>>with the stuff in <> replaced with the appropriate info. Now it _>>occurred to me that the best way to generate this string would be to _>>store it as a parameterized string as per alerts, that is _>> _>>^0 ID = ^1 in ^2 _>> _> _>How about: _> Str255 title; _> String format; _> _> GetIndString(format, FORMAT_STRING_ID, 1); _> . _> . _> PtoCstr(format); _>sprintf(title,format, PtoCstr(resName), PtoCstr(resNumberStr),PtoCstr(resFile)); _> SetWTitle(window, CtoPstr(title)); or even better: #define PS(s) (int)(unsigned)(unsigned char)(s)[0], &(s)[1] Str255 title; sprintf(title, "%.*s ID = %.*s in %.*s", PS(resName), PS(rseNumberStr), PS(resFile)); CtoPstr(title); SetWTitle(window, title); That way, you aren't modifying the Str255s resName, resNumberStr, or resFile, so you don't have to worry about forgetting to turn them back into pascal strings. Note, that this clever trick uses code already built into sprintf to handle pascal strings directly. The only caveat is that the PS macro evaluates the argument twice, so it had better not have side effects. --- David Phillip Oster --"When we replace the mouse with a pen, Arpa: oster@dewey.soe.berkeley.edu --3 button mouse fans will need saxophone Uucp: {uwvax,decvax}!ucbvax!oster%dewey.soe.berkeley.edu --lessons." - Gasee