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

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!mcsun!ub4b!info-sparc1.info.ucl.ac.be!NewsWatcher
  3. From: Meessen@slig.ucl.ac.be  (Christophe Meessen)
  4. Subject: Re: Q: DrawString only draws 8 characters of my string
  5. Message-ID: <Meessen-210792094221@130.104.58.6>
  6. Followup-To: comp.sys.mac.programmer
  7. Sender: news@info.ucl.ac.be (News Administrator)
  8. Nntp-Posting-Host: 130.104.58.6
  9. Organization: Universite Catholique de Louvain (Belgium)
  10. References: <Brp1GF.4Dt@news.cso.uiuc.edu> <NEERI.92Jul20230142@iis.ethz.ch>
  11. Date: Tue, 21 Jul 1992 08:04:11 GMT
  12. Lines: 89
  13.  
  14. In article <NEERI.92Jul20230142@iis.ethz.ch>, neeri@iis.ethz.ch (Matthias
  15. Neeracher) wrote:
  16. > In article <Brp1GF.4Dt@news.cso.uiuc.edu> rpoldrac@s.psych.uiuc.edu (Russ Poldrack) writes:
  17. > >I'm trying to print some strings using DrawString() and it refuses to
  18. > >print more than 8 characters of the string.  The variables are intact
  19. > >and the entire string is there is the watch window, but it doesn't
  20. > >come out on the screen.  The variables being printed are declared as
  21. > >char[20], so pointer checking is off to make it run.
  22. >            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  23. > Aargh! Did you ever work in the nuclear power industry? The compiler is your
  24. > *friend*. It was trying to *tell* you something.
  25. > >Does the
  26. > >variable HAVE to be an Str255?  Thanks.
  27. > It doesn't have to be a Str255. It does, however, have to be a *Pascal* string.
  28. > Pascal Strings start with a count byte, as opposed to C strings, which are
  29. > terminated with a 0 byte.
  30. > You have 2 alternatives:
  31. > - use drawstring instead of DrawString or
  32. > - Declare your variables as Str31 or Str255 and write your string literals with
  33. > a "\p" at the beginning, as in "\pHello World"
  34. > Personally, I prefer #2, but for small programs, #1 might be easier.
  35. ...
  36. > Matthias
  37.  
  38. I would suggest to avoid literal strings in a Macintosh program. Better use
  39. resource strings for constant strings. It's not that hard to implement.
  40.  
  41. To draw a C string I would then suggest to use 
  42. void DrawText( Ptr textBuf, short firstByte, short byteCount )
  43.  
  44. suppose your variable is 
  45.  
  46. char theString[20];
  47.  
  48. use 
  49.  
  50. DrawText( (Ptr)theString, 0, strlen( theString ) );
  51.  
  52.  
  53. To load and draw constant string from a 'STR ' resource. To access such a
  54. string you only need the resource ID.
  55.  
  56. // declare the string handle
  57. Handle theString;
  58.  
  59. // load the string from 'STR ' resource with ID kStringID
  60. theString = (Handle)GetResource( 'STR ', kStringID );
  61.  
  62. // remove handle from resource map
  63. DetachResource( theString );
  64.  
  65. // draw the resource
  66. DrawText( *theString, 0, GetHandleSize( theString ) );
  67.  
  68. // free's space used by the string
  69. DisposHandle( theString);
  70.  
  71.  
  72.  
  73. You may also load the string from a 'STR#' resource. Each resource may
  74. contain more than one resource. To access such a string you need the
  75. resource ID and the index number (1 - ... ) of the string.  
  76.  
  77. // declare the string buffer
  78. Str255 theString;
  79.  
  80. // load the string from 'STR#' resource with ID kStringID and index
  81. kStringIdx
  82. GetIndString( &theString, kStringID, kStringIdx );
  83.  
  84. // draw the resource
  85. DrawString( theString );
  86.  
  87. equivalent to
  88.  
  89. DrawText( theString + 1, 0, theString[0] );
  90.  
  91.  
  92. Bien cordialement,
  93.  
  94.                            Christophe MEESSEN
  95.