Results 1 to 4 of 4

Thread: Dynamic Menu

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 1999
    Location
    London, UK
    Posts
    58

    Post

    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

    ------------------
    Code:
    * * * * * * * * * * * * * * * * * * * * * *
    *                                         *
    *    AndyC                                *
    *    London                               *
    *    email: [email protected]      *
    *                                         *
    * * * * * * * * * * * * * * * * * * * * * *

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Post

    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.

    Code:
    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

    [email protected]
    A BMW Group Company

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 1999
    Location
    London, UK
    Posts
    58

    Post

    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 [email protected] please?

    Thanks again,

    AndyC (slowly waking up now)



    ------------------
    * * * * * * * * * * * * * * * * * * * * * *
    AndyC
    London
    email: [email protected]
    * * * * * * * * * * * * * * * * * * * * * *

  4. #4
    Lively Member
    Join Date
    Dec 1999
    Posts
    106

    Post

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width