home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!mcsun!ub4b!info-sparc1.info.ucl.ac.be!NewsWatcher
- From: Meessen@slig.ucl.ac.be (Christophe Meessen)
- Subject: Re: Q: DrawString only draws 8 characters of my string
- Message-ID: <Meessen-210792094221@130.104.58.6>
- Followup-To: comp.sys.mac.programmer
- Sender: news@info.ucl.ac.be (News Administrator)
- Nntp-Posting-Host: 130.104.58.6
- Organization: Universite Catholique de Louvain (Belgium)
- References: <Brp1GF.4Dt@news.cso.uiuc.edu> <NEERI.92Jul20230142@iis.ethz.ch>
- Date: Tue, 21 Jul 1992 08:04:11 GMT
- Lines: 89
-
- 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:
- > >I'm trying to print some strings using DrawString() and it refuses to
- > >print more than 8 characters of the string. The variables are intact
- > >and the entire string is there is the watch window, but it doesn't
- > >come out on the screen. The variables being printed are declared as
- > >char[20], so pointer checking is off to make it run.
- > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- >
- > Aargh! Did you ever work in the nuclear power industry? The compiler is your
- > *friend*. It was trying to *tell* you something.
- >
- > >Does the
- > >variable HAVE to be an Str255? Thanks.
- >
- > It doesn't have to be a Str255. It does, however, have to be a *Pascal* string.
- > Pascal Strings start with a count byte, as opposed to C strings, which are
- > terminated with a 0 byte.
- >
- > 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.
- >
- ...
- > Matthias
-
- I would suggest to avoid literal strings in a Macintosh program. Better use
- resource strings for constant strings. It's not that hard to implement.
-
- To draw a C string I would then suggest to use
- void DrawText( Ptr textBuf, short firstByte, short byteCount )
-
- suppose your variable is
-
- char theString[20];
-
- use
-
- DrawText( (Ptr)theString, 0, strlen( theString ) );
-
-
- To load and draw constant string from a 'STR ' resource. To access such a
- string you only need the resource ID.
-
- // declare the string handle
- Handle theString;
-
- // load the string from 'STR ' resource with ID kStringID
- theString = (Handle)GetResource( 'STR ', kStringID );
-
- // remove handle from resource map
- DetachResource( theString );
-
- // draw the resource
- DrawText( *theString, 0, GetHandleSize( theString ) );
-
- // free's space used by the string
- DisposHandle( theString);
-
-
-
- You may also load the string from a 'STR#' resource. Each resource may
- contain more than one resource. To access such a string you need the
- resource ID and the index number (1 - ... ) of the string.
-
- // declare the string buffer
- Str255 theString;
-
- // load the string from 'STR#' resource with ID kStringID and index
- kStringIdx
- GetIndString( &theString, kStringID, kStringIdx );
-
- // draw the resource
- DrawString( theString );
-
- equivalent to
-
- DrawText( theString + 1, 0, theString[0] );
-
-
- Bien cordialement,
-
- Christophe MEESSEN
-