Some menu issues (PB4)
-
- Addict
- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact:
Some menu issues (PB4)
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).
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).
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.
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


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.
-
- Addict
- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact:
-
- Addict
- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact:
-
- Addict
- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact:
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
#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:
and the variable menu1handle is a valid windows handle you can use in API calls.
Code: Select all
menu1 = CreateMenu(#PB_Any, WindowID(#window))
menu1handle = MenuID(menu1)
BERESHEIT
-
- Addict
- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact:
-
- Addict
- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact:
-
- Addict
- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact:
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.
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.
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.
Last edited by Fred on Thu Jul 27, 2006 12:38 pm, edited 1 time in total.
-
- Addict
- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact:
Odd, this works now again, but not at home..
Both PC's are XP, not sure about the pb (beta)version though, both are v4..
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
Last edited by Edwin Knoppert on Thu Jul 27, 2006 12:41 pm, edited 1 time in total.
-
- Addict
- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact: