home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!darwin.sura.net!jvnc.net!yale.edu!ira.uka.de!chx400!bernina!bernina!neeri
- From: neeri@iis.ethz.ch (Matthias Neeracher)
- Subject: Re: Q: DrawString only draws 8 characters of my string
- In-Reply-To: Meessen@slig.ucl.ac.be's message of Tue, 21 Jul 1992 08:04:11 GMT
- Message-ID: <NEERI.92Jul21135202@iis.ethz.ch>
- Followup-To: comp.sys.mac.programmer
- Sender: news@bernina.ethz.ch (USENET News System)
- Organization: Integrated Systems Laboratory, ETH, Zurich
- References: <Brp1GF.4Dt@news.cso.uiuc.edu> <NEERI.92Jul20230142@iis.ethz.ch>
- <Meessen-210792094221@130.104.58.6>
- Date: Tue, 21 Jul 1992 12:52:02 GMT
- Lines: 59
-
- In article <Meessen-210792094221@130.104.58.6> Meessen@slig.ucl.ac.be (Christophe Meessen) writes:
- >In article <NEERI.92Jul20230142@iis.ethz.ch>, neeri@iis.ethz.ch (Matthias
- >Neeracher) wrote:
- >>
- >> In article <Brp1GF.4Dt@news.cso.uiuc.edu> rpoldrac@s.psych.uiuc.edu (Russ Poldrack) writes:
- >> You have 2 alternatives:
- >>
- >> - use drawstring instead of DrawString or
- >> - Declare your variables as Str31 or Str255 and write your string literals with
- >> a "\p" at the beginning, as in "\pHello World"
- >>
- >> Personally, I prefer #2, but for small programs, #1 might be easier.
- >
- >I would suggest to avoid literal strings in a Macintosh program.
-
- Agreed.
-
- >To load and draw constant string from a 'STR ' resource. To access such a
- >string you only need the resource ID.
-
- But your code is going to lead to some trouble:
-
- >// declare the string handle
- >Handle theString;
-
- Should be "StringHandle theString;"
-
- >// load the string from 'STR ' resource with ID kStringID
- >theString = (Handle)GetResource( 'STR ', kStringID );
-
- "(StringHandle)"
-
- >// remove handle from resource map
- >DetachResource( theString );
-
- This line is unnecessary.
-
- >// draw the resource
- >DrawText( *theString, 0, GetHandleSize( theString ) );
-
- And here the *real* trouble begins:
-
- - 'STR ' resources are stored as handles to *Pascal* strings, which means
- you should use "DrawString(*theString);"
- - While it is unnecessary to *detach* the resource, it is *essential* to lock
- it with "HLock((Handle) theString);" before drawing.
-
- >// free's space used by the string
- >DisposHandle( theString);
-
- or, if you omit the DetachResource, "ReleaseResource((Handle) theString);"
-
- Matthias
-
- -----
- Matthias Neeracher neeri@iis.ethz.ch
- "No, what he didn't like about heroes was that they were usually
- suicidally gloomy when sober and homicidally insane when drunk."
- -- Terry Pratchett, _The Colour of Magic_
-