Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!tut.cis.ohio-state.edu!att!cbnewsk!ech From: ech@cbnewsk.ATT.COM (ned.horvath) Newsgroups: comp.sys.mac.programmer Subject: Re: Finding the size of the screen under Multifinder/Color QD Message-ID: <1808@cbnewsk.ATT.COM> Date: 10 Jan 90 22:13:55 GMT References: <10164@saturn.ucsc.edu> Organization: AT&T Bell Laboratories Lines: 57 From article <10164@saturn.ucsc.edu>, by sirkm@ssyx.ucsc.edu (Greg Anderson): > [quoted references to invalid screenbits.bounds deleted] > I know it's illegal to call InitGraf() from within XCMD's, but can I > call it from within a DA? It seems like I would have the same problems > you experienced. > > If I cannot call InitGraf() from within my DA, then how can I find the > size of the screen? >>Can anyone tell me, is there a better way to get at global variables >>such as screenBits from within an XCMD? > Sort of -- make callbacks to HyperCard. This won't always get you what you > want, but it can often be very helpful... Assuming that the A5 you "inherit" is valid, and that InitGraf has been called by your host application (which had pretty well ALWAYS be true!), there are a couple of answers. 1. GrafPort myPort; OpenPort (&myPort);...your code here...ClosePort(&myPort); This gives you access to some of the variables you crave. 2. More generally, the low memory global CurrentA5 (long integer at 0x904) contains the address of the address of thePort (the last quickdraw variable) for the current application. So the following code snippet will get you a way to PEEK (never, never, NEVER poke!) at the QD globals: struct qdvars { /* note that the order is the reverse */ long randSeed; /* of that on IM I-204 */ BitMap screenBits; Cursor arror; Pattern dkGray; Pattern ltGray; Pattern gray; Pattern black; Pattern white; GrafPtr thePort; } *myGlobals; myGlobals = (struct qdvars *) ( (**(long**)0x904) - /* address of thePort */ (long)&((struct qdvars *)0)->thePort /* offset of thePort */ ); I presume that if you're not using C you can figure out how to translate that nasty stuff into your own argot. The ugly part with 0x904 gets the address of thePort; the even more bizarre second term evaluates to a constant (at compile time) which is the offset of thePort in the full set of Quickdraw globals. You can now reference myGlobals->screenBits.bounds, for example. The second example works whenever the host application has called InitGraf(), even at interrupt time; most APPLs call InitGraf within micro seconds after launch, so you should be safe. =Ned Horvath=