I did this by adding a bunch of menu items a design time and unchecking their visible property. Then at runtime, when i wanted to 'add' one, i simply changed one of the item's caption and made it visible.:)
Printable View
I did this by adding a bunch of menu items a design time and unchecking their visible property. Then at runtime, when i wanted to 'add' one, i simply changed one of the item's caption and made it visible.:)
Or you could make a menuitem collection.
Under the forms menueditor, simply add an element, and set its index to 0.
When you then scan the favorites directory, you simple add new menuitems to the collection. One for each file found.
Code:...
if i>0 then
load objFavorites(i)
end if
objFavorites(i).caption = Filename
objFavorites(i).visible = true
i=i+1
Hmm... that works but now I'm having trouble adding subdirectories and such. First, I don't know how to add subdirectories to a objfavorites(index) and then there is that other problem of looping through every directory in the favorites directory and adding every directory in that and so on endless loop kinda thing. I think I can figure that second problem out, but for adding submenus I'm clueless. Any help is appreciated.
Thanks! :)
Well vb comes to a direct holdt, when you try to create fancy things like dynamically added submenuitems.
To fix your problem, you would have to take over the creation of menuitems from VB, which means subclassing and alot of API writing.
I collected this on this forum, it may help:
Create a menu called mnuFolder with the caption Folder.
Than create a submenu called mnucontents with the caption Contents.
And add this code:
Code:Private Sub Form_Load()
On Error Resume Next
Dim FileLister
FileLister = Dir$("C:\*.*")
Do While Len(FileLister)
Load mnucontents(mnucontents.Count)
MyInt = mnucontents.Count - 1
mnucontents(MyInt).Caption = FileLister
FileLister = Dir
Loop
End Sub
Then to find out path to user's favourites:
Code:Option Explicit
Private Declare Function SHGetFolderPath Lib "shfolder" Alias "SHGetFolderPathA" (ByVal hwndOwner As Long, ByVal nFolder As Long, ByVal hToken As Long, ByVal dwFlags As Long, ByVal pszPath As String) As Long
Private Const CSIDL_FAVORITES As Long = &H6 ' <user name>\Favorites
Private Sub Command1_Click()
Dim Path As String
Path = String(260, 0)
'Path must have a length, And 260 is large enough To contain any path
SHGetFolderPath 0, CSIDL_FAVORITES, 0, 0, Path
MsgBox Path
End Sub