Page 1 of 1
Posted: Mon Jan 27, 2003 11:29 am
by BackupUser
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?
Posted: Mon Jan 27, 2003 1:01 pm
by BackupUser
Restored from previous forum. Originally posted by Pupil.
You could do it with the WIN API command ModifyMenu(). I think there's a code snipp on the forum that might help you with that particular API command.
Posted: Mon Jan 27, 2003 4:16 pm
by BackupUser
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:
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
Posted: Wed Jan 29, 2003 5:01 pm
by BackupUser
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