Newsgroups: comp.sys.apple2.programmer Path: news.weeg.uiowa.edu!news.uiowa.edu!hobbes.physics.uiowa.edu!newsrelay.iastate.edu!vixen.cso.uiuc.edu!howland.reston.ans.net!gatech!swrinde!sgiblab!sgigate.sgi.com!olivea!decwrl!decwrl!netcomsv!apple.com!gallant.apple.com!news From: David A Lyons Subject: Re: how to get info from Window Record? Sender: news@gallant.apple.com Message-ID: <1994Jan28.233506.15925@gallant.apple.com> X-Useragent: Version 1.1.3 Date: Fri, 28 Jan 1994 23:35:06 GMT X-Xxdate: Fri, 28 Jan 94 22:22:15 GMT References: <2iakd0$btp@TAMUTS.TAMU.EDU> Organization: Apple Computer, Inc. Lines: 65 In article <2iakd0$btp@TAMUTS.TAMU.EDU> Jason Perez, j0p7771@TAMUTS.TAMU.EDU writes: > [...] > CtlRecHndl frameControl,tmp; > unsigned long *ctlPtr; > GrafPortPtr bWinPtr; > > frameControl = (CtlRecHndl) NewHandle(sizeof(CtlRec),bannerID,0xC010,NULL); > tmp = (CtlRecHndl) NewHandle(sizeof(CtlRec),bannerID,0xC010,NULL); > bWinPtr = NewWindow(&bWin); > ctlPtr = (unsigned long *) (bWinPtr + 0x00CAL); /*offset to Handle */ > frameControl = (CtlRecHndl) (*ctlPtr); /*get Handle */ > /*now go through all controls */ > for (tmp = frameControl;tmp != 0L; tmp = (*tmp)->ctlNext) { > if ((long) ((*tmp)->ctlProc) == scrollProc) { > fprintf(fout,"found a scrollbar: %#x\n",(*tmp)->ctlFlag); > } > } > > this code just doesn't seem to work. sometimes it will not find the > end of the list, other times it will find only one control with a > ctlProc value of $05000000 (what's this?). any help much appreciated. Aha! It took me *three* tries to come up with the right answer on this one. First, I was going to tell you to use GetWControls (but that's for content controls, and there is no corresponding call for the frame control list). Second, I was going to tell you that you had to subtract 4 from the offsets on page 52-15 into the window record, because the window pointer points to the window's grafport at offset 4 (but you already have the right offset for wFrameCtls). So! The magic phrase is (bWinPtr + 0x00CAL), which is an example of C pointer arithmetic. If bWinPtr was a pointer to a one-byte value (char *), then your code would work. But bWinPtr is a GrafPort *, so it points to objects that are 170 bytes in size. So the compiler correctly tries to be helpful, and it computes a value that points $CA grafports higher in memory ($CA * 170 = 34340 bytes), which is not exactly what you wanted. You can instead do: ctlPtr = (unsigned long *) (((char *) bWinPtr) + 0xCA); Or, better yet, skip a couple steps and go straight from the window pointer to the frame control handle (and wind up with legible code): frameControl = ((WindRecPtr) bWinPtr)->wFrameCtrls; By the way, your frameControl=NewHandle and tmp=NewHandle statements serve no purpose (except to allocate memory that you will never use). Those lines can simply go away. By the other way, $05000000 is not a valid ctlProc; it's just garbage you stumbled across by traversing random memory as if it were a linked list of control records (you probably saw other values too, but this one looked close to what you were searching for). Dave Lyons, dlyons@apple.com Mr Tangent My opinions are my own, not Apple's.