CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: menus

  1. #1
    Join Date
    Mar 2001
    Posts
    29

    menus

    I have an mdi application and i would like to add each time a form is opened to save that name is the most recent files. Like it is done in microsoft word - where the last four documents is listed in the File menu.

    thanks!


  2. #2
    Join Date
    Jun 2001
    Location
    Memphis, TN
    Posts
    146

    Re: menus

    What you need to do is create 4 (if that's how many you're wanting...) menu items under the File menu. Set them to hidden by default. You'll need to log the most recently opened documents to a text file or even the registry by updating your log every time a new document is opened. Then set your app to load those settings and apply them through code, probably in the Load event of your MDI parent form, to the 4 invisible items under the File menu and make them (or however many) visible.


  3. #3
    Join Date
    May 2001
    Location
    Russia
    Posts
    200

    Re: menus

    Good answer but i use creating dinamic menu:
    Create menu MenuDoc with index 0
    Place this code in MDI form load

    For i = 1 To 4
    strNameDoc = GetSetting("MenuDoc", CStr(i), "Name in menu")
    Load MenuDoc(i)
    MenuDoc(i).Caption = strNameDoc
    Next

    This is exapmle to read data from registry. To save data use
    SaveSetting "MenuDoc", CStr(i), "Name in menu", strNameDoc

    Andy Tower

  4. #4
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: menus

    Try this code to add to and delete from menu

    Dim gLastElement As Integer

    Private Sub Form_Load()
    '---------------------------
    gLastElement = 0
    mnuDel.Enabled = False
    End Sub

    Private Sub mnuAdd_Click()
    '---------------------------
    mnuItems(0).Visible = True
    If gLastElement = 15 Then
    Exit Sub
    End If
    gLastElement = gLastElement + 1
    Load mnuItems(gLastElement)
    mnuItems(gLastElement).Caption = "Troop" + Str(gLastElement)
    mnuDel.Enabled = True
    End Sub

    Private Sub mnuDel_Click()
    '---------------------------
    mnuAdd.Enabled = True
    Unload mnuItems(gLastElement)
    gLastElement = gLastElement - 1
    If gLastElement = 0 Then mnuDel.Enabled = False: mnuItems(0).Visible = False
    End Sub

    Private Sub mnuGrow_Click()
    '---------------------------
    If gLastElement = 15 Then mnuAdd.Enabled = False
    End Sub



    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  5. #5
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: menus

    Tower,
    Using VB IDE Menu Editor, there is an option called WindowList that will maintain a list of open documents so the capability must be there.
    I have a Dynamic menu sample I found on Planet-Source-Code.com/vb titled "Dynamic Menu Control (Updated) submitted by Pete Cozens that contains a MenuStructure with a flag byte. The flag byte definitions have a WindowList constant so you might look at that sample. Here are the Structure and flag byte definitions for your reference

    Enum MenuFlags
    Checked = &H1
    Hidden = &H2
    Grayed = &H4
    PopUp = &H8
    WindowList = &H20 <----------------????????
    LastItem = &H100
    End Enum
    '*********************************************************************************************
    ' Internal menu struct
    '*********************************************************************************************
    Type MenuStruct
    dwFlags as MenuFlags
    lpNextMenu as Long
    lpFirstItem as Long
    lpszName as Long
    hMenu as Long
    wID as Integer
    wShortcut as Integer
    End Type




    John G

  6. #6
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: menus

    Just so you see this in your email, since you are the originator, Please refer to my post about your probelm. I posted it to the wrong Responder. My response is buried somewhere in the original thread for this question.

    John G

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

Featured