Got an idea for enhancing PureBasic? New command(s) you'd like to see?
srod
PureBasic Expert
Posts: 10589 Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...
Post
by srod » Tue May 12, 2009 11:10 am
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...
I may look like a mule, but I'm not a complete ass.
Perkin
Enthusiast
Posts: 504 Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK
Post
by Perkin » Tue May 12, 2009 11:21 am
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
%101010 = $2A = 42
srod
PureBasic Expert
Posts: 10589 Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...
Post
by srod » Tue May 12, 2009 11:29 am
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.
I may look like a mule, but I'm not a complete ass.
Perkin
Enthusiast
Posts: 504 Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK
Post
by Perkin » Tue May 12, 2009 11:36 am
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?
%101010 = $2A = 42
Perkin
Enthusiast
Posts: 504 Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK
Post
by Perkin » Tue May 12, 2009 11:38 am
Also - A (possibly?) useful command would be DisableSubMenu, to disable/enable a whole submenu.
%101010 = $2A = 42
Mistrel
Addict
Posts: 3415 Joined: Sat Jun 30, 2007 8:04 pm
Post
by Mistrel » Tue May 12, 2009 11:39 am
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?
srod
PureBasic Expert
Posts: 10589 Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...
Post
by srod » Tue May 12, 2009 11:41 am
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
I may look like a mule, but I'm not a complete ass.
Perkin
Enthusiast
Posts: 504 Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK
Post
by Perkin » Tue May 12, 2009 12:05 pm
Thank srod.
%101010 = $2A = 42
Berikco
Administrator
Posts: 1326 Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:
Post
by Berikco » Tue May 12, 2009 1:33 pm
This was asked a few years ago i remember, and confirmed by Fred it would be added......i guess it slipped Fred's mind
srod
PureBasic Expert
Posts: 10589 Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...
Post
by srod » Tue May 12, 2009 2:05 pm
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!
I may look like a mule, but I'm not a complete ass.
Perkin
Enthusiast
Posts: 504 Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK
Post
by Perkin » Wed May 13, 2009 9:15 am
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?
%101010 = $2A = 42
DoubleDutch
Addict
Posts: 3220 Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:
Post
by DoubleDutch » Thu May 14, 2009 1:50 pm
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)
srod
PureBasic Expert
Posts: 10589 Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...
Post
by srod » Thu May 14, 2009 2:20 pm
Use SetMenuItemInfo_() which should work across the board.
Deprecated does not mean that it will not work however!
I may look like a mule, but I'm not a complete ass.
DoubleDutch
Addict
Posts: 3220 Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:
Post
by DoubleDutch » Tue Jun 09, 2009 12:14 am
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.
nco2k
Addict
Posts: 1344 Joined: Mon Sep 15, 2003 5:55 am
Post
by nco2k » Mon Dec 21, 2009 2:42 pm
@srod
thanks for the workaround.
c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf