1. Dynamic Menu Creation & Destroying them after each session
Hi,
I am trying to create dynamic menus/menuitems options for each log-in session.
Creating is fine, but destroying those menuitems is not going through.
I tried to follow the logic destroyMenu in ARWEN, but could not get through.
Can not use both win32lib and arwen together because of namespace clashes.
Is there any other way around?
Regardcs,
Rad.
2. Re: Dynamic Menu Creation & Destroying them after each session
Just thinking - not sure if it would work, but surely you could send a message
to Windows directly?
Alex
3. Re: Dynamic Menu Creation & Destroying them after each session
Hi Pete,
Thanks for your reply.
Let me give you the background of what I am trying to do.
I am trying to develop a multi-user application where each user will log in to
the application via user-id/password combination. Depending on his access rights
to various options within the application, a dynamic menu will be built after his
successful login. Once he logs off, the menu will be destroyed and control will
come back to earlier log-in screen for other/ same user to go in. Each time
depending on logged-in user's access rights, a dynamic menu will be available for
that single user session.
(Though currently I am loading all the menu options for any user and trying to
remove menu after log off.)
Now, the way I went ahead with it - using EuVIDE, win32lib and FASTMENU by
c.k.lester. At the closure of main application window (where menu is built) and
before going back to log-in window, I am trying to destroy the user specific
menu/menu items, without which menu bar is appended with same multiple menu
options for each new session.
My menu structure is as follows:
System (Menu) --> Categories (Sub-menu) --> Category Maintenance (Menu Item)
--> Category List (Menu Item)
| |
| |
| --> Users (Sub-menu) --> User Maintenance (Menu Item)
| --> User List (Menu Item)
|
Log-out (Menu) --> Exit (Menu Item)
I tried to follow the logic in ARWEN destroyMenu function. Got the MenuID
(System, Log-out) properly, but got stuck at Menu Items.
E.g. For System menu, got xGetMenuItemCount properly as 2, but could not call
destroyMenu recursively with proper MenuItem IDs. xGetMenuItemID fails. Got some
number mID.
Is there any way I can get the MenuItemID's of the parent MenuID?
Following is the code I am using:
procedure MainMenu_onClose (integer self, integer event, sequence
params)--params is ()
sequence children
-- Get a list of all the controls owned by this window
children = findChildren(MainMenu)
-- Delete all the Menus
for i = 1 to length(children) do
if find(children[i][2],{Menu}) then
void = destroyMenu(children[i][2])
end if
end for
openWindow({LogInWin, Combo20}, Normal)
end procedure
.
.
.
.
global function destroyMenu(atom id)
atom hMenu, hsubMenu
integer count, mID
sequence submenus
if id = Menu then
hMenu = getHandle(id)
-- first, destroy any menuitems
count = c_func(xGetMenuItemCount, {hMenu})
for i = count to 1 by -1 do
mID = c_func(xGetMenuItemID, {hMenu, i})
if mID != #FFFFFFFF then -- valid id obtained
void = destroyMenu(mID)
end if
end for
-- second, destroy the menu
void = c_func(xDestroyMenu, {hMenu} )
return True
-- destroy a single menuitem
elsif id = MenuItem then --or id = MenuSep then
void = c_func(xRemoveMenu, {getParentHwnd(id), id, MF_BYCOMMAND})
return True
end if
return True
end function
I get mID as a number which fails in xGetMenuItemID with "type_check failure,
mID is 4294967295" error.
Also I am not sure about the xRemoveMenu parameters (getParentHwnd ?).
Where can I get detailed documentation on xGet..... functions?
Regards,
Rad.
-----Original Message-----
From: Pete Lomax [mailto:petelomax at blueyonder.co.uk]
Sent: 13 November 2005 05:45
To: EUforum
Cc: radhx at rediffmail.com
Subject: Re: Dynamic Menu Creation & Destroying them after each session
Rad wrote:
>Hi,
>
>I am trying to create dynamic menus/menuitems options for each log-in session.
Not /quite/ sure what you mean there. Log in or program run?
>Creating is fine, but destroying those menuitems is not going through.
>
>I tried to follow the logic destroyMenu in ARWEN, but could not get through.
As a convert to arwen, I may be able to help, though if you are in a
round about way asking how to apply what I consider that relatively
clear-cut logic to win32lib, now that I could never follow.
>Can not use both win32lib and arwen together because of namespace clashes.
True, plus two incompatible message loops from two GUI libs would be
more than a minor problem to get over.
My win32lib/MEditor project rebuilt menus, which seemed to work, but
to be honest was always problematical. See rebuildWindowMenu() in
file.e, which was as far as I got.
I have not re-attempted similar in arwen/Edita, though there is an
example shipped with arwen, demo_menus.exw which works just fine.
Regards,
Pete
PS MEditor (which I no longer support) and Edita are available from
http://palacebuilders.pwp.blueyonder.co.uk/euphoria.html
PPS As I am currently unable to post to Euforum, please cc any reply
both there and to me direct.
PPPS My recommendation is, of course, to dump win32lib and join the
growing arwen crowd!
4. Re: Dynamic Menu Creation & Destroying them after each session
Rad wrote:
>
> Hi Pete,
>
> Thanks for your reply.
>
> Let me give you the background of what I am trying to do.
>
> I am trying to develop a multi-user application where each user will log in
> to the application via user-id/password combination. Depending on his access
> rights to various options within the application, a dynamic menu will be built
Why don't you simply GREY out certain features depending on the
log-in password that way everyone will use the same menu but
not be able to access certain selections or features.
Bernie
My files in archive:
w32engin.ew mixedlib.e eu_engin.e win32eru.exw
Can be downloaded here:
http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan
5. Re: Dynamic Menu Creation & Destroying them after each session
Bernie Ryan wrote:
>
> Rad wrote:
>
> Why don't you simply GREY out certain features depending on the
> log-in password that way everyone will use the same menu but
> not be able to access certain selections or features.
>
> Bernie
>
Yes, I can take that option for sure.
The system I am trying to clone in Euphoria has more than 500 options for
users of various categories operators, officers, managers etc. Each category
of users will have access to only specific processes/options. Only the
Superuser will have access to all the options.
By building user specific menus I am trying to reduce the menu clutter for
all the users, would like to hide those options from the users which
they will never be using.
Regards,
Rad.
6. Re: Dynamic Menu Creation & Destroying them after each session
- Posted by Greg Haberek <ghaberek at gmail.com>
Nov 13, 2005
-
Last edited Nov 14, 2005
> Is there any way I can get the MenuItemID's of the parent MenuID?
Its pretty simple. Just get the count of items, then walk through
grabbing each ID. I just whipped this up in GMail, it might not work
entirely:
global function getMenuItemIDs( atom MenuID )
-- MenuID is the parent menu handle
integer count
sequence IDs
atom ID
count = c_func( xGetMenuItemCount, {MenuID} )
if count = -1 then
return {}
end if
IDs = {}
for i = 0 to count-1 do -- zero-based index
IDs &= c_func( xGetMenuItemID, {MenuID, i} )
end if
return IDs
end function
> I get mID as a number which fails in xGetMenuItemID with "type_check fail=
ure, mID is 4294967295" error.
That's because its too big to be an integer. You need to declare mID
as an atom. Most Windows "handles" need to be atoms.
> Also I am not sure about the xRemoveMenu parameters (getParentHwnd ?).
BOOL RemoveMenu(
HMENU hmenu,=09// handle of menu
UINT uItem,=09// menu item identifier or position
UINT fuFlags=09// menu item flag
);
> Where can I get detailed documentation on xGet..... functions?
They're Windows API functions, and they don't start with 'x', most of
us use that to separate them from the actual functions used to wrap
them. Download the Windows API documentation here: (link from the
Archive)
ftp://ftp.borland.com/pub/delphi/techpubs/delphi2/win32.zip
7. Re: Dynamic Menu Creation & Destroying them after each session
Greg Haberek wrote:
>
> > Is there any way I can get the MenuItemID's of the parent MenuID?
>
> Its pretty simple. Just get the count of items, then walk through
> grabbing each ID. I just whipped this up in GMail, it might not work
> entirely:
>
Finally I cracked it. Using C K Lester's FastMenu (with little modification)
and the functions available in that include, I could destroy the user
specific menu at the end of each successful session and regenerate it again
for the next session.
Following is the code:
==========================================================
function destroyMenu(atom itemID, sequence item)
atom childID
sequence s
for i = 1 to length(item) do
s = item[i]
if not allAtoms(s) then -- from FastMenu
childID = getMenuID(s[1]) -- from FastMenu
-- InfoWindow("SubMenu" & sprintf("%d", i) & " ID: " & sprintf("%d", childID)
& " : " & s[1])
void = destroyMenu(childID, s[2])
else
childID = getMenuID(s)
-- InfoWindow("MenuItem" & sprintf("%d", i) & " ID: " & sprintf("%d", childID)
& " : " & s)
end if
destroy(childID)
end for
return w32True
end function
procedure MainMenu_onClose (integer self, integer event, sequence
params)--params is ()
atom childID
for i = 1 to length(user_menu) do -- user_menu is input for FastMenu
childID = getMenuID(user_menu[i][1]) -- from FastMenu
-- InfoWindow("MenuBar" & sprintf("%d", i) & " ID: " & sprintf("%d", childID) &
" : " & user_menu[i][1])
void = destroyMenu(childID, user_menu[i][2])
destroy(childID)
refreshWindow(MainMenu)
end for
end procedure
setHandler( MainMenu, w32HClose, routine_id("MainMenu_onClose"))
==========================================================
CK, I was wondering whether destroyMenu() can be included into FastMenu
as a function itself.
Thanks to all you guys, Pete Lomax, Greg Haberek, Bernie Ryan,
Alex Chamberlain... for giving me insight into the problem,
it really helped me to learn.
Regards,
Rad.
8. Re: Dynamic Menu Creation & Destroying them after each session
Rad wrote:
>
> CK, I was wondering whether destroyMenu() can be included into FastMenu
> as a function itself.
Yeah, I'll put it in the library.
Thanks! :)
-=ck
"Programming in a state of EUPHORIA."
http://www.cklester.com/euphoria/