Click to See Complete Forum and Search --> : menus


batsheva
June 21st, 2001, 04:49 PM
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!

Ghost308
June 21st, 2001, 05:18 PM
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.

Tower
June 21st, 2001, 06:48 PM
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

Iouri
June 22nd, 2001, 07:17 AM
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
iouri@hotsheet.com

John G Duffy
June 22nd, 2001, 05:07 PM
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

John G Duffy
June 22nd, 2001, 05:10 PM
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