MenuItem(#PB_Any, ...)

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
HeX0R
Addict
Addict
Posts: 1189
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

MenuItem(#PB_Any, ...)

Post 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...!?
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: MenuItem(#PB_Any, ...)

Post by STARGÅTE »

+1

and same like:
FreeMenuItem() oder RemoveMenuItem(), to delete one Item, and not the whole Menu and create all others new.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: MenuItem(#PB_Any, ...)

Post 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?
BERESHEIT
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: MenuItem(#PB_Any, ...)

Post by MachineCode »

netmaestro wrote:#PB_Any would select from 32768-66535
You mean 65535, yes? ;)
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: MenuItem(#PB_Any, ...)

Post by netmaestro »

yep.
BERESHEIT
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: MenuItem(#PB_Any, ...)

Post 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
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply