How to change title of SubMenu item ???
How to change title of SubMenu item ???
It suppose to be an easy question but... How it is possible to change title of SubMenu (!) item created with OpenSubMenu ?
I could change main menu items text with SetMenuTitleText, I could change text for items in that menu with SetMenuItemText...
But if I've got a case when I created another SubMenu then I am getting strange situation - I could change text of items in that submenu,
but I can't change text for submenu setting itself.... Please advice...
I could change main menu items text with SetMenuTitleText, I could change text for items in that menu with SetMenuItemText...
But if I've got a case when I created another SubMenu then I am getting strange situation - I could change text of items in that submenu,
but I can't change text for submenu setting itself.... Please advice...
- RSBasic
- Moderator
- Posts: 1218
- Joined: Thu Dec 31, 2009 11:05 pm
- Location: Gernsbach (Germany)
- Contact:
Re: How to change title of SubMenu item ???
Code: Select all
EnableExplicit
Define SubMenu
If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If CreateMenu(1, WindowID(0))
MenuTitle("Menu")
SubMenu = OpenSubMenu("New")
MenuItem(1, "File")
MenuItem(2, "Folder")
CloseSubMenu()
SetMenuItemText(1, SubMenu, "Open")
EndIf
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
EndIf
\\Edit:
Only for Windows.
Re: How to change title of SubMenu item ???
Only Windows
Don´t work on MacOS
Don´t work on MacOS
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: How to change title of SubMenu item ???
From PB-Help:
OpenSubMenu(Text$ [, ImageID])
...
Return value
None.
Regards, Charly
PureBasic 5.4-5.7, Linux: (X/L/K)Ubuntus+Mint - Windows XP (32Bit)
PureBasic Linux-API-Library & Viewer: http://www.chabba.de
PureBasic Linux-API-Library & Viewer: http://www.chabba.de
Re: How to change title of SubMenu item ???
That seems to be a undocumented feature. The only way I know, is to close and re-create the whole menu with the other title...RSBasic wrote:Code: Select all
SubMenu = OpenSubMenu("New")
Re: How to change title of SubMenu item ???
Look like for now I would just have to avoid using SubMenu option at all
until solution would be implemented in future versions of PB.
until solution would be implemented in future versions of PB.
Re: How to change title of SubMenu item ???
mhs wrote:... is to close and re-create the whole menu with the other title...
Code: Select all
EnableExplicit
Procedure m_Menu(Title.s)
If IsMenu(1) : FreeMenu(1) : EndIf
If CreateMenu(1, WindowID(0))
MenuTitle("Menu")
OpenSubMenu(Title)
MenuItem(1, "File")
MenuItem(2, "Folder")
CloseSubMenu()
EndIf
Debug "Menu created"
EndProcedure
If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
m_Menu("New")
AddWindowTimer(0, 1, 5000)
Repeat
Select WaitWindowEvent()
Case #PB_Event_Timer
m_Menu("Open")
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
EndIf
Re: How to change title of SubMenu item ???
Which is a totally ridiculous and impractical way to do it (not blaming you, mhs). An official command to change it would be best.mhs wrote:The only way I know, is to close and re-create the whole menu with the other title...
Re: How to change title of SubMenu item ???
I know that it's ridiculous
I would also prefer an official command, but if it's the only way at the moment... better than nothing. And my example shows that it's not impractical, depending on the requirements...
Is there a feature request?
I would also prefer an official command, but if it's the only way at the moment... better than nothing. And my example shows that it's not impractical, depending on the requirements...
Is there a feature request?
Re: How to change title of SubMenu item ???
Also, as I mentioned in another thread, recreating a menu can fail if there's not enough memory at the time. Granted, this is a low possibility, but still there -- it happens to me with my laptop with 4 GB of RAM at times, because I have a bucketload of apps and things happening most of the time.
Re: How to change title of SubMenu item ???
I played around just for fun by changing the menu completely with fictive words when clicking on the Refresh button, to see if there is a performance slow down. On my computer it is immediate, so it looks good. On Windows, it is necessary to use the API LockWindowUpdate_() to avoid flashing.
Dude said he had memory problems when modifying a menu... Does a menu use so much memory? I hope that you did remove the menu before re-creating a new one?
Code: Select all
Procedure.s CW(); Create Word
C.s="bcdfghjklmnprstvwxz"
V.s="aeiou"
Syl=Random(5,2)
For i=1 To Syl
Wd.s+Mid(C,Random(Len(C),1),1)+Mid(V,Random(Len(V),1),1)
Next i
Wd.s=UCase(Left(Wd,1))+Right(Wd,Len(Wd)-1)
ProcedureReturn Wd
EndProcedure
Procedure MenuA(Win,M)
If IsMenu(M) : FreeMenu(M) : EndIf
If CreateMenu(M,WindowID(Win))
MenuTitle(CW()); first item on the menu bar
OpenSubMenu(CW())
For i=1 To 20
MenuItem(i,CW())
Next i
CloseSubMenu()
OpenSubMenu(CW())
For i=1 To 20
MenuItem(i,CW())
Next i
CloseSubMenu()
OpenSubMenu(CW())
For i=1 To 20
MenuItem(i,CW())
Next i
CloseSubMenu()
OpenSubMenu(CW())
For i=1 To 20
MenuItem(i,CW())
Next i
CloseSubMenu()
MenuTitle(CW()); second item on the menu bar
OpenSubMenu(CW())
For i=1 To 20
MenuItem(i,CW())
Next i
CloseSubMenu()
OpenSubMenu(CW())
For i=1 To 20
MenuItem(i,CW())
Next i
CloseSubMenu()
OpenSubMenu(CW())
For i=1 To 20
MenuItem(i,CW())
Next i
CloseSubMenu()
OpenSubMenu(CW())
For i=1 To 20
MenuItem(i,CW())
Next i
CloseSubMenu()
OpenSubMenu(CW())
For i=1 To 20
MenuItem(i,CW())
Next i
CloseSubMenu()
MenuTitle(CW()); third item on the menu bar
OpenSubMenu(CW())
For i=1 To 20
MenuItem(i,CW())
Next i
CloseSubMenu()
OpenSubMenu(CW())
For i=1 To 20
MenuItem(i,CW())
Next i
CloseSubMenu()
OpenSubMenu(CW())
For i=1 To 20
MenuItem(i,CW())
Next i
CloseSubMenu()
OpenSubMenu(CW())
For i=1 To 20
MenuItem(i,CW())
Next i
CloseSubMenu()
OpenSubMenu(CW())
For i=1 To 20
MenuItem(i,CW())
Next i
CloseSubMenu()
MenuTitle(CW()); fourth item on the menu bar
OpenSubMenu(CW())
For i=1 To 20
MenuItem(i,CW())
Next i
CloseSubMenu()
OpenSubMenu(CW())
For i=1 To 20
MenuItem(i,CW())
Next i
CloseSubMenu()
OpenSubMenu(CW())
For i=1 To 20
MenuItem(i,CW())
Next i
CloseSubMenu()
OpenSubMenu(CW())
For i=1 To 20
MenuItem(i,CW())
Next i
CloseSubMenu()
OpenSubMenu(CW())
For i=1 To 20
MenuItem(i,CW())
Next i
CloseSubMenu()
EndIf
EndProcedure
If OpenWindow(3, 0, 0, 800, 600, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(2,650,500,80,30,"Refresh")
MenuA(3,1)
Repeat
Event=WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case 2
LockWindowUpdate_(WindowID(3))
MenuA(3,1)
LockWindowUpdate_(0)
EndSelect
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
EndIf
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
Re: How to change title of SubMenu item ???
You can create 2 Menus with different text and switch between when you need
No free and recreate ,No lag time,No flicker
It is always there
I do not know if this trick will work with Mac or not
Oh I like Windows for such things (I can do what I want at any time)
Unless Danilo or Shardik can come with a solution for Linux & Mac
No free and recreate ,No lag time,No flicker
It is always there
I do not know if this trick will work with Mac or not
Oh I like Windows for such things (I can do what I want at any time)
Unless Danilo or Shardik can come with a solution for Linux & Mac
Code: Select all
If OpenWindow(0, 0, 0, 300, 300, "PureBasic - Menu",#PB_Window_SystemMenu| #PB_Window_ScreenCentered)
ButtonGadget(0,10,240,60,25,"Switch")
If CreateMenu(0, WindowID(0))
MenuTitle("File")
MenuItem( 1, "&Load...")
MenuItem( 2, "Save")
MenuItem( 3, "Save As...")
MenuBar()
OpenSubMenu("Recents")
MenuItem( 5, "Pure.png")
MenuItem( 6, "Basic.jpg")
OpenSubMenu("Even more !")
MenuItem( 12, "Yeah")
CloseSubMenu()
MenuItem( 13, "Rocks.tga")
CloseSubMenu()
MenuBar()
MenuItem( 7, "&Quit")
MenuTitle("Edition")
MenuItem( 8, "Cut")
MenuItem( 9, "Copy")
MenuItem(10, "Paste")
MenuTitle("?")
MenuItem(11, "About")
EndIf
If CreateMenu(1, WindowID(0))
MenuTitle("File")
MenuItem( 1, "&Load...")
MenuItem( 2, "Save")
MenuItem( 3, "Save As...")
MenuBar()
OpenSubMenu("Recents #2")
MenuItem( 5, "Pure.png")
MenuItem( 6, "Basic.jpg")
OpenSubMenu("Even more ! #2")
MenuItem( 12, "Yeah")
CloseSubMenu()
MenuItem( 13, "Rocks.tga")
CloseSubMenu()
MenuBar()
MenuItem( 7, "&Quit")
MenuTitle("Edition")
MenuItem( 8, "Cut")
MenuItem( 9, "Copy")
MenuItem(10, "Paste")
MenuTitle("?")
MenuItem(11, "About")
EndIf
HideMenu(1,1)
HideMenu(0,0)
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case 0
Run ! 1
If Run = 1
HideMenu(0,1)
HideMenu(1,0)
Else
HideMenu(1,1)
HideMenu(0,0)
EndIf
EndSelect
Case #PB_Event_Menu
Select EventMenu() ; To see which menu has been selected
Case 1
Debug "Item 1"
Case 11 ; About
MessageRequester("About", "Cool Menu example", 0)
Default
MessageRequester("Info", "MenuItem: "+Str(EventMenu()), 0)
EndSelect
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until Quit = 1
EndIf
End
Egypt my love
Re: How to change title of SubMenu item ???
No, I said low memory can be problematic but the actual possibility of that is low.charvista wrote:Dude said he had memory problems when modifying a menu
It depends on how big it is, and how many icons are used for the items. Menus can be massive.charvista wrote:Does a menu use so much memory?
Re: How to change title of SubMenu item ???
Don't use LockWindowUpdate()...charvista wrote:On Windows, it is necessary to use the API LockWindowUpdate_() to avoid flashing.
http://blogs.msdn.com/b/oldnewthing/arc ... 52612.aspx
http://blogs.msdn.com/b/oldnewthing/arc ... 16211.aspx
http://blogs.msdn.com/b/oldnewthing/arc ... 26880.aspx
http://blogs.msdn.com/b/oldnewthing/arc ... 35472.aspx
http://blogs.msdn.com/b/oldnewthing/arc ... 42084.aspx
http://blogs.msdn.com/b/oldnewthing/arc ... 47713.aspx
Use SetWindowRedraw_(hWnd, #False) instead.
Re: How to change title of SubMenu item ???
Very interesting! Thanks a lot for the information kenmo!kenmo wrote:Don't use LockWindowUpdate()...charvista wrote:On Windows, it is necessary to use the API LockWindowUpdate_() to avoid flashing.
http://blogs.msdn.com/b/oldnewthing/arc ... 52612.aspx
http://blogs.msdn.com/b/oldnewthing/arc ... 16211.aspx
http://blogs.msdn.com/b/oldnewthing/arc ... 26880.aspx
http://blogs.msdn.com/b/oldnewthing/arc ... 35472.aspx
http://blogs.msdn.com/b/oldnewthing/arc ... 42084.aspx
http://blogs.msdn.com/b/oldnewthing/arc ... 47713.aspx
Use SetWindowRedraw_(hWnd, #False) instead.
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%