jxf@phobos.cis.ksu.edu (Jerry Frain) (01/24/90)
[ Jeez, I can't believe that this is giving me so much trouble... ] I am writing a program (using THINK C 4.0, if anyone cares), which has two windows open simultaneously. Both windows are zoomDocProcs, so I have a set of scroll bars for both. What is the easiest way to know which scroll bars to size when the user resizes a window? I know that I *could* find out which window it is, and then figure out which ControlHandles I used to first set up the windows, but I want to make a generic "UpdateScrollBars" function, passing only a WindowPtr (or WindowPeek) variable to it. I originally thought that I could traverse the list of controls that are attached to the controlList of the WindowRecord, but I can't see an easy way to identify which controls are scroll bars (once I do that, I would look at the contrlRect to determine right or bottom scroll bar). Does the ControlHandle tell which ControlDefProc ID I specified at creation? Any help would be appreciated, in a big way. Thanks in advance, --Jerry -- Jerry Frain -- Professional Student Kansas State University Internet: jxf@phobos.cis.ksu.edu Dept of Computing & Information Sciences BITNET: MUSTANG@KSUVM Manhattan, Kansas UUCP: ...!{rutgers|textbell}!ksuvax1!phobos.cis.ksu.edu!jxf
6500stom@hub.UUCP (David Stoms) (01/24/90)
From article <1990Jan23.190524.3693@deimos.cis.ksu.edu>, by jxf@phobos.cis.ksu.edu (Jerry Frain): > I originally thought that I could traverse the list of controls that > are attached to the controlList of the WindowRecord, but I can't see > an easy way to identify which controls are scroll bars (once I do that, > I would look at the contrlRect to determine right or bottom scroll bar). The slick way to do this is to allocate a handle in refCon of the WindowRecord. You can then store the handles to the scroll bars there. This is real easy is C and a little less easy in Pascal. Example: typedef struct { int windowID; /* maybe, maybe not */ ContorlHandle hScrollBar; ControlHandle vScrollBar; } MyWindowInfoRec, **MyWindowInfoHdl; Then: MyWindow->refCon = (long)MyWindowInfoHdl; > Does the ControlHandle tell which ControlDefProc ID I specified at > creation? Yes and no but mostly yes: the ControlDefProc field is a handle to the CDEF. You can do a GetResInfo on it if you have the urge to. / Josh Pritikin T The C++ programming language \ | Internet: 6500stom@ucsbuxa.ucsb.edu | is at worst, the second best | | AppleLink: Josh.P | for a given application. | \ GEnie: J.Pritikin ! But usually, it is the best. /
6600pete@hub.UUCP (Pete Gontier) (01/24/90)
From article <1990Jan23.190524.3693@deimos.cis.ksu.edu>, by jxf@phobos.cis.ksu.edu (Jerry Frain): > Does the ControlHandle tell which ControlDefProc ID I specified at > creation? I haven't heard anything to that effect anywhere. However, if you really want to do things this way, you could conceivably traverse the control list and compare the defProc field with GetResource on the scoll bar CDEF. However, this is kludgy for two reasons: Looking through the control list. I can't think of any specific reasons why this is bad other than the fact that most similar hacks eventually break. Looking directly in a data structure which is supposed to be maintained by the toolbox. It's probably best to go ahead and put a handle in the window's refCon field and store the handles to the scroll bars in it. Be sure to use SetWRefCon and GetWRefCon even though they are slower than looking in the record directly. Eventually people will start doing this as a standard practice and monstrosities like the auxilliary window list will cease to appear. "Obey the rules," says Officer MacFriendly. ------------------------------------------------------------------------------ Pete Gontier | InterNet: 6600pete@ucsbuxa.ucsb.edu, BitNet: 6600pete@ucsbuxa Editor, Macker | Online Macintosh Programming Journal; mail for subscription Hire this kid | Mac, DOS, C, Pascal, asm, excellent communication skills
lim@iris.ucdavis.edu (Lloyd Lim) (01/24/90)
In article <1990Jan23.190524.3693@deimos.cis.ksu.edu> jxf@phobos.cis.ksu.edu (Jerry Frain) writes: >I originally thought that I could traverse the list of controls that >are attached to the controlList of the WindowRecord, but I can't see >an easy way to identify which controls are scroll bars (once I do that, >I would look at the contrlRect to determine right or bottom scroll bar). Most programmers and object-oriented systems store and handle to some kind of data structure in the window's refCon. This is appropriate for complex applications. In my simpler programs I use a simpler method of identifying scrollbars. I store constants in the control refCons when they are created which let me identify horizontal and vertical scrollbars when going through the controlList. Actually, most of the time my applications are simple enough that I only have the scrollbars in the controlList and I can identify them by position in the controlList (ie - the first is the horizontal, the next is the vertical). I still need constants in the control refCons though in order to identify scrollbars in a scrollbar actionProc in a generic manner. +++ Lloyd Lim Internet: lim@iris.ucdavis.edu (128.120.57.20) Compuserve: 72647,660 US Mail: 146 Lysle Leach Hall, U.C. Davis, Davis, CA 95616