Page 1 of 2
Some menu issues (PB4)
Posted: Tue Jul 25, 2006 6:48 pm
by Edwin Knoppert
In v3.x i could use PB_ANY with createmenu() and then an unique handle was returned to eventually set items disabled and such.
Somehow v4 does not like PB_ANY and i had to use a hardcoded ID.
the issue is that i prepare form creation code which might be used multiple times.
Imagne two windows using the same menu code and the menu is set to id 0.
Will this go wrong?
How to distinguish?
For modularity reasons numbering the menu's in run-time and possibly getting the same id twice is not an option.
PB_ANY produces unique handles, how can i manage the same ?
The help only shows an example with one id (0).
Posted: Tue Jul 25, 2006 7:21 pm
by Shannara
Some info @
http://www.purebasic.fr/english/viewtop ... light=menu
Have to be careful though. Not all people prefer to program for the future of applications (easy extensibility). See replies in that thread
1.5 years later

A response from the dev team
http://www.purebasic.fr/english/viewtop ... ight=pbany
With that mentioned ...
Its fairly impossible unless you set aside a certain set of numbers for menu items and that is all. Just have to make sure the using application use other numbers instead.
Posted: Tue Jul 25, 2006 7:41 pm
by Edwin Knoppert
I have not read it yet but since the hWnd exists i might use that one instead.
Unique enough..?
Posted: Tue Jul 25, 2006 7:43 pm
by Edwin Knoppert
Hmmm:
>Also on Windows there is a limitation which 16 bits id
That sucks..
XP hWnd's are much greater.
Posted: Tue Jul 25, 2006 7:48 pm
by Edwin Knoppert
Let me ask this differently..
Could i use windows with menus where *all* menu's are created with 0 and still distinguish a menu so i can set or inspect it's events properly?
I don't care for PB_ANY itself but the system must be modulair.
Posted: Thu Jul 27, 2006 4:29 am
by netmaestro
#PB_Any never returns a handle, on any PureBasic object. It returns a unique #object which is usable in native PB commands but if you want to get a handle usable in API calls you must use <object>ID(#object). So for menus, do:
Code: Select all
menu1 = CreateMenu(#PB_Any, WindowID(#window))
menu1handle = MenuID(menu1)
and the variable menu1handle is a valid windows handle you can use in API calls.
Posted: Thu Jul 27, 2006 8:01 am
by Edwin Knoppert
that was not my question..
Posted: Thu Jul 27, 2006 11:57 am
by freak
The Menu items are numbered starting from 0 on the OS side.. this is not a PB limitation.
You will have to create your own mapping function to make it modular. I do not see any
big problem there though.
Posted: Thu Jul 27, 2006 12:05 pm
by Edwin Knoppert
Still not what i asked info about..
Posted: Thu Jul 27, 2006 12:11 pm
by freak
Then maybe you should consider rephrasing your question.
#PB_Any on menus works in PB4 no different than before, so i really do not understand where
your problem is exactly.
Posted: Thu Jul 27, 2006 12:34 pm
by Edwin Knoppert
I asked if when i create menus and keep all those menus to ID 0:
1) How will i distinguish the menu being clicked in my event loop?
Possibly by the windowid ?
2) How do i reset such menu for a specific window.
Like disable a specific menu item..
this all in perspective of having multiple windows open at the same time.
Posted: Thu Jul 27, 2006 12:37 pm
by Fred
When looking to your original question, i can't detect a problem. #PB_Any works correctly here. You can create several menu with the same menuitem ids, just use EventWindow() to detect on which window it has occured.. It's the same for the toolbars. Also posting a small code showing your problem will probably help more.
Posted: Thu Jul 27, 2006 12:37 pm
by Edwin Knoppert
Odd, this works now again, but not at home..
Code: Select all
hWnd = WindowID( hWndID )
......
nMenuID = CreateMenu( #PB_Any, hWnd )
If nMenuID <> 0
MenuTitle( "&File" )
MenuItem( 1000, "Open..." )
MenuItem( 1001, "Save..." )
MenuItem( 1002, "Save As.." )
MenuItem( 1003, "&Close" )
MenuBar()
MenuItem( 1004, "Print..." )
MenuBar()
MenuItem( 1005, "&Exit" )
MenuTitle( "&Edit" )
MenuItem( 1006, "Cut" )
MenuItem( 1007, "Copy" )
DisableMenuItem( nMenuID, 1007, 1 )
MenuItem( 1008, "Paste" )
DisableMenuItem( nMenuID, 1008, 1 )
MenuItem( 1009, "Select All" )
MenuBar()
MenuItem( 1010, "Find..." )
MenuItem( 1011, "Find Next" )
MenuItem( 1012, "Replace..." )
MenuTitle( "&Help" )
MenuItem( 1013, "&Contents" )
MenuBar()
MenuItem( 1014, "About..." )
EndIf
Both PC's are XP, not sure about the pb (beta)version though, both are v4..
Posted: Thu Jul 27, 2006 12:40 pm
by Edwin Knoppert
I will retest this code at home tonight.
Really, the disable menu stuff did not work.
Posted: Thu Jul 27, 2006 1:25 pm
by Dr. Dri
Maybe with EventwParam() or EventlParam() ?
Dri