Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!apple!stevec From: stevec@Apple.COM (Steve Christensen) Newsgroups: comp.sys.mac.programmer Subject: Re: Getting resource template ID from Control Handle Message-ID: <54323@apple.Apple.COM> Date: 25 Jun 91 22:28:00 GMT References: <1991Jun25.150157.910@potomac.ads.com> Organization: Apple Computer Inc., Cupertino, CA Lines: 47 jtn@potomac.ads.com (John T. Nelson) writes: >[...that he has a dialog with a mixture of controls and text that the user > can click on. He's calling FindControl to figure out who got clicked on, > but it returns a ControlHandle and not a dialog item number. So, he > wonders how he can get the dialog item number of which control was hit...] Well, amazingly, the answer is in the Dialog Manager chapter of Inside Mac, volume I. If it's a modal dialog, do something like this: myDialog = GetNewDialog(...); do { ModalDialog(nil, &itemHit); // wait for user to click on an item switch (itemHit) { // do item-specific stuff case xxx: ... } } while (itemHit != OKitem); // wait until user clicks "OK" DisposDialog(myDialog); ModalDialog tracks simple buttons and checkboxes correctly (however you may have to handle scrollbars specially), and stuffs keypresses into the active edit item. You get control back every time a mouse clicks on an enabled dialog item, or a key is hit and there is an active edit item. If you have a non-modal dialog, you can do something similar to the above in your main event loop: if (GetNextEvent(EveryEvent, &myEvent)) { ... if (IsDialogEvent(&myEvent)) if (DialogSelect(&myEvent, &whichDialog, &itemHit)) { switch (itemHit) { case xxx: ... } } } ... In any case, pick up IM vol I and peruse the Dialog Manager chapter.. steve -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Steve Christensen Never hit a man with glasses. stevec@apple.com Hit him with a baseball bat.