Page 2 of 2 FirstFirst 12
Results 41 to 56 of 56

Thread: Menu Icons

  1. #41
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    6,837

    Re: Menu Icons

    A working demo of *what*? I still have no idea what the problem is and what you think isn't working.

    The top menu is "staying checked" through what action? The other two are not during what action? What are you doing that you think which one is checked should or should not change, and what code is there that you think should be carrying it out? The only time any of the check status are changing is *once* when you click a sub-sub-menu item on Form1, which changes the checks on Form2's sub-sub-menus, and when Form2 loads, which checks the first item (always, because it's not intended to do anything else as originally written).

    And what do you mean you're not using hSubMenu? You put the code I wrote in Form2, so yes you're using it, hSubMenu is the menu containing "Sub Menu 1" "Sub Menu 2" and "Sub Menu 3". hMenu is the top level menu bar.

    None of the VB code you've written is going to change the check status of those three, because to rehash the conversation that led to this, only API check an item that opens a submenu.

  2. #42

    Thread Starter
    Addicted Member Mongoose_MHS's Avatar
    Join Date
    May 2024
    Posts
    187

    Re: Menu Icons

    Ok, See the hsub part..

    However, what I am trying to do is get the NEXT sub menu checked.. As you can see, the first one always stays checked when it should be the second one and so on.. Outlined in red..
    Attached Images Attached Images  
    Monroe High School.. GO HORNETS!

    If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that

  3. #43

    Thread Starter
    Addicted Member Mongoose_MHS's Avatar
    Join Date
    May 2024
    Posts
    187

    Re: Menu Icons

    thinking something in here has to be added:
    Code:
    Private Sub Form_Load()
    Dim hMenu As LongPtr
    Dim hSubmenu As LongPtr
    hMenu = GetMenu(Me.hWnd)
    hSubmenu = GetSubMenu(hMenu, 0)
    CheckMenuItem hSubmenu, 0, MF_BYPOSITION Or MF_CHECKED
    End Sub
    OR

    The submenus need indexes? OR both, I could be wrong.. I dunno
    Monroe High School.. GO HORNETS!

    If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that

  4. #44
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    6,837

    Re: Menu Icons

    That's what the code in post 39 is for, so you can check any item in that submenu.

    You'll see it's the same code as the original, just made into a function that replaces the 0 in CheckMenuItem with the number you give it, which represents the order, starting at 0, of the items.

    I don't know how to make it any clearer than that; all you have to do is copy/paste it into the project you posted earlier (to the form you want to use it in, or both), and if you want

    UncheckItemByIndex 0 - Removes the check from "Sub Menu 1"

    CheckItemByIndex 1 - Checks "Sub Menu 2"


    I've modified the project to my best guess at how you wanted to work... it will check the initial item, then once Form2 is loaded, it will only allow one subsubitem to be checked, and check the subitem that contains the checked subsubitem while unchecking the others.
    Attached Files Attached Files
    Last edited by fafalone; May 20th, 2024 at 02:34 PM.

  5. #45
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    6,837

    Re: Menu Icons

    Oops there was a bug when I first posted it make sure you have the version I posted 4 minutes after the original, the correct version of Form1 will have

    Load Form2
    Form2.CheckItemByIndex 1
    Form2.Show vbModal


    To load it and check the item before the Show call blocks; the original version didn't check it initially because it was after Show.

  6. #46

    Thread Starter
    Addicted Member Mongoose_MHS's Avatar
    Join Date
    May 2024
    Posts
    187

    Unhappy Re: Menu Icons

    issue on form 2, but I indexed all the submenus and seubsubmenus.. Is that what's causing it?

    Ugh, small pics..
    Attached Images Attached Images   
    Last edited by Mongoose_MHS; May 20th, 2024 at 02:56 PM.
    Monroe High School.. GO HORNETS!

    If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that

  7. #47

    Thread Starter
    Addicted Member Mongoose_MHS's Avatar
    Join Date
    May 2024
    Posts
    187

    Re: Menu Icons

    Nvm.. I'm gonna try something..
    *Nope, already there so..
    Monroe High School.. GO HORNETS!

    If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that

  8. #48

    Thread Starter
    Addicted Member Mongoose_MHS's Avatar
    Join Date
    May 2024
    Posts
    187

    Re: Menu Icons

    form2 - 3rd Submenu.. subsubmenu selection change - It shouldn't have an error.. Everything is indexed
    Code:
    Private Sub mnuSubSubMenu2_Click(Index As Integer)
        Dim c As Long
        
        For c = 0 To mnuSubSubMenu2.UBound
            mnuSubSubMenu1(c).Checked = (Index = c)
        Next
        CheckItemByIndex 2
        UncheckItemByIndex 0
        UncheckItemByIndex 1
        UncheckItemByIndex 2 'I added this as it was missing, hoping this would be the fix, but it wasn't...
        For c = 0 To mnuSubSubMenu.UBound
            mnuSubSubMenu(c).Checked = False
        Next
        For c = 0 To mnuSubSubMenu2.UBound
            mnuSubSubMenu2(c).Checked = False
        Next
    End Sub
    Attached Images Attached Images  
    Last edited by Mongoose_MHS; May 20th, 2024 at 03:31 PM.
    Monroe High School.. GO HORNETS!

    If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that

  9. #49
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    6,837

    Re: Menu Icons

    Sorry it's a typo... change the yellow to mnuSubSubMenu2 and remove the green line. It wasn't "missing"... You do understand that CheckMenuItemByIndex *adds* the checkmark and UncheckMenuItemByIndex *removes* the check right? So the idea is you check the one you want and uncheck the others.
    Last edited by fafalone; May 20th, 2024 at 04:41 PM.

  10. #50

    Thread Starter
    Addicted Member Mongoose_MHS's Avatar
    Join Date
    May 2024
    Posts
    187

    Re: Menu Icons

    the other submenus have 0,1,2...

    Code:
    Private Sub mnuSubSubMenu_Click(Index As Integer)
        Dim c As Long
        
        For c = 0 To mnuSubSubMenu.UBound
            mnuSubSubMenu(c).Checked = (Index = c)
        Next
        CheckItemByIndex 0 'here
        UncheckItemByIndex 1 'here
        UncheckItemByIndex 2 'here
        For c = 0 To mnuSubSubMenu1.UBound
            mnuSubSubMenu1(c).Checked = False
        Next
        For c = 0 To mnuSubSubMenu2.UBound
            mnuSubSubMenu2(c).Checked = False
        Next
    End Sub
    
    Private Sub mnuSubSubMenu1_Click(Index As Integer)
        Dim c As Long
        
        For c = 0 To mnuSubSubMenu1.UBound
            mnuSubSubMenu1(c).Checked = (Index = c)
        Next
        CheckItemByIndex 1
        UncheckItemByIndex 0 'Here
        UncheckItemByIndex 1 'here
        For c = 0 To mnuSubSubMenu.UBound
            mnuSubSubMenu(c).Checked = False
        Next
        For c = 0 To mnuSubSubMenu2.UBound
            mnuSubSubMenu2(c).Checked = False
        Next
    End Sub
    
    Private Sub mnuSubSubMenu2_Click(Index As Integer)
        Dim c As Long
        
        For c = 0 To mnuSubSubMenu2.UBound
            mnuSubSubMenu1(c).Checked = (Index = c)
        Next
        CheckItemByIndex 2
        UncheckItemByIndex 0 'here
        UncheckItemByIndex 1 'here
        UncheckItemByIndex 2 'why not this one?
        For c = 0 To mnuSubSubMenu.UBound
            mnuSubSubMenu(c).Checked = False
        Next
        For c = 0 To mnuSubSubMenu2.UBound
            mnuSubSubMenu2(c).Checked = False
        Next
    End Sub
    ****ok, whatever.. I changed what you said and removed that line I put.. guess what.. still not working.. but no error now.. selection still not working right

    Code:
    Private Sub mnuSubSubMenu_Click(Index As Integer)
        Dim c As Long
        
        For c = 0 To mnuSubSubMenu.UBound
            mnuSubSubMenu(c).Checked = (Index = c)
        Next
        CheckItemByIndex 0 'here
        UncheckItemByIndex 1 'here
        UncheckItemByIndex 2 'here
        For c = 0 To mnuSubSubMenu1.UBound
            mnuSubSubMenu1(c).Checked = False
        Next
        For c = 0 To mnuSubSubMenu2.UBound
            mnuSubSubMenu2(c).Checked = False
        Next
    End Sub
    
    Private Sub mnuSubSubMenu1_Click(Index As Integer)
        Dim c As Long
        
        For c = 0 To mnuSubSubMenu1.UBound
            mnuSubSubMenu1(c).Checked = (Index = c)
        Next
        CheckItemByIndex 1
        UncheckItemByIndex 0 'Here
        UncheckItemByIndex 1 'here
        For c = 0 To mnuSubSubMenu.UBound
            mnuSubSubMenu(c).Checked = False
        Next
        For c = 0 To mnuSubSubMenu2.UBound
            mnuSubSubMenu2(c).Checked = False
        Next
    End Sub
    
    Private Sub mnuSubSubMenu2_Click(Index As Integer)
        Dim c As Long
        
        For c = 0 To mnuSubSubMenu2.UBound
            mnuSubSubMenu2(c).Checked = (Index = c)
        Next
        CheckItemByIndex 2
        UncheckItemByIndex 0 'here
        UncheckItemByIndex 1 'here
        For c = 0 To mnuSubSubMenu.UBound
            mnuSubSubMenu(c).Checked = False
        Next
        For c = 0 To mnuSubSubMenu2.UBound
            mnuSubSubMenu2(c).Checked = False
        Next
    End Sub
    Last edited by Mongoose_MHS; May 20th, 2024 at 06:34 PM.
    Monroe High School.. GO HORNETS!

    If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that

  11. #51

    Thread Starter
    Addicted Member Mongoose_MHS's Avatar
    Join Date
    May 2024
    Posts
    187

    Re: Menu Icons

    I can't figure it out... Here is the newest. The 3rd submenu in form2 is not working properly, everything else does as far as I can see. Going out to a movie with friends, bbl
    Attached Files Attached Files
    Monroe High School.. GO HORNETS!

    If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that

  12. #52
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    6,837

    Re: Menu Icons

    Alright I'm pretty sure I didn't miss anything this time.
    Attached Files Attached Files

  13. #53

    Thread Starter
    Addicted Member Mongoose_MHS's Avatar
    Join Date
    May 2024
    Posts
    187

    Re: Menu Icons

    at a friend's house waiting for them to get ready.. So far, seems all good.. However, can I ask what the actual issue was and how to avoid them? I mean i'll have to actually look later when I get home, but in brief can you explain? I'm asking cause if I want to really expand this I would like to know so I can follow it. I'm not trying to give you hard time.. I'm trying to understand it and it's "limitations", because this is interesting and is worthy for future applications.

    * I also want to say I apprciate your help on this.. I know you didn't / don't have to.
    Last edited by Mongoose_MHS; May 20th, 2024 at 09:21 PM.
    Monroe High School.. GO HORNETS!

    If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that

  14. #54

    Thread Starter
    Addicted Member Mongoose_MHS's Avatar
    Join Date
    May 2024
    Posts
    187

    Re: Menu Icons

    This is the part I really don't get, tho it works perfectly fine..

    Code:
    Private Sub mnuSubSubMenu_Click(Index As Integer)
        Dim c As Long
        
        For c = 0 To mnuSubSubMenu.UBound
            mnuSubSubMenu(c).Checked = (Index = c)
        Next
        CheckItemByIndex 0
        UncheckItemByIndex 1
        UncheckItemByIndex 2
        For c = 0 To mnuSubSubMenu1.UBound
            mnuSubSubMenu1(c).Checked = False
        Next
        For c = 0 To mnuSubSubMenu2.UBound
            mnuSubSubMenu2(c).Checked = False
        Next
    End Sub
    
    Private Sub mnuSubSubMenu1_Click(Index As Integer)
        Dim c As Long
        
        For c = 0 To mnuSubSubMenu1.UBound
            mnuSubSubMenu1(c).Checked = (Index = c)
        Next
        CheckItemByIndex 1
        UncheckItemByIndex 0
        UncheckItemByIndex 2 'Why is this not a "1"? Just curious..
    'and there "should be a 3rd one here" as it is another option to choose... "2"
        For c = 0 To mnuSubSubMenu.UBound
            mnuSubSubMenu(c).Checked = False
        Next
        For c = 0 To mnuSubSubMenu2.UBound
            mnuSubSubMenu2(c).Checked = False
        Next
    End Sub
    
    Private Sub mnuSubSubMenu2_Click(Index As Integer)
        Dim c As Long
        
        For c = 0 To mnuSubSubMenu2.UBound
            mnuSubSubMenu2(c).Checked = (Index = c)
        Next
        CheckItemByIndex 2
        UncheckItemByIndex 0
        UncheckItemByIndex 1 'but it is here? Just curious..
        For c = 0 To mnuSubSubMenu.UBound
            mnuSubSubMenu(c).Checked = False
        Next
        For c = 0 To mnuSubSubMenu1.UBound
            mnuSubSubMenu1(c).Checked = False
        Next
    End Sub
    i'm just at a loss because each subsubmenu is different.. yet you have it working just fine now.. Trying to wrap my head around it cause each subsubmenu is different.. It works as is.. but.. I sorta see it.. Still a lil confusing.. Sorry
    Last edited by Mongoose_MHS; May 20th, 2024 at 10:32 PM.
    Monroe High School.. GO HORNETS!

    If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that

  15. #55

    Thread Starter
    Addicted Member Mongoose_MHS's Avatar
    Join Date
    May 2024
    Posts
    187

    Re: Menu Icons

    sorry, just not getting it.. I'm trying to make logic out of it.. but
    Monroe High School.. GO HORNETS!

    If I've help you, please add to my reputation level! Each reply has a "STAR" icon followed by: "Rate this post".. click that

  16. #56
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    6,837

    Re: Menu Icons

    CheckItemByIndex (adds a checkmark)/UncheckItemByIndex (removes a checkmark if present) go by their position from the top, and you start counting from 0: 0 is the first item (Caption="Sub Menu 1"), 1 is the second item (Caption="Sub Menu 2"), and 2 is the 3rd item (Caption="Sub Menu 3").

    mnuSubSubMenu is the submenu for the first item, so we add a checkmark to it (position 0), and remove it from the second and third items (index 1 and 2)-- aka, we check 0 and uncheck 1 and 2.

    mnuSubSubMenu1 is the submenu for the second item, so we add a checkmark to position 1, and remove checkmarks from positions 0 and 2. In this sub we're checking an item belonging to position 1, so that's why we add a check with CheckItemByIndex 1 and don't remove a check with UncheckItemByIndex 1.

    mnuSubSubMenu2 is the submenu for the third item, so we add a checkmark to position 2, and remove checkmarks from positions 0 and 1. Since this is the *third* group (position 2), this time we do want to remove the checkmark from "Sub Menu 2" (position 1).

    Name:  mnucheck2.jpg
Views: 87
Size:  55.0 KB


    ---

    The issue with my first posts is that I'm only human so make mistakes sometimes, and put the wrong number in a couple places, and missed it since didn't try every possible combo, only a few.

    The central issue here to begin with is that there's no automatic management. VB will not add or remove checks unless you explicitly tell it to, on every click. So with the original code in Form_Load, all that did at first was show the concept of how to add a checkmark to a menuitem which opens a sub-sub-menu; it was hard coded to the first menu (position 0 along the top)'s first item (position 0 of the subitems). Just like when managing checkmarks with VB, you have to tell it what to do every time something is clicked. It will not automatically uncheck one item if you add a check to another (at least, with VB6 built in features), so you have to tell it not only to add a checkmark to the item you clicked, but to remove the checkmarks from any other item which shouldn't have one at that point.
    Last edited by fafalone; May 21st, 2024 at 12:54 AM.

Page 2 of 2 FirstFirst 12

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