home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / mac / programm / 12753 < prev    next >
Encoding:
Text File  |  1992-07-20  |  2.5 KB  |  74 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!darwin.sura.net!jvnc.net!yale.edu!ira.uka.de!chx400!bernina!bernina!neeri
  3. From: neeri@iis.ethz.ch (Matthias Neeracher)
  4. Subject: Re: Q: DrawString only draws 8 characters of my string
  5. In-Reply-To: Meessen@slig.ucl.ac.be's message of Tue, 21 Jul 1992 08:04:11 GMT
  6. Message-ID: <NEERI.92Jul21135202@iis.ethz.ch>
  7. Followup-To: comp.sys.mac.programmer
  8. Sender: news@bernina.ethz.ch (USENET News System)
  9. Organization: Integrated Systems Laboratory, ETH, Zurich
  10. References: <Brp1GF.4Dt@news.cso.uiuc.edu> <NEERI.92Jul20230142@iis.ethz.ch>
  11.     <Meessen-210792094221@130.104.58.6>
  12. Date: Tue, 21 Jul 1992 12:52:02 GMT
  13. Lines: 59
  14.  
  15. In article <Meessen-210792094221@130.104.58.6> Meessen@slig.ucl.ac.be  (Christophe Meessen) writes:
  16. >In article <NEERI.92Jul20230142@iis.ethz.ch>, neeri@iis.ethz.ch (Matthias
  17. >Neeracher) wrote:
  18. >> 
  19. >> In article <Brp1GF.4Dt@news.cso.uiuc.edu> rpoldrac@s.psych.uiuc.edu (Russ Poldrack) writes:
  20. >> You have 2 alternatives:
  21. >> 
  22. >> - use drawstring instead of DrawString or
  23. >> - Declare your variables as Str31 or Str255 and write your string literals with
  24. >> a "\p" at the beginning, as in "\pHello World"
  25. >> 
  26. >> Personally, I prefer #2, but for small programs, #1 might be easier.
  27. >
  28. >I would suggest to avoid literal strings in a Macintosh program.
  29.  
  30. Agreed.
  31.  
  32. >To load and draw constant string from a 'STR ' resource. To access such a
  33. >string you only need the resource ID.
  34.  
  35. But your code is going to lead to some trouble:
  36.  
  37. >// declare the string handle
  38. >Handle theString;
  39.  
  40. Should be "StringHandle theString;"
  41.  
  42. >// load the string from 'STR ' resource with ID kStringID
  43. >theString = (Handle)GetResource( 'STR ', kStringID );
  44.  
  45. "(StringHandle)"
  46.  
  47. >// remove handle from resource map
  48. >DetachResource( theString );
  49.  
  50. This line is unnecessary.
  51.  
  52. >// draw the resource
  53. >DrawText( *theString, 0, GetHandleSize( theString ) );
  54.  
  55. And here the *real* trouble begins:
  56.  
  57. - 'STR ' resources are stored as handles to *Pascal* strings, which means
  58.   you should use "DrawString(*theString);"
  59. - While it is unnecessary to *detach* the resource, it is *essential* to lock
  60.   it with "HLock((Handle) theString);" before drawing.
  61.  
  62. >// free's space used by the string
  63. >DisposHandle( theString);
  64.  
  65. or, if you omit the DetachResource, "ReleaseResource((Handle) theString);"
  66.  
  67. Matthias
  68.  
  69. -----
  70. Matthias Neeracher                                   neeri@iis.ethz.ch
  71.    "No, what he didn't like about heroes was that they were usually
  72.     suicidally gloomy when sober and homicidally insane when drunk."
  73.                           -- Terry Pratchett, _The Colour of Magic_
  74.