Results 1 to 11 of 11

Thread: How can I update a top-level menu before displaying it?

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    56

    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"?

  2. #2
    Hyperactive Member
    Join Date
    Sep 2009
    Location
    Lost in thought
    Posts
    349

    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.

    how to stop the playsound when it is in loop..Play more than 1 sound at a time..
    ini file Check if IP changed Strings 'Split', 'Left' and 'Right'
    Save And Load an Array of list-boxes, to and from a file......list-box and CommonDialog
    Quote Originally Posted by RobDog888

    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

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    56

    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.

    Thanks again.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    Hyperactive Member
    Join Date
    Sep 2009
    Location
    Lost in thought
    Posts
    349

    Re: How can I update a top-level menu before displaying it?

    Hope this helps you!,
    Have a nice day.

    Regards 5ms.
    Attached Files Attached Files

  7. #7

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    56

    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.

  8. #8
    Hyperactive Member
    Join Date
    Sep 2009
    Location
    Lost in thought
    Posts
    349

    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
    Or May be this
    Last edited by 5ms?; May 20th, 2010 at 03:17 PM.

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: How can I update a top-level menu before displaying it?

    The localize, lazy fashion is to write the update logic once... then call that function in all the different places you need to call it from.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    56

    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.

  11. #11
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width