peterbak@microsoft.UUCP (Peter Bako) (05/12/89)
I have recently started to program the macs, and am experimenting with control bars. I have written a simple application, which opens a window up, puts a horizontal control bar in the middle, and will eventually display its current value above it. At the moment I am having problems with incrementing the value by one, if the user clicks on the down arrow. (problems means Bus Error!) Here is a scaled version of the code: case inContent: MousePoint = AnEvent.where; GlobalToLocal(&MousePoint); tempInt = FindControl(&MousePoint, myWindow, &whichControl); switch (tempInt) { case inThumb: TrackControl(whichControl, &MousePoint, nil); break; case inUpButton: case inDownButton: case inPageUp: case inPageDown: TrackControl(whichControl, &MousePoint, MoveScrollbar); break; } ok thats part of my control loop... Now the routime MoveScrollbar... MoveScrollbar(theControl, partCode) ControlHandle theControl; int partCode; { int amount, current; switch (partCode) { case inUpButton: /* I go thru case inUpButton, inDownButton, inPageUp, inPageDown. then my case statement is over, and the following three lines are left */ current = GetCtlValue(theControl); current += amount; /*amount set by switch */ SetCtlValue(theControl, current); } Ok now as far as I can tell, I always break while performing the SetCtlValue in the routine above. As far as I can tell everything is in the right place, yet each time I click either of the arrows I crash. Any suggestions? Peter Bako PS. I try to read this group, but I dont always get a chance to, so please send me mail....
ksitze@nmsu.edu (Kevin Sitze) (05/16/89)
Relatively simple... Your call to FindControl: tempInt = FindControl(&MousePoint, myWindow, &whichControl); Should be tempInt = FindControl(MousePoint, myWindow, &whichControl); and accordingly the calls to TrackControl should be: For Thumb: TrackControl(whichControl, MousePoint, nil); For rest: TrackControl(whichControl, MousePoint, MoveScrollbar); A point is 4 bytes long and should be passed directly. A pointer to the point will give the wrong value. Finally, the reason everything blows up in your face: You have to tell C that the routine is expected to be called from the toolbox. E.g. Pascal compatable: pascal MoveScrollbar(theControl, partCode) ControlHandle theControl; int partCode; { } Have fun!! -Kelesi -- ------------------------------------+------------------------------- From the Macintosh of: Kevin Sitze | Disclamer: Who the heck needs | a disclamer? After all, Dan EMail: ksitze%NMSU.edu | Quayle doesn't. SMail: 601 S. Melendres +------------------------------- Las Cruces, NM 88005 | "We have the answers, the ------------------------------------+ trouble lies in finding the "The difference between intelligence| questions..." and stupidity is that intelligence | "The information is there, has a limit." - anonymous | finding it is another story." The dolt confuses you -- more -- | - Any consultant ------------------------------------+-------------------------------