adding items to menu during runtime

Posted on 1998-08-05
Medium Priority
Last Modified: 2010-05-03
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
Question by:mwam
  • 4
  • 2

Expert Comment

ID: 1468081
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. :-)


Author Comment

ID: 1468082
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.


Accepted Solution

gissing earned 600 total points
ID: 1468083
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.
7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.


Author Comment

ID: 1468084
that's what i was looking for...thanks

Author Comment

ID: 1468085
how do i go about adding a command for this
new menuitem...during runtime?

Expert Comment

ID: 1468086
what do you mean "adding a command" ?

Author Comment

ID: 1468087
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)
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


Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

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.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question