Some menu issues (PB4)

Everything else that doesn't fall into one of the other PB categories.
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Some menu issues (PB4)

Post 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).
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post 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 :D

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.
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post by Edwin Knoppert »

I have not read it yet but since the hWnd exists i might use that one instead.
Unique enough..?
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post by Edwin Knoppert »

Hmmm:

>Also on Windows there is a limitation which 16 bits id
That sucks..
XP hWnd's are much greater.
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post 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.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
BERESHEIT
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post by Edwin Knoppert »

that was not my question..
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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.
quidquid Latine dictum sit altum videtur
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post by Edwin Knoppert »

Still not what i asked info about..
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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.
quidquid Latine dictum sit altum videtur
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post 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.
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post 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.
Last edited by Fred on Thu Jul 27, 2006 12:38 pm, edited 1 time in total.
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post 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..
Last edited by Edwin Knoppert on Thu Jul 27, 2006 12:41 pm, edited 1 time in total.
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post by Edwin Knoppert »

I will retest this code at home tonight.
Really, the disable menu stuff did not work.
Dr. Dri
Enthusiast
Enthusiast
Posts: 243
Joined: Sat Aug 23, 2003 6:45 pm

Post by Dr. Dri »

Maybe with EventwParam() or EventlParam() ?

Dri
Post Reply