🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #5862

Re: Accessing NewMenu UserData

#5862
From: Dale Larson
Date: Mon, 15 Oct 1990 23:50
47 lines
2239 bytes
In article <15157@cbmvax.commodore.com> peter@cbmvax.commodore.com 
(Peter Cherna) writes:
>Let's say your function returned a BOOL and took a UWORD as its parameter:
>
>	BOOL (*fcn)(UWORD);
>
>	fcn = GTMENUITEM_USERDATA( ItemAddress( menu, selection ) );
>
>	return = (*fcn)(code);
>
>Your problem is that GTMENUITEM_USERDATA() returns an APTR (which
>is really a void* ).  You'd have to cast that into a pointer-to-function
>before you can invoke it as a function. 

Thank you very much for your reply.  I guessed that GTMENUITEM_USERDATA()
was returning an APTR, but wasn't very sure, so I didn't try very hard to
get the cast into a pointer-to-function right.  With your little nudge
my menus are now screaming.  Instead of adding a new variable as you did
above, I call the function with a cast. 
 
I really really really really love gadtools!!!

(Sure, there's a lot more to be done, but gadtools is such an improvement
over 1.3 intuition!)  Setting up the menus took me all of 120 _seconds_!
Attaching the menus to windows has always been cake.  Since none of my 
menu-handling functions have any inputs or outputs, dealing with MENUPICKS 
is now as simple for me as:

USHORT selection;
struct MenuItem item;

selection = code;  /*  code = IntuiMessage->Code  */
while(selection!=MENUNULL)
	{
	item = ItemAddress(Menu, (LONG)selection);
	(* (void (*)void))GTMENUITEM_USERDATA(item))();
	selection = item->NextSelect;
	}

>     Peter Cherna, Software Engineer, Commodore-Amiga, Inc.
>     {uunet|rutgers}!cbmvax!peter    peter@cbmvax.cbm.commodore.com
>My opinions do not necessarily represent the opinions of my employer.
>"Television is a medium because it is neither rare nor well-done."


--
-Dale Larson  (dlarson@blake.u.washington.edu)
Technical Details
Message-ID: <9295@milton.u.washington.edu>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!ogicse!milton!blake.u.washington.edu!dlarson
References: <9194@milton.u.washington.edu> <15157@cbmvax.commodore.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!ogicse!milton!blake.u.washington.edu!dlarson
From: dlarson@blake.u.washington.edu (Dale Larson)
Newsgroups: comp.sys.amiga.tech
Subject: Re: Accessing NewMenu UserData
Message-ID: <9295@milton.u.washington.edu>
Date: 15 Oct 90 23:50:53 GMT
References: <9194@milton.u.washington.edu> <15157@cbmvax.commodore.com>
Sender: news@milton.u.washington.edu
Organization: The Evergreen State College,  WA
Lines: 47