adding items to menu during runtime

i would like to give the user of my program
the ability to edit/change/delete items from
the menubar. these changes would be saved in
an ini file and read from when the program
loads. If its alot easier (on me) the user
could manually edit the ini file. how do i go
about reading multiple items from an ini file
and adding them to the programs menu?...please
be detailed and give example...thanks
mwamAsked:
Who is Participating?
 
gissingConnect With a Mentor Commented:
Use the following declaration...

Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

.to read a buffer from a private profile (a.k.a. an INI file)

Have a menu on your form which has a menu item which is in a control array, Make it index zero. That is, you will have an invisible menu item called something like "mnuItem(0)". When you read the strings in from the INI file (using the above API call), do a Load mnuItem(1) to create a new menu item with index 1. Make it visible, set its caption, and away you go. (for subsequent menu items, you obviously do a Load mnuItem(2), Load mnuItem(3)... etc. etc.
0
 
zabmanCommented:
Well there are several ways to go about this, I'll use the one I think is easiest:

1.  Create the menubar with ALL of the options that you would    
    like to have.

2.  In the MAIN FORM LOAD read the INI file and have the program
    interperate the information to see if the menu controll will
    be visable.  That's it!

  You see, it is virtually impossible to create new controls in Run-Time, however, you can have the controls visible or invisible!  

  If you would like a demo app, e-mail me at zabman@hotmail.com and I will send you a copy.

                           -- Neil Z. :-)

0
 
mwamAuthor Commented:
you'll have to be more specific.
i don't know of any VB command "interpret("file.ini")" :)
also, whether its visible or not, is beside the point.
it wont be visible in the menu bar, but when right clicking,
i'll use the PopupMenu command. the menu control is created
in design time, but i need to know how to add items to it,
when the form loads...thanks.

0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
mwamAuthor Commented:
that's what i was looking for...thanks
0
 
mwamAuthor Commented:
how do i go about adding a command for this
new menuitem...during runtime?
0
 
gissingCommented:
what do you mean "adding a command" ?
0
 
mwamAuthor Commented:
i mean, the menu item has to do something, right?
anyway..i figured out a way...i'm using "Line Input #1"
to read a text file to get the menu items (in this case
programs to be run and their paths) .. i'm adding
the paths to an invisible listbox then assigning them this way:

Private Sub mnurun_Click(Index As Integer)
If Index = 0 Then Exit Sub
For i = 0 To appnumber - 1
If Index = i + 1 Then task = Shell(List2.List(i), vbNormalFocus)
Next
End Sub

appnumber being total number of items (apps) and the paths
being the list2.list(i). theres probably a better way
using arrays, but i've never used them and this seems to work.
any suggestions would be appreciated...thanks


0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.