SetSubmenuText()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

SetSubmenuText()

Post 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... :wink:
I may look like a mule, but I'm not a complete ass.
Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Post 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
%101010 = $2A = 42
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Post by Perkin »

Apologies, now I know what you want. :oops:
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
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Post by Perkin »

Also - A (possibly?) useful command would be DisableSubMenu, to disable/enable a whole submenu.
%101010 = $2A = 42
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post 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?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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
I may look like a mule, but I'm not a complete ass.
Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Post by Perkin »

Thank srod.
%101010 = $2A = 42
Berikco
Administrator
Administrator
Posts: 1326
Joined: Wed Apr 23, 2003 7:57 pm
Location: Belgium
Contact:

Post 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 ;)
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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! :)
I may look like a mule, but I'm not a complete ass.
Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Post 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?
%101010 = $2A = 42
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post 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)
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Use SetMenuItemInfo_() which should work across the board.

Deprecated does not mean that it will not work however! :wink:
I may look like a mule, but I'm not a complete ass.
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post 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. 8)
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: SetSubmenuText()

Post by nco2k »

@srod
thanks for the workaround. :)

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Post Reply