Page 1 of 1

MenuItem(#PB_Any, ...)

Posted: Fri Feb 25, 2011 11:14 pm
by HeX0R
I created an include, where i wanted to do anything dynamically to not interfere with any mainprogram.
Then i recognized, that it is not possible to create dynamic MenuItems...!?

Re: MenuItem(#PB_Any, ...)

Posted: Fri Feb 25, 2011 11:32 pm
by STARGÅTE
+1

and same like:
FreeMenuItem() oder RemoveMenuItem(), to delete one Item, and not the whole Menu and create all others new.

Re: MenuItem(#PB_Any, ...)

Posted: Sat Feb 26, 2011 5:22 am
by netmaestro
On Windows, menu items must fit in an usignedword-sized variable (Purebasic .u). One approach could be 0-32767 are available static menuitem #'s and #PB_Any would select from 32768-66535. Workable and probably useful for Windows, imho. No idea on other OS's.
STARGÅTE wrote:and same like:
FreeMenuItem() oder RemoveMenuItem(), to delete one Item, and not the whole Menu and create all others new.
Entirely different topic, no?

Re: MenuItem(#PB_Any, ...)

Posted: Sat Feb 26, 2011 5:36 am
by MachineCode
netmaestro wrote:#PB_Any would select from 32768-66535
You mean 65535, yes? ;)

Re: MenuItem(#PB_Any, ...)

Posted: Sat Feb 26, 2011 5:40 am
by netmaestro
yep.

Re: MenuItem(#PB_Any, ...)

Posted: Sat Feb 26, 2011 5:58 am
by ts-soft
WorkAround:

Code: Select all

EnableExplicit

Procedure MyMenuitem(ID, Text.s, ImageID = 0)
  Static Dim IDs(65535)
  Protected I
  If ID <> #PB_Any
    If IDs(ID) <> 1
      MenuItem(ID, Text, ImageID)
      IDs(ID) = 1
      ProcedureReturn #True
    Else
      ProcedureReturn #False
    EndIf
  Else
    For I = 65535 To 0 Step -1
      If IDs(I) = 0
        IDs(I) = 1
        MenuItem(I, Text, ImageID)
        ProcedureReturn I
      EndIf
    Next
    ProcedureReturn #False
  EndIf
EndProcedure

Macro MenuItem(a, b, c = 0)
  MyMenuitem(a, b, c)
EndMacro

Define mnuSave, mnuClose
OpenWindow(0, #PB_Ignore, #PB_Ignore, 640, 480, "")
If CreateMenu(0, WindowID(0))
  MenuTitle("Project")
  MenuItem(1, "Open")
  mnuSave = MenuItem(#PB_Any, "Save")
  MenuItem(3, "Save as"+Chr(9)+"Ctrl+A")
  mnuClose = MenuItem(#PB_Any, "Close")
EndIf

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow : Break
    Case #PB_Event_Menu
      Select EventMenu()
        Case 1 : Debug "Open"
        Case 3 : Debug "Save As"
        Case mnuSave : Debug "Save"
        Case mnuClose : Debug "Close"
      EndSelect
  EndSelect
ForEver
Is not native, but better as nothing

Greetings - Thomas