Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Menu Editor Question 4

Status
Not open for further replies.

dvannoy

MIS
May 4, 2001
2,765
0
0
US
On my main form i have a menu...i put an item called window.I want the users to be able to see what forms are open. so they can select it without minimizing the current form.

can someone help me do this?

Thanks DVannoy
A+,Network+,CNA
dvannoy@onyxes.com
 
I don't think that you can add menu items during run-time, but what you may want to do is add all possible window names to the menu, and set their visibility property to false. When the user opens one of those windows up, simply add:

[formName].[menuItemName].visibility = true

to your new form's OnLoad() event. Hope this helps. "The night sky over the planet Krikkit is the least interesting sight in the entire universe."

-Hitch Hiker's Guide To The Galaxy
 
AtomicChip's suggestion is probably the easiest way of achieving this effect.

Beleive me, doing it the requested way is a pain. Firstly, VB has no functionality for adding new menus at run time. So firstly, you need to use the API just to create and then populate the menu. Secondly, once you have done this, there is no mechanism in VB to receive events from this new menu. So you have to subclass the main windows procedure using Address, and look for certain windows messages from your newly created menu.

I hacked together some code to do this today, which you can have a look at if you are still interested. But AtomicChip's suggestion is probably the easiest way of achieving this effect.
 
thanks..yaa AtomicChip's suggestion was easy to do..the only thing i dont like is, menu editor makes you have one visable item under the menu heading...so i did a line...doesnt look the best but it works..

I would like to look at your code if you dont mind..

Thanks DVannoy
A+,Network+,CNA
dvannoy@onyxes.com
 
Is there a way to avoid this visible item requirement? There must be a better way to build a window menu item. How does Microsoft do it in Word?
 
dvannoy-
If you want a better way of doing what you want, instead of using a line in the menu, why not set the actual menu item's enabled property to false until at least one of the forms are open? At that point, re-enable the menu item, and set the form's submenu item to visibility = true (as I suggested above). There's no point in having a menu enabled if there's nothing in it. Hope this helps to get you around your problem. WinAPI can really get ugly sometimes. "The night sky over the planet Krikkit is the least interesting sight in the entire universe."

-Hitch Hiker's Guide To The Galaxy
 
You can actually add menu items at run time. You just need to have one there to begin with, because VB won't start a new set. You make a menu with one sub-item and give it an index to make it a control array. Then make it invisible. Then, when "loading" the menu, just make sure the FIRST one just changes the display of the first menu item and makes it visible. Any after that will add a new control array item and set each one up. I've used this to display report selections that are available depending on who is logged in.
 
dvannoy,

If you really want to look at my code then let me know - but the suggestions given here are probably all better (certainly easier) solutions.
 
Here’s a more detailed description. Sorry about the rather vague note before. I was in a hurry.

1) Create a main menu item such as "Options" or "Reports", or whatever, and make it invisible and disabled.
2) Make one sub-menu item under it, set the index to 0 to make it a control array, and disable it and make it invisible.
3) OR, set them up and when the form loads, start by disabling them and making them invisible, and then immediately run a routine to “build” the menu selection list. This is probably the better way.
4) This is a sample build routine, with mnuMyMenuItems being the name of the sub-menu control array.

Public Sub LoadMyMenu()
'This routine clears, then loads the menu.
Dim intCounter as integer

'Turn it on to work with it.
mnuMyMenuItems(0).Visible = vbTrue

'The UNLOAD removes all of the items
' except the first one from the
' list, to start building it fresh. Obviously
' if you do it once for the form, this is not
' necessary, but with it, you allow for calling
' the routine from anywhere and triggering a
' full menu rebuild.
If mnuMyMenuItems.Count > 1 Then
For intCounter = mnuMyMenuItems.Count - 1 To 1 Step -1
Unload mnuMyMenuItems(intCounter)
Next intCounter
End If

'Now load it up again.
intCounter = 0

With m_rstSourceTable
.MoveFirst

'Go through the table (or other selection
' source you have), adding the selections
' to the menu. As long as whatever you
' assign to the caption is a valid string,
' this is a good spot to do things like
' calculations and concatenations for the
' list.
Do While Not .EOF
intCounter = intCounter + 1
'This adds an item to the menu.
Load mnuMyMenuItems(intCounter)

'Set the new item properties. Yes,
' you CAN put separators or other such
' things in this way, but you will
' have to control when and where.
mnuMyMenuItems(intCounter).enabled = True
mnuMyMenuItems(intCounter).Visible = True
mnuMyMenuItems(intCounter).Caption = yourstring

.MoveNext
Loop
End With

'Turn off the first one. (I took this route
' because I was going to work with the items
' numbered 1 and onward anyway, and this was
' a simple way to just “hide” that necessary
' first one without having to change its
' properties much. If you want to use it,
' make sure you use it FIRST, before creating
' any new ones, by enabling it and changing
' the caption. Remember that if you have to make
' it invisible again later for any reason,
' do NOT UNLOAD it, as you need this one.)
mnuMyMenuItems(0).Visible = vbFalse
End Sub

5) In the menu control array’s Click event, just check
the caption of the item with that index number, and
run the code that pertains to that item. You obviously
have to make sure your spelling is good, and if you
change a caption, you have to change the hard-coded
version, but it’s well worth it. This is a great and
easy way to create customized or context-sensitive
popup menus geared to certain logged-in users or to
the previous steps the user has followed.


 
courtoisf,

Thanks - I needed help on this too. I think .net has methods for all of this, but we're not implementing that for some time. Thanks again.
 
VB6 has a very easy solution to this. Add a menu item, name it, then check the 'window list' checkbox on the menu editor.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top