Create a menu by code

Ming
08-02-2001, 07:51 PM
Hi,
I have no control in a form at the begining (a blank form). Now i want to read a database to check which user can have which group of menu. That's why I need to create a dynamic menu.

If a menu exist already in the form, i can use Load Array( ) to add item.
However if i hv no existing menu? ^^;

Pls give me some advice, thx!

Ming

Thinker
08-02-2001, 07:57 PM
You have to have a 0 index menu to add additional ones at run-time. But you can make them invisible until you are ready to display them all.

I think therefore I am... sometimes right. images/icons/wink.gif

Ming
08-02-2001, 08:06 PM
Then is there any method that I can create it without the 0 index?
since, for each menu item, i must hv a submenu. if i hv a 0 index menu item, i can create the menubar item, but i dun know how to create the submenu ^^;

Thinker
08-02-2001, 08:16 PM
You have to have the 0 index menu. I don't know how to load submenus to a dynamically loaded top-level menu. It would be better to create a set of top level menus that would support all needs, with 1 submenu under each with a 0 index. Then after you read the database you can load the needed submenus and make the needed top-level menus visible and leave the rest hidden.

I think therefore I am... sometimes right. images/icons/wink.gif

Derek Stone
08-02-2001, 08:29 PM
Check out these API functions.
They will accomplish the task, albeit tediously.

AppendMenu
CreatePopupMenu
DestroyMenu
GetMenu
GetSubMenu
InsertMenuItem
ModifyMenu
RemoveMenu
TrackPopupMenu

I'll try to find/make an example in the meantime.

Good Luck
-cl

Ad1
08-03-2001, 06:43 AM
maybe a better solution would be to create all the menus at design time, but only make the applicable ones visible at run time which will make designing them and your coding of the click events a lot easier

Garrett Sever
08-07-2001, 05:43 PM
Those menu API functions require subclassing the form and capturing the appropriate messages... Much more involved than just having a zero-indexed menu that's hidden and using the "menu1_Click(Index as Integer)" methods.

He really doesn't want to use the menu API functions... Its ALOT more work than he (should) want.

-Hand out

<font color=green>"On a long enough timeline, everyone's life expectancy drops to zero."</font color=green> - Fight Club

Derek Stone
08-07-2001, 06:21 PM
If you bothered to actually read his post you'd understand why YOUR post is NOT the practical solution.

-cl

NewWave
01-29-2002, 06:24 AM
So does that mean their is an easy way do populate submenus or not? Example lying around anywhere?

Cheers-
NewWave

Garrett Sever
01-29-2002, 07:34 AM
Well, as is stated above, the easiest way would be to have one submenu with an index of 0 (could have Visible = False), and dynamically load the rest using the Load statement.

If you opt to using CL's APIs you can also get the job done, however you will have to intercept the click messages using subclassing. This path is far from easy.

Regards.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum