Restored from previous forum. Originally posted by geoff.
How do I change the text of a menu item?
I tried:
MenuItem(ItemNumber,"New Text")
But that didn't work.
Do I have to free the whole menu and create a new one?
Change Menu Item?
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by freak.
The Code snip here is only about the Check Marks at Items, but that is implemented in PB now.
Here is what you need:
The Code snip here is only about the Check Marks at Items, but that is implemented in PB now.
Here is what you need:
Code: Select all
; change Text of a Menu Item
OpenWindow(0, 0,0, 100, 100, #PB_Window_Screencentered|#PB_Window_SystemMenu, "Menu")
hMenu.l = CreateMenu(1, WindowID()) ; you need to save the Handle to the Menu like this.
MenuTitle("Test")
MenuItem(5, "Click to change...") ; add an Item (Number doesn't matter)
Repeat
Select WaitWindowEvent()
Case #PB_Eventclosewindow: End
Case #PB_EventMenu ; Item was clicked.
Text.s = "changed." ; new Text
ModifyMenu_(hMenu, 5, #MF_BYCOMMAND | #MF_STRING, 0, @Text)
; Set new Text:
; fist one is the Handle you got from CreateMenu()
; second one is the Item Number from MenuItem()
; last one is the String Pointer
; the other ones just need to be like that.
EndSelect
ForEver
Hope this helps...
Timo
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by geoff.
Thanks for your code, complete with useful comments.
I rely heavily on changing menu items so this gets me out of a hole.
I didn't reply before because I've been installing OS and drivers
on a new computer. It hasn't been straightforward.
Thanks, Geoff
Thanks for your code, complete with useful comments.
I rely heavily on changing menu items so this gets me out of a hole.
I didn't reply before because I've been installing OS and drivers
on a new computer. It hasn't been straightforward.
Thanks, Geoff