PDA

Click to See Complete Forum and Search --> : Dynamic Menu


Andy Collyer
Dec 8th, 1999, 04:09 PM
Hi again!

I've got a load of tables - an unknown amount. I can (thanks to your help!) find out what they're called and do all sorts of stuff with them, but I want to include on my main form a menu that list them all, then when the user clicks one they get presented with a form they can use to edit stuff in there. That's not a problem but I am struggling with the menu bit. I don't seem to be able to load menu items at run-time, so I tried giving the first 10 plus a "More Tables..." one by using menu editor to create 10 entries and setting visible to false for all but the first. That bit works but when I click on "Tables" (top level), the code attempts to fill in the names and make them visible/invisible depending on whether or not there is a table name to put there. That bit doesn't work :( - I get runtime error 388: "Can't set Visible property from a parent menu". So I'm a bit stuck. Is there a way of doing this (what is it? ;) )or should I bin that idea and start again afresh?

Thanks for your advice,

AndyC
London

------------------

* * * * * * * * * * * * * * * * * * * * * *
* *
* AndyC *
* London *
* email: andy.collyer@bigfoot.com *
* *
* * * * * * * * * * * * * * * * * * * * * *

Mark Sreeves
Dec 8th, 1999, 06:19 PM
First of all I haven't tested this ;)

It's not runnable code anyway but it might point you in the right direction!


If you need more help I might be able to dig out a runnable sample.


Public Type MENUITEMINFO
cbSize As Long
fMask As Long
fType As Long
fState As Long
wID As Long
hSubMenu As Long
hbmpChecked As Long
hbmpUnchecked As Long
dwItemData As Long
dwTypeData As String
cch As Long
End Type

' Menus
Public Declare Function CreateMenu Lib "user32" () As Long
Public Declare Function DestroyMenu Lib "user32" (ByVal hMenu As Long) As Long
Public Declare Function SetMenu Lib "user32" (ByVal hWnd As Long, ByVal hMenu As Long) As Long
Public Declare Function InsertMenuItem Lib "user32" Alias "InsertMenuItemA" (ByVal hMenu As Long, ByVal un As Long, ByVal bool As Boolean, ByRef lpcMenuItemInfo As MENUITEMINFO) As Long
Public Declare Function GetMenu Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function SetMenuItemInfo Lib "user32" Alias "SetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, ByVal bool As Boolean, lpcMenuItemInfo As MENUITEMINFO) As Long
Public Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long


------------------
Mark Sreeves
Analyst Programmer

Mark.Sreeves@Softlab.co.uk
A BMW Group Company

Andy Collyer
Dec 8th, 1999, 06:39 PM
:o Point taken! It was early and I'm not so hot in the am!!

Thanks for the code - had a quick play but evidentally it's going to need much more! Looks like a fun weekend ahead :)

If you could try to dig out some working code that'd be great - in case this thread gets lost in the flood of daily questions, could you send it to andy.collyer@bigfoot.com please?

Thanks again,

AndyC (slowly waking up now)



------------------
* * * * * * * * * * * * * * * * * * * * * *
AndyC
London
email: andy.collyer@bigfoot.com
* * * * * * * * * * * * * * * * * * * * * *

hayessj
Dec 8th, 1999, 07:29 PM
I'm not too sure if I understand your problem but I think this may help. If you are looking to create a menu with a dynamic number of entries then open the menu editor and create a top level menu i.e. mnuFile. Create a sub menu item, call it mnuMain and give it an index of 0. Then paste the code below into the form. You'll see that if you change the value of nRandom in the Form_Load event you get that number of entries.

Option Explicit

Private Sub Form_Load()
Dim nRandom As Integer
Dim i As Integer

nRandom = 10

For i = 1 To nRandom
Load mnuMain(i)
mnuMain(i).Caption = i
Next

End Sub

Private Sub mnuMain_Click(Index As Integer)
MsgBox "clicked in menu item " & i
End Sub