Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!apple!apple.com!leahy3 From: leahy3@apple.com (Frank Leahy) Newsgroups: comp.sys.mac.programmer Subject: Re: Implementing a Talking Menu Message-ID: <1190@internal.Apple.COM> Date: 5 Apr 89 20:31:38 GMT References: <3937@bgsuvax.UUCP> Sender: usenet@Apple.COM Organization: Apple Computer, Inc. Lines: 56 In article <3937@bgsuvax.UUCP> maner@bgsuvax.UUCP (Walter Maner) writes: > "We are working on a desk accessory that will speak the menu choice on a > mouse event. I would like to know how to get the English text of the menu > and the menu choice (whichever the cursor was over) on mouseDOWN. There seems to be enough interest in this question that I thought I'd post my answer to the net. The global MenuDisable ($B54) along with a MenuHook does what you want. MenuDisable was originally designed to allow Help systems to determine which item the user had chosen, even if the item was disabled (hence the name). After MenuSelect returns 0,0, you can call MenuDisable to see if 1) the mouse was released outside of the menu and menu bar (MenuDisable=0) 2) the mouse was released in the menu bar (hi word of MenuDisable <> 0) 3) a disabled item had been chosen (both hi and lo words of MenuDisable <> 0) The standard MDEF (supplied by Apple) continuously sets MenuDisable while the menu is down. You can install a MenuHook (very easy to do) that looks at the value of MenuDisable, call GetMHandle(hi word of MenuDisable) to get the menu handle (if <> 0), then GetItem(lo word of MenuDisable) to get the item text (if <> 0). (You may also want to look at whether the item is disabled, and if so speak the item in a different voice). If you are doing this for your own program, and it has all text items, you're ok. Problems occur if you are trying to make this work with either custom MDEF's, e.g. a palette, or with hierarchical menus. Custom MDEF's may not set MenuDisable, and many do not have item text defined for each item in the palette. If the custom MDEF does set MenuDisable, you could use ResEdit to enter text for each item (e.g. white, gray, 50%, black, etc.). The problem with hierarchical menus is that MenuHook is not called while a hierarchical menu is down, because of an oversight on my part when I rewrote the Menu Manager for the MacII. Another way to get both time and information is to write an MDEF "wrapper" that gets called instead of the standard MDEF. (This will require **MANY** more tricks than writing a MenuHook. You should not do this unless you REALLY know what you are doing, including how to get at the correct MDEF's once yours has been called, as well as how to get yours called instead of any other MDEF. Kids don't try this at home!). When your MDEF is called, you will want to do your work during the "Choose Message". Once you do the work, or if it is not the choose message, you must call the real MDEF so that tracking continues properly. In summary, if it's your program, and you don't use hierarchical menus it's very easy. The hard part is trying to handle custom MDEF's, and hierarchical menus. Good luck, Frank Leahy Apple Computer leahy3@apple.com AppleLink: LEAHY3