How can I update a top-level menu before displaying it?
I can't put the updating code in the click event handler. In VB6, if the user clicks the menu, the click event handler is called AFTER the menu is displayed . Furthermore, unlike button menus, menus don't provide a "before drop down" event handler. Click is the only event handler .
Is there a way to add code to the click event handler to say, "drop down this menu"?
Re: How can I update a top-level menu before displaying it?
Hope this helps you!
Code:
Private Sub Form_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then ' Check if right mouse button was clicked.
PopupMenu mnuFile ' Display the File menu as a pop-up menu.
End If
End Sub
Have a nice day,
Regards 5ms.
Last edited by 5ms?; May 20th, 2010 at 10:16 AM.
Reason: ?
.
The answer to your question is Here
And here
C:\Program Files\Microsoft Visual Studio\MSDN98\98VSa\1033\SAMPLES\VB98
Please go to the "Thread Tools" menu at the top of this Thread, and click "Mark Thread Resolved" when you have your answer.
So I can fine the answer when I need it.
So please install VB6 service pack 6 as its the latest and last supported service pack MS will ever make. http://support.microsoft.com/kb/q198880/ I'm sure this will fix your issue
The only reason some people get lost in thought is because it’s unfamiliar territory. —Paul Fix
Re: How can I update a top-level menu before displaying it?
Thank you for your response.
I think I am having trouble with your proposed solution because I am not displaying a contextual menu. I used the menu editor to create this menu system. mnuFile is at the top level.
I tried putting the "update menu" code in the MouseDown and the MouseUp handlers. In both cases, when I mouse down (or up) on the "File" in the top-level menu, the appropriate handler is not executed.
I tried to use PopupMenu in the mnuFile_Click handler, to display my file menu after the update code completes. In my experiment, nothing visibly happens when this event handler calls PopupMenu mnuFile.
I think I require handlers that are invoked when the user clicks within the top-level menu.
Otherwise, I may not be calling PopupMenu properly.
Re: How can I update a top-level menu before displaying it?
I think the correct solution is to update the menu as needed during the course of your application, not just before it is displayed. When clicking on the "File" menu, whatever you would be making the decision on, whether to display/not display some submenu items already happened, correct? So when it happens, then modify the menu.
Insomnia is just a byproduct of, "It can't be done"
Re: How can I update a top-level menu before displaying it?
the question that needs to be answered is: What is it EXACTLY you are trying to do? and I don't mean "change the menu before I display it" ... that much we gathered... but what's the circumstances that necessitates the changing of the menu?
Re: How can I update a top-level menu before displaying it?
I have an ActiveX arrangement. My program has a connection to an application like MS Word. In my program, I want the file menu to have an item for every document that is opened in my MS Word. Each item displays the name of its corresponding MS word document.
Through the connection, I can get the open document file names. For a button menu, I could update the menu items in the drop down event handler. But I can't do this with my top-level File menu, because there is no drop down event handler for menus.
While it is possible to update the menu when you open a document, create a document, close a document, save a document under a different name, or recover a lost document, the logic supporting this menu is now spread all over the program. Plus, even if user never displays the menu, the program updates the menu in an eager fashion. I was looking for a localized, lazy solution, like the button menu solution.
Re: How can I update a top-level menu before displaying it?
Code:
Private Sub Form_Load()
Dim x As Integer
For x = 1 To 4
Load mnuSubItem(x)
mnuSubItem(x).Caption = "Menu Item " & x + 1
mnuSubItem(x).Visible = True
Next x
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)
If Button = vbRightButton Then
Me.PopupMenu mnuShortCut
End If
End Sub
Private Sub mnuSubItem_Click(Index As Integer)
MsgBox Index
End Sub
Re: How can I update a top-level menu before displaying it?
Thanks, folks.
5ms?, when I click on the File menu in the top-level menu, neither MDIForm_MouseUp nor MDIForm_MouseDown execute. And putting ...
Me.PopupMenu mnuFile
... after update code in mnuFile_Click does not give me the desired results.
Techgnome, maybe I am using these terms improperly. When I said "localize", I meant a solution that is written in one place, rather than having a piece of the solution in several places. Let's update the menu in one place, just before displaying the menu. Let's not update is when we open, when we close, etc. When I said "lazy", I meant waiting to update the menu is the last possible moment. If the user never opens that menu, there is no need to update it.
Thanks for you help, everybody. It appears the best solution is to update the menu whenever you update the collection of opened documents.
Re: How can I update a top-level menu before displaying it?
Unfortunately, the way you wish to do it may require subclassing. When a menu item is about to be selected, messages are sent to the form. VB gives you the notification after it has been selected, not before. Subclassing would allow you to see that "before" message. Subclassing is an advanced topic and not IDE-friendly; crashes easily even when used properly. More stable in compiled apps, but unhandled errors within your app can cause crashes too.
Insomnia is just a byproduct of, "It can't be done"