Solved

adding items to menu during runtime

Posted on 1998-08-05
7
168 Views
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
0
Comment
Question by:mwam
  • 4
  • 2
7 Comments
 

Expert Comment

by:zabman
Comment Utility
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
 

Author Comment

by:mwam
Comment Utility
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
 
LVL 1

Accepted Solution

by:
gissing earned 200 total points
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:mwam
Comment Utility
that's what i was looking for...thanks
0
 

Author Comment

by:mwam
Comment Utility
how do i go about adding a command for this
new menuitem...during runtime?
0
 
LVL 1

Expert Comment

by:gissing
Comment Utility
what do you mean "adding a command" ?
0
 

Author Comment

by:mwam
Comment Utility
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

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now