Article View: comp.sys.amiga.tech
Article #5084Re: Problem with Menu Events
From: Fred Mitchell - Product Assuranc...
Date: Thu, 30 Aug 1990 16:38
Date: Thu, 30 Aug 1990 16:38
74 lines
2466 bytes
2466 bytes
In article <906@augean.ua.OZ.AU> e4ajwake@augean.ua.OZ.AU (Wakefield) writes:
>Dear Gurus, (or similar)
>
>I have a problem with intuition returning the address of a menu item when
>the item causes an event. The code that I am using is shown below, cut down
>of course.
>
>The file "menu.h" contains all the menu and screen etc structures required to
>run the program. I have previously been using the class & code fields to
>extract the menu item, and used switch statements to recover the menu item
>and call the apporpriate function (replaced here by printf's).
>
>However it seems that it should be possible to use the code outlined below to
>do this more efficently and simply.
>
>The problem:
>
>The address field of the message structure is alays ZERO!!!
>
>Questions:
>
>Is what I am trying to do possible ?
>Has anyone out there done this before ?
>Does anyone have some sample code ?
>Is there a simple solution ?
>
>Now the code...
>
>
>#include "menu.h"
>
>void HandleEvent();
>
>main()
>
>{
> APTR address;
> struct IntuiMessage *message;
>
> for(;;) {
> Wait(1L << MyWindow1->UserPort->mp_SigBit);
>
> while(message = (struct IntuiMessage *)
> GetMsg(MyWindow1->UserPort))
> {
> address = message->IAddress;
> ReplyMsg(message);
> HandleEvent(address);
> }
> }
The way to get the address of the MenuItem structure is to
take the Menu number returned in the Code field and call
ItemAddress() as follows:
struct MenuItem *mi;
...
mi = ItemAddress(yourMenuStrip, message->Code);
...
Also, you'll want to check the NextSelect field in your MenuItem to see
if there are any other selections:
while (mi->NextSelect != MENUNULL) {
mi = ItemAddress(yourMenuStrip, mi->NextSelect)
...process it...
}
And that should do the trick for you.
-Mitchell
Yes, I remember my first taste of Intuition...
Technical Details
Message-ID:
<14095@cbmvax.commodore.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!cbmvax!mitchellReferences:
<906@augean.ua.OZ.AU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!cbmvax!mitchell From: mitchell@cbmvax.commodore.com (Fred Mitchell - Product Assurance) Newsgroups: comp.sys.amiga.tech Subject: Re: Problem with Menu Events Keywords: Menu Events Message-ID: <14095@cbmvax.commodore.com> Date: 30 Aug 90 16:38:31 GMT References: <906@augean.ua.OZ.AU> Reply-To: mitchell@cbmvax (Fred Mitchell - Product Assurance) Organization: Commodore, West Chester, PA Lines: 74