Post by 1180michel on Mar 6, 2021 6:24:02 GMT -5
Hi !
Please, do you know how to "cascade" popup menu's (putting little black arrows, do you see ?) ?
I know how to cascade "standard" menu's, thanks to Jim Brossman, but not the popup menus.
Here is is a short program, so you can understand what I mean !
And sorry for my english writing, i'm a poor french-speaking belgian :-)))
Thanks to all !
======================================================================
'Cascading Menu Demo - Jim Brossman
nomainwin
WindowWidth = 600 : WindowHeight = 300
UpperLeftX=int((DisplayWidth-WindowWidth)/2)
UpperLeftY=int((DisplayHeight-WindowHeight)/2)
'These are the menu items that will be modified to have cascading menus added.
'The label [anybranch] must be in the menu but does not need to be defined.
'You can't leave it blank.
menu #main, " &Names ",_
"Edit Names", [anybranch],_ 'Menu #0
"&Print Names", [PrintNames],_
"Find Duplicate",[anybranch]
menu #main, " &Address ", "&Edit Address", [EditAdd] 'Menu #1
menu #main, " &Tools ", "Sub Menu 1",_ 'Menu #2
[SubMenu1],"Sub Menu 2", [SubMenu2],_
"Sub Menu 3", [anybranch]
'These will be the sub menus that modify the above menus and
'add the cascading menus.
menu #main, "&Edit Names","&Add",[Add],"&Change",[Chg],_ 'Menu #3
"&Delete",[Del]
menu #main, "&Find Duplicate", "&Names", [FindDupNames],_ 'Menu #4
"&Addresses", [FindAdds]
menu #main, "&Sub Menu 1", "&Top", [Top], "&Middle", [Middle],_ 'Menu #5
"&Bottom", [Bottom]
menu #main, "&Sub Menu 2", "&First", [First], "&Second", [Second],_ 'Menu #6
"&Third", [Third]
menu #main, "&Sub Menu 3", "&One", [One], "&Two", [Two],_ 'Menu #7
"T&hree", [Three]
'These is another menu items that will not be modified.
menu #main, " &Help ", "&Help File", [HelpFile],_ 'Menu #8
"Help &About", [HelpAbout]
open "Cascading Menu Demo" for graphics as #main
#main,"when rightButtonUp [popup]"
print #main, "trapclose [Quit]"
'wait 'Unremark this line to see all menus in the window.
'Get handles of the main window, window menu and sub menus.
hMain=HWnd(#main)'Handle of main window
CallDLL #user32,"GetParent",hMain AS word,hParent AS word
' CallDll #user,"GetMenu",_
'Get the handle of the window menu into hMenu
calldll #user32, "GetMenu",hParent as ulong,hMenu as ulong
'Get the handles of the sub menus from hMenu using the Menu #
'and put the handle into hnames, htools, heditnames etc.
'We are going to modify menu #0 with menu #3 and #4
'and menu #2 with menus #5, 6 and 7.
calldll #user32, "GetSubMenu",hMenu as ulong,_
0 as long,h0 as ulong 'Get handle of the Names menu #0
calldll #user32, "GetSubMenu",hMenu as ulong,_
2 as long,h2 as ulong 'Get handle of the Tools menu #2
calldll #user32, "GetSubMenu",hMenu as ulong,_
3 as long,h3 as ulong 'Get handle of Edit Names menu #3
calldll #user32, "GetSubMenu",hMenu as ulong,_
4 as long,h4 as ulong 'Get handle of Find Duplicate menu #4
calldll #user32, "GetSubMenu",hMenu as ulong,_
5 as long,h5 as ulong 'Get handle of Sub Menu 1 menu #5
calldll #user32, "GetSubMenu",hMenu as ulong,_
6 as long,hsubmenu2 as ulong 'Get handle of Sub Menu 2 menu #6
calldll #user32, "GetSubMenu",hMenu as ulong,_
7 as long,hsubmenu3 as ulong 'Get handle of Sub Menu 3 menu #7
'Modify the submenus to add the cascading menus.
'To modify a sub menu you need the handle of the menu item from the above lines,
'the the sub menu position under the menu item,
'the handle of the sub menu to make that will make the change,
'and the new name of the sub menu.
call MenuMod h0, 0, h3, "&Edit Names"
call MenuMod h0, 2, h4, "&Find Duplicate"
call MenuMod h2, 0, h5, "Sub Menu &1"
call MenuMod htools, 1, hsubmenu2, "Sub Menu &2"
call MenuMod htools, 2, hsubmenu3, "Sub Menu &3"
'Remove all the cascading sub menus now that they have replaced the
'original ones because they still remain in the window menu.
'Remove in reverse order or numbers will be wrong because if you
'remove 3 first, #4 becomes #3, #5 becomes #4 etc.
for x=7 to 3 step -1
call MenuRemove hMenu, x
next
'You must redraw the menu bar for all the changes to take effect.
calldll #user32, "DrawMenuBar", hMain as ulong, result as long
notice "Clicking on the menu items, you can see the little black arrows, who are pointing to cascaded menus"
nomainwin
WindowWidth = 600 : WindowHeight = 300
UpperLeftX=int((DisplayWidth-WindowWidth)/2)
UpperLeftY=int((DisplayHeight-WindowHeight)/2)
'These are the menu items that will be modified to have cascading menus added.
'The label [anybranch] must be in the menu but does not need to be defined.
'You can't leave it blank.
menu #main, " &Names ",_
"Edit Names", [anybranch],_ 'Menu #0
"&Print Names", [PrintNames],_
"Find Duplicate",[anybranch]
menu #main, " &Address ", "&Edit Address", [EditAdd] 'Menu #1
menu #main, " &Tools ", "Sub Menu 1",_ 'Menu #2
[SubMenu1],"Sub Menu 2", [SubMenu2],_
"Sub Menu 3", [anybranch]
'These will be the sub menus that modify the above menus and
'add the cascading menus.
menu #main, "&Edit Names","&Add",[Add],"&Change",[Chg],_ 'Menu #3
"&Delete",[Del]
menu #main, "&Find Duplicate", "&Names", [FindDupNames],_ 'Menu #4
"&Addresses", [FindAdds]
menu #main, "&Sub Menu 1", "&Top", [Top], "&Middle", [Middle],_ 'Menu #5
"&Bottom", [Bottom]
menu #main, "&Sub Menu 2", "&First", [First], "&Second", [Second],_ 'Menu #6
"&Third", [Third]
menu #main, "&Sub Menu 3", "&One", [One], "&Two", [Two],_ 'Menu #7
"T&hree", [Three]
'These is another menu items that will not be modified.
menu #main, " &Help ", "&Help File", [HelpFile],_ 'Menu #8
"Help &About", [HelpAbout]
open "Cascading Menu Demo" for graphics as #main
#main,"when rightButtonUp [popup]"
print #main, "trapclose [Quit]"
'wait 'Unremark this line to see all menus in the window.
'Get handles of the main window, window menu and sub menus.
hMain=HWnd(#main)'Handle of main window
CallDLL #user32,"GetParent",hMain AS word,hParent AS word
' CallDll #user,"GetMenu",_
'Get the handle of the window menu into hMenu
calldll #user32, "GetMenu",hParent as ulong,hMenu as ulong
'Get the handles of the sub menus from hMenu using the Menu #
'and put the handle into hnames, htools, heditnames etc.
'We are going to modify menu #0 with menu #3 and #4
'and menu #2 with menus #5, 6 and 7.
calldll #user32, "GetSubMenu",hMenu as ulong,_
0 as long,h0 as ulong 'Get handle of the Names menu #0
calldll #user32, "GetSubMenu",hMenu as ulong,_
2 as long,h2 as ulong 'Get handle of the Tools menu #2
calldll #user32, "GetSubMenu",hMenu as ulong,_
3 as long,h3 as ulong 'Get handle of Edit Names menu #3
calldll #user32, "GetSubMenu",hMenu as ulong,_
4 as long,h4 as ulong 'Get handle of Find Duplicate menu #4
calldll #user32, "GetSubMenu",hMenu as ulong,_
5 as long,h5 as ulong 'Get handle of Sub Menu 1 menu #5
calldll #user32, "GetSubMenu",hMenu as ulong,_
6 as long,hsubmenu2 as ulong 'Get handle of Sub Menu 2 menu #6
calldll #user32, "GetSubMenu",hMenu as ulong,_
7 as long,hsubmenu3 as ulong 'Get handle of Sub Menu 3 menu #7
'Modify the submenus to add the cascading menus.
'To modify a sub menu you need the handle of the menu item from the above lines,
'the the sub menu position under the menu item,
'the handle of the sub menu to make that will make the change,
'and the new name of the sub menu.
call MenuMod h0, 0, h3, "&Edit Names"
call MenuMod h0, 2, h4, "&Find Duplicate"
call MenuMod h2, 0, h5, "Sub Menu &1"
call MenuMod htools, 1, hsubmenu2, "Sub Menu &2"
call MenuMod htools, 2, hsubmenu3, "Sub Menu &3"
'Remove all the cascading sub menus now that they have replaced the
'original ones because they still remain in the window menu.
'Remove in reverse order or numbers will be wrong because if you
'remove 3 first, #4 becomes #3, #5 becomes #4 etc.
for x=7 to 3 step -1
call MenuRemove hMenu, x
next
'You must redraw the menu bar for all the changes to take effect.
calldll #user32, "DrawMenuBar", hMain as ulong, result as long
notice "Clicking on the menu items, you can see the little black arrows, who are pointing to cascaded menus"
notice "With a right-click, you can see a popup menu. How to put little black arrows in this popup menu, to go to cascaded menus ?"
wait
'Sub to modify the sub menus and add the cascading menu.
sub MenuMod hmainmenu, position, hsubmenu, pointer$
flags = _MF_BYPOSITION Or _MF_POPUP Or _MF_STRING
calldll #user32, "ModifyMenuA",_
hmainmenu as ulong,_ 'Handle of the menu to be modified
position as long,_ 'position of the sub menu under the menu
flags as long,_ ' change using the position number
hsubmenu as ulong,_ 'hendle of sub menu to change
pointer$ as ptr,_ 'new name of the sub menu
result as long
end sub
'Sub to remove cascading menus no longer needed.
sub MenuRemove hmainmenu, position
calldll #user32, "RemoveMenu",hmainmenu as ulong,_ 'handle of window menu
position as long,_MF_BYPOSITION as long,_ 'Menu # of original cascading menu.
result as long
end sub
'These branches are here so the program doesn't crash if
'you select a menu item.
[Add] a$="Add": gosub [Notify]:wait
[Chg] a$="Change": gosub [Notify]:wait
[Del] a$="Delete": gosub [Notify]:wait
[PrintNames] a$="Print Names": gosub [Notify]:wait
[EditAdd] a$="Edit Addresses": gosub [Notify]:wait
[FindDupNames] a$="Find Duplicate Names": gosub [Notify]:wait
[FindAdds] a$="Find Duplicate Adresses": gosub [Notify]:wait
[Top] a$="Top": gosub [Notify]:wait
[Middle] a$="Middle": gosub [Notify]:wait
[Bottom] a$="Bottom": gosub [Notify]:wait
[First] a$="First": gosub [Notify]:wait
[Second] a$="Second": gosub [Notify]:wait
[Third] a$="Third": gosub [Notify]:wait
[One] a$="One": gosub [Notify]:wait
[Two] a$="Two": gosub [Notify]:wait
[Three] a$="Three": gosub [Notify]:wait
[HelpFile] a$= "Help File": gosub [Notify]:wait
[HelpAbout] a$= "Help Aboute": gosub [Notify]:wait
[Quit]
close #main
end
[Notify]
Notice "You have selected "+a$:return
[Notifys]'
Notice "You have selected popupmenu"
wait
[popup]'
popupmenu "Menupopup1",[Notifys],_
"Menupopup2",[Notifys],_
"Menupopup3",[Notifys]
wait
'Sub to modify the sub menus and add the cascading menu.
sub MenuMod hmainmenu, position, hsubmenu, pointer$
flags = _MF_BYPOSITION Or _MF_POPUP Or _MF_STRING
calldll #user32, "ModifyMenuA",_
hmainmenu as ulong,_ 'Handle of the menu to be modified
position as long,_ 'position of the sub menu under the menu
flags as long,_ ' change using the position number
hsubmenu as ulong,_ 'hendle of sub menu to change
pointer$ as ptr,_ 'new name of the sub menu
result as long
end sub
'Sub to remove cascading menus no longer needed.
sub MenuRemove hmainmenu, position
calldll #user32, "RemoveMenu",hmainmenu as ulong,_ 'handle of window menu
position as long,_MF_BYPOSITION as long,_ 'Menu # of original cascading menu.
result as long
end sub
'These branches are here so the program doesn't crash if
'you select a menu item.
[Add] a$="Add": gosub [Notify]:wait
[Chg] a$="Change": gosub [Notify]:wait
[Del] a$="Delete": gosub [Notify]:wait
[PrintNames] a$="Print Names": gosub [Notify]:wait
[EditAdd] a$="Edit Addresses": gosub [Notify]:wait
[FindDupNames] a$="Find Duplicate Names": gosub [Notify]:wait
[FindAdds] a$="Find Duplicate Adresses": gosub [Notify]:wait
[Top] a$="Top": gosub [Notify]:wait
[Middle] a$="Middle": gosub [Notify]:wait
[Bottom] a$="Bottom": gosub [Notify]:wait
[First] a$="First": gosub [Notify]:wait
[Second] a$="Second": gosub [Notify]:wait
[Third] a$="Third": gosub [Notify]:wait
[One] a$="One": gosub [Notify]:wait
[Two] a$="Two": gosub [Notify]:wait
[Three] a$="Three": gosub [Notify]:wait
[HelpFile] a$= "Help File": gosub [Notify]:wait
[HelpAbout] a$= "Help Aboute": gosub [Notify]:wait
[Quit]
close #main
end
[Notify]
Notice "You have selected "+a$:return
[Notifys]'
Notice "You have selected popupmenu"
wait
[popup]'
popupmenu "Menupopup1",[Notifys],_
"Menupopup2",[Notifys],_
"Menupopup3",[Notifys]
wait