[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Resources
- To: greg@eos.arc.nasa.gov
- Subject: Resources
- From: cornell@unix1.cs.umass.edu (Matthew Cornell)
- Date: Fri, 31 May 91 17:07:34 EDT
- Cc: info-mcl@cambridge.apple.com
- In-reply-to: Greg Pisanich's message of Fri, 31 May 91 11:52:21 -0700 <9105311852.AA13123@eos.arc.nasa.gov>
To work with resources you need to read the chapter on them in Inside
Macintosh.
The usual procedure is to save your graphic as a PICT resource (from
Canvas or MacDraw), use the OpenResFile trap to make the PICTs
available, use the GetResource, GetIndResource, or GetNamedResource
trap to get a mac handle to the pict, then do DRAW-PICTURE, etc. using
the handle.
I posted a 1.3.2 file called resources.lisp that has lisp-level
routines for handling resources. I think there have been other
postings of PICT-specific things like pict dialog items and reading
PICT files.
I haven't converted resources.lisp to 2.0b1 but its improved trap
interface makes trap hacking much easier (thanks to the Apple team).
Here is simple code to open, close, and maintain resource files:
? (defvar *open-resource-files* ())
*OPEN-RESOURCE-FILES*
? (let* ((file-name (choose-file-dialog))
(result (with-pstrs ((str (namestring file-name)))
(#_openResFile str))))
(if (minusp result)
(warn "Error (~S) opening ~S." result file-name)
(push result *open-resource-files*)))
(2352)
? (let ((refnum (first *open-resource-files*)))
(setf *open-resource-files* (delete refnum *open-resource-files*))
(#_closeResFile refnum))
NIL
? *open-resource-files*
NIL
?
Here is code that draws all PICTs in the front window's upperleft hand
corner. (I don't think you need to call #_DisposHandle on each
resource, and I think you should call #_LoadResource in case the
resource has been purged. Can someone correct me on this?).
(dotimes (index (#_CountResources "PICT"))
(draw-picture (first (windows)) (#_GetIndResource "PICT" index))
(sleep 1))
matt