This is interesting to me.. I know you can have menu and sub menu icons. However, Based on the menu item it will have an icon that you are currently viewing. I'll have to come up with a screenshot of what I mean. This is interesting to me tho. I just figured I would throw it out there as an idea.
Last edited by Mongoose_MHS; May 19th, 2024 at 03:50 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
Like.. If you have a menu that has a few options and select one.. then go back to select another option, it will have an icon infront of the one currently being used or displayed. Not just an icon for every option just 1 for the current if anyone knows what I mean. Like a checkmark or a dot.
Last edited by Mongoose_MHS; May 14th, 2024 at 08:24 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
Cool, but can you have it so that only the current menu has a checkmark? So, if you click one item it will have it and if you select another item it will have it instead?
The concept is simple enough. Handle the click event of the menu items and inside the event handler check if the menu item is checked. If it is then loop over every other menu item to uncheck the currently iterated control.
Mongoose, it's entirely up to you how you handle a menu item's "checked" property, or which menu items put a checkmark on which other menu items. This is all standard VB6 menu stuff, no APIs no nothing but the standard properties.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
Cool, but can you have it so that only the current menu has a checkmark? So, if you click one item it will have it and if you select another item it will have it instead?
Easy. Example with a submenu array.
Code:
Private Sub Submenu1_Click(Index As Integer)
Dim c As Long
For c = 0 To Submenu1.UBound
If c = Index Then
Submenu1(c).Checked = True
Else
Submenu1(c).Checked = False
End If
Next
End Sub
Ok, so I gave it a whirl and i think it's a success! Granted it's probably NOT the right way of doing it.. However, I did manage to accomplish it.. So, hence my very first project! YAY!
I used a "shape" and "fill color".. You can make the shape visible OR hide it off the form.. But, hey it works!
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
Private Sub Submenu1_Click(Index As Integer)
Dim c As Long
For c = 0 To Submenu1.UBound
If c = Index Then
Submenu1(c).Checked = True
Else
Submenu1(c).Checked = False
End If
Next
End Sub
Awesome! His code works a lot better than mine and a lot shorter.. Well, I gave it a shot and it worked but definately not as good as his.. However, I did make something work.. That's worth "something", I think. I learned to add a sound tho! That's a plus!
Last edited by Mongoose_MHS; May 15th, 2024 at 06:16 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
I do have a question tho for you.. Is it possible to carry that setting to another form that has the same exact menu options. The reason is not to unload the other form to revert back to the first form. I hope that makes sense. Cause if I close one form to open another form with the same menu, I don't want to exit out from the second form to go back to the first form. I hope that makes sense. If not i'll try to make it more understandable.
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
Private Sub Submenu1_Click(Index As Integer)
Dim c As Long
For c = 0 To Submenu1.UBound
If c = Index Then
Submenu1(c).Checked = True
Form2.Submenu1(c).Checked = Submenu1(c).Checked 'Added
Else
Submenu1(c).Checked = False
End If
Next
End Sub
or
Code:
Private Sub Submenu1_Click(Index As Integer)
Dim c As Long
For c = 0 To Submenu1.UBound
If c = Index Then
Submenu1(c).Checked = True
Form2.Submenu1(c).Checked = Submenu1(c).Checked 'Added
Else
Form2.Submenu1(c).Checked = Submenu(c).unchecked 'Just a thought
End If
Next
End Sub
If I am assuming wrong, can you please add another form in the zip so I can see it being done?
Last edited by Mongoose_MHS; May 15th, 2024 at 06:42 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
Private Sub Submenu1_Click(Index As Integer)
Dim c As Long
For c = 0 To Submenu1.UBound
Submenu1(c).Checked = (Index = c)
Form2.Submenu1(c).Checked = Submenu1(c).Checked
Next
End Sub
Adjusted, and it works so far.. Now, I have to do the samething to form2..
Code:
Option Explicit
Private Sub Submenu1_Click(Index As Integer)
Dim c As Long
For c = 0 To Submenu1.UBound
Submenu1(c).Checked = (Index = c)
Form2.Submenu1(c).Checked = Submenu1(c).Checked
Next
Unload Me 'Added
Form2.Show vbModal 'Added
End Sub
Edit: Works perfectly fine in both forms.. Thank you Eduardo!
Last edited by Mongoose_MHS; May 15th, 2024 at 07:45 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
Now, I don't know if it's just me and my PC as to why there is a blue bgcolor with checkmark.. When i though it would be just the checkmark. I can deal with it.. Just curious as to why there is a blue bg to it.
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
Actually, I want to extend this even further.. So, I can CAN have what is done above.. However, now I want to try to have BOTH the main selection AND a SUB menu selection.. BOTH having the checkmark.. I am currently working on that. If you can beat me to it as I am new.. go for it cause I would love to see this in action. Again, I am currently working on it but I don't know how far I'll get at my pace.
I would post a pic, but obviously I haven't gotten that far yet.. If I get there I will tho. and I wanted a "simple" project for school... So much for that lol
Last edited by Mongoose_MHS; May 16th, 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
I think it can't be done to have a Submenu AND a SubSubMenu checked cause I the Submenu is not being checked - It just opens to the SubSubmenu.. I gave it a shot. The reason I wanted to try this is because I wanted to see which Submenu I'm in and then open the SubSubmenu to see which one I was on. Oh well, so much for that.
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
Ok, so what I wanted to do was have BOTH submenu AND subsubmenu checked, However, I realized that the "Submenu" cannot be "checked". I have tried. So, I am asking if there is a way to have both with a checkmark? Or is that a no go?
Last edited by Mongoose_MHS; May 18th, 2024 at 09:32 PM.
Reason: spelling
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
That's just a limitation of VB6, not menus themselves, if you wanted to pursue managing it by API with CheckMenuItem.
For example, to check the first subitem of the first menu like in the picture;
Code:
Option Explicit
Private Enum LongPtr
vbNullPtr
End Enum
Private Enum MenuFlags
MF_INSERT = &H0
MF_ENABLED = &H0
MF_UNCHECKED = &H0
MF_BYCOMMAND = &H0
MF_STRING = &H0
MF_UNHILITE = &H0
MF_GRAYED = &H1
MF_DISABLED = &H2
MF_BITMAP = &H4
MF_CHECKED = &H8
MF_POPUP = &H10
MF_MENUBARBREAK = &H20
MF_MENUBREAK = &H40
MF_HILITE = &H80
MF_CHANGE = &H80
MF_END = &H80 ' Obsolete -- only used by old RES files
MF_APPEND = &H100
MF_OWNERDRAW = &H100
MF_DELETE = &H200
MF_USECHECKBITMAPS = &H200
MF_BYPOSITION = &H400
MF_SEPARATOR = &H800
MF_REMOVE = &H1000
MF_DEFAULT = &H1000
MF_SYSMENU = &H2000
MF_HELP = &H4000
MF_RIGHTJUSTIFY = &H4000
MF_MOUSESELECT = &H8000&
End Enum
Private Declare Function CheckMenuItem Lib "user32" (ByVal hMenu As LongPtr, ByVal uIDCheckItem As Long, ByVal uCheck As MenuFlags) As Long
Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As LongPtr, ByVal nPos As Long) As LongPtr
Private Declare Function GetMenu Lib "user32" (ByVal hWnd As LongPtr) As LongPtr
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
Note that this is outside of VB's knowledge; it won't changed the .Checked property because VB doesn't know you've made the change from outside. So if you're doing it this way to reliably determine whether it's checked, you'd also have to use API...
Private Declare Function GetMenuState Lib "user32" (ByVal hMenu As LongPtr, ByVal uID As Long, ByVal uFlags As MenuFlags) As Long
If GetMenuState(hSubmenu, 0, MF_BYPOSITION) And MF_CHECKED Then
(it's checked)
Last edited by fafalone; May 19th, 2024 at 02:12 AM.
Note that this is outside of VB's knowledge; it won't changed the .Checked property because VB doesn't know you've made the change from outside. So if you're doing it this way to reliably determine whether it's checked, you'd also have to use API...
Code:
Private Declare Function GetMenuState Lib "user32" (ByVal hMenu As LongPtr, ByVal uID As Long, ByVal uFlags As MenuFlags) As Long
If GetMenuState(hSubmenu, 0, MF_BYPOSITION) And MF_CHECKED Then 'You stopped here, so how can I uise it if the statement is not complete?
(it's checked)
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
*I see how this is working out.. Lengthy process. However, I think it will work out just fine. Let me work on this a bit and I'll post up a zip when I'm finish. Give me some time, as I do not sit at my PC for long periods of time in one sitting.
Last edited by Mongoose_MHS; May 19th, 2024 at 02:24 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
Ok, I "thought" I had this figured out.. Somehow I don't.. So, the first submenu works with it's subsubmenu's.. the other subsubmenu's do too.. However, the 1st submenu stays checked and not the other 2.. Can you have a look and tell me what I am missing as I just can't forsee it.
Last edited by Mongoose_MHS; May 19th, 2024 at 03:44 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
I'm having trouble following what you're even trying to do there... you've got two separate forms with their menus jumbled together.
But which one are you talking about stays checked? The one set by API? There's no code I can see even attempting to determine which of "Sub Menu 1" "Sub Menu 2" or "Sub Menu 3" is checked; just the code I wrote that checks "Sub Menu 1"; it's not looking up what's checked. You'd change it to CheckMenuItem hSubmenu, 1, MF_BYPOSITION Or MF_CHECKED to check "Sub Menu 2" instead, and CheckMenuItem hSubmenu, 2, MF_BYPOSITION Or MF_CHECKED to check "Sub Menu 3".
One problem I see you're going to run into with trying is on Form2 you have mnuSubMenu(0), mnuSubMenu1(1), and mnuSubMenu2(2); I think that's just an unintentional error because you've set up the sub-sub-menu control arrays right and the sub-menus on Form1 right.
SubMenu 'this has to stay blank - this stays checked in form 2 'this one is the only one that stays checked
...SubSubMenu 0 'and stays checked 'works fine
...SubSubMenu 1 'and stays checked 'works fine
Submenu1 'this has to have a number to differ - this DOESN'T stay checked in form 2why?
...SubSubMenu0 'and stays checked works fine
...SubSubmenu1 'and stays cheked 'works fine
Submenu2 'this has to have a number to differ this has to have a number to differ - this DOESN'T stay checked in form 2WHY?
...SubSubMenu 0 'and stays checked works fine
...SubSubmenu 1 'and stays checked works fine
You have the code to see the menu editor.. but something like that as I am just typing freehanded..... This is what i'm trying to figure out..
Last edited by Mongoose_MHS; May 19th, 2024 at 04:48 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
It's the SUBMENUS (2 and 3) that don't stay checked, always the first one... all the SUBSUBMENUS work just fine... why is the 1st SUBMENU always checked and not the other 2 is my question..
*Menus on both forms SHOULD be identical as you are NOT reverting back to form 1.. so form 2 will continue with choices. Form1 is just a starting point.. You "can revert back to it later, but once form2 loads.. it will handle selections. and "IF" you do revert back to form1.. then back to start on selections.
Last edited by Mongoose_MHS; May 19th, 2024 at 04:54 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
Stays (or doesn't) when what happens? You set the check states once from Form1 then unload it; there's no code to change check states in Form2. If I change the API to check "Sub Menu 2" instead, it stays checks no matter what I click. So doesn't stay checked when.... what?
*Menus on both forms SHOULD be identical as you are NOT reverting back to form 1.. so form 2 will continue with choices. Form1 is just a starting point.. You "can revert back to it later, but once form2 loads.. it will handle selections. and "IF" you do revert back to form1.. then back to start on selections.
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
It's the SUBMENUS (2 and 3) that don't stay checked, always the first one... all the SUBSUBMENUS work just fine... why is the 1st SUBMENU always checked and not the other 2 is my question..
*Menus on both forms SHOULD be identical as you are NOT reverting back to form 1.. so form 2 will continue with choices. Form1 is just a starting point.. You "can revert back to it later, but once form2 loads.. it will handle selections. and "IF" you do revert back to form1.. then back to start on selections.
The code example I gave you checks the first item (index 0). See the middle paragraph of post #32.
Private Sub CheckItemByIndex(n As Long)
Dim hMenu As LongPtr
Dim hSubmenu As LongPtr
hMenu = GetMenu(Me.hWnd)
hSubmenu = GetSubMenu(hMenu, 0)
CheckMenuItem hSubmenu, n, MF_BYPOSITION Or MF_CHECKED
End Sub
CheckItemByIndex 0 - Checks "Sub Menu 1" of the Form the code is in. CheckItemByIndex 1 - Checks "Sub Menu 2" of the Form the code is in. CheckItemByIndex 2 - Checks "Sub Menu 3" of the Form the code is in.
Code:
Private Sub UncheckItemByIndex(n As Long)
Dim hMenu As LongPtr
Dim hSubmenu As LongPtr
hMenu = GetMenu(Me.hWnd)
hSubmenu = GetSubMenu(hMenu, 0)
CheckMenuItem hSubmenu, n, MF_BYPOSITION Or MF_UNCHECKED
End Sub
UncheckItemByIndex 0 - Unchecks "Sub Menu 1" of the Form the code is in. UncheckItemByIndex 1 - Unchecks "Sub Menu 2" of the Form the code is in. UncheckItemByIndex 2 - Unchecks "Sub Menu 3" of the Form the code is in.
I'm not using "hSubMenu" and such.. You're just confusing me.. please make a working demo and point out what I did wrong in notes so I can learn... Because I have tried with failure and I really tried. Sorry, but I just don't get it. My menus are fine and match..
Last edited by Mongoose_MHS; May 19th, 2024 at 05:43 PM.
Reason: spelling
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