Page 1 of 1
SetSubmenuText()
Posted: Tue May 12, 2009 11:10 am
by srod
We have SetMenuItemText() and SetMenuTitleText(), but no equivalent for setting a submenu text!
I make the request having just found a need for such a command. Using api is no problem, but still...

Posted: Tue May 12, 2009 11:21 am
by Perkin
Don't you just use SetMenuItemText with the number of the entry you want to change. Altered from the PB example.
Code: Select all
If OpenWindow(0, 200, 200, 220, 100, "SubMenu Example")
If CreateMenu(0, WindowID(0))
MenuTitle("Project")
MenuItem(1, "Open")
MenuItem(2, "Close")
MenuBar()
OpenSubMenu("Recent files") ; begin sub-menu
MenuItem( 3, "C:\Autoexec.bat")
MenuItem( 4, "D:\Test.txt")
CloseSubMenu() ; end sub-menu
EndIf
SetMenuItemText(0,4,"THIS IS CHANGED") ; <---- change the sub item text
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf
Posted: Tue May 12, 2009 11:29 am
by srod
No.
In the case of your code I wish to alter the "Recent files" text.
The only way at the moment to do this is to use api. Very simple, and a very simple addition to the PB menu library to plug what is a little hole.
Posted: Tue May 12, 2009 11:36 am
by Perkin
Apologies, now I know what you want.
I've never had need to change that text.
Yes, this would be a useful built-in command.
How do you do it with the API?

Posted: Tue May 12, 2009 11:38 am
by Perkin
Also - A (possibly?) useful command would be DisableSubMenu, to disable/enable a whole submenu.
Posted: Tue May 12, 2009 11:39 am
by Mistrel
Would this function be cross-platform? I'm not sure what you mean by "submenu text" or "recent files" so I have to ask. Would you provide an example?
Posted: Tue May 12, 2009 11:41 am
by srod
Mistrel wrote:Would this function be cross-platform? I'm not sure what you mean by "submenu text" or "recent files" so I have to ask. Would you provide an example?
Uhm look at Perkin's code!
@Perkin : here is how to use api to alter the submenu title's text. I avoid using the obsolete ModifyMenu_() :
Code: Select all
#MainMenu = 0
If OpenWindow(0, 200, 200, 220, 100, "SubMenu Example")
If CreateMenu(#MainMenu, WindowID(0))
MenuTitle("Project")
MenuItem(1, "Open")
MenuItem(2, "Close")
MenuBar()
OpenSubMenu("Recent files") ; begin sub-menu
MenuItem( 3, "C:\Autoexec.bat")
MenuItem( 4, "D:\Test.txt")
CloseSubMenu() ; end sub-menu
MenuTitle("Edit")
MenuItem(5, "Copy")
EndIf
;Change the "Recent files" submenu text.
mii.MENUITEMINFO
With mii
\cbSize = SizeOf(MENUITEMINFO)
\fMask = #MIIM_TYPE
\fType = #MFT_STRING
\dwTypeData = @"Heyho!"
EndWith
hSubMenu = GetSubMenu_(MenuID(#MainMenu), 0)
SetMenuItemInfo_(hSubmenu, 3, #True, mii)
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf
Posted: Tue May 12, 2009 12:05 pm
by Perkin
Thank srod.
Posted: Tue May 12, 2009 1:33 pm
by Berikco
This was asked a few years ago i remember, and confirmed by Fred it would be added......i guess it slipped Fred's mind

Posted: Tue May 12, 2009 2:05 pm
by srod
Berikco wrote:This was asked a few years ago i remember, and confirmed by Fred it would be added......i guess it slipped Fred's mind

Ahhh; I did a search through the Feature requests forum but could find nothing.
You have a good memory there Bericko!

Posted: Wed May 13, 2009 9:15 am
by Perkin
Perhaps a simple way to code this command, would be to have the 'OpenSubMenu' command use a MenuItemNumber as does the other menu commands, then you could access the text from the usual 'SetMenuItemText'.
Is that possible?
Posted: Thu May 14, 2009 1:50 pm
by DoubleDutch
Is the API command ModifyMenu_ now deprecated?
If so, what should you use across Win95 to Win7 that does this:
Code: Select all
ModifyMenu_(i_CurrentMenu,item,#MF_BYCOMMAND|#MF_OWNERDRAW,item,i_CurrentMenu)
Posted: Thu May 14, 2009 2:20 pm
by srod
Use SetMenuItemInfo_() which should work across the board.
Deprecated does not mean that it will not work however!

Posted: Tue Jun 09, 2009 12:14 am
by DoubleDutch
This post indirectly inspired me to add recent files to Elementary Reports:
http://forum.computingdata.com/viewtopic.php?f=3&t=162
I've done it a different way though, the menu is ownerdrawn so it's much easier to change things. The addition I made to my menusize/menudraw system is that if the text is empty, then menu item has a height of zero!
So I just setup 10 'recent files' and set the default text to "", when it's not "" then the height becomes normal and the menu item is visible.
As an added bonus I use the normal key 'thingy' (the bit after a tab) to display the date that the file was last accessed.

Re: SetSubmenuText()
Posted: Mon Dec 21, 2009 2:42 pm
by nco2k
@srod
thanks for the workaround.
c ya,
nco2k