Clickable menuTitle

Just starting out? Need help? Post your questions and find answers here.
normeus
Enthusiast
Enthusiast
Posts: 414
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Clickable menuTitle

Post by normeus »

I was working on a tiny program, and I needed a single click Help menu item to display a simple explanation. Using CloseSubMenu() did the trick. It's hard to explain, but I am using a MenuItem() as a MenuTitle(). Sample code:

Code: Select all

  If OpenWindow(0, 200, 200, 220, 100, "SubMenu Example")
    If CreateMenu(0, WindowID(0))
      MenuTitle("Project") 
        MenuItem(1, "Open")  
        MenuItem(2, "Close")
        MenuBar()
        OpenSubMenu("Recent files")       ; begin submenu
          MenuItem( 3, "C:\Autoexec.bat")
          MenuItem( 4, "D:\Test.txt")
        CloseSubMenu()                    ; end submenu
       CloseSubMenu()                     ; end first menutitle
       MenuItem(5, "Help")            ; instead of MenuTitle creating MenuItem
       MenuTitle("About us")
       MenuItem(6,"Mission")
       MenuItem(7,"Corporate Blah, Blah")
      EndIf
      Repeat 
       Event = WaitWindowEvent() 
       Select Event
                 Case #PB_Event_Menu
         Select EventMenu()
            Case 5
              MessageRequester("Help", " I didn't know you could close the first menu title", #PB_MessageRequester_Ok | #PB_MessageRequester_Info)
          EndSelect
      EndSelect
      
      Until Event=#PB_Event_CloseWindow
  EndIf

I found having one click menu item useful for my tiny program. Should it be in the help? Nice to know you are able to do this.

Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Clickable menuTitle

Post by BarryG »

It is in the manual, under EventMenu(). When you click a menu (anywhere on it), it generates a #PB_Event_Menu event.
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: Clickable menuTitle

Post by fsw »

The code doesn't work as is on macOS.
MenuItem(5, "Help") is missing...

I am to provide the public with beneficial shocks.
Alfred Hitshock
normeus
Enthusiast
Enthusiast
Posts: 414
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: Clickable menuTitle

Post by normeus »

fsw,
I forgot to mention: Windows 64 and PB 5.72x64 it might not work on other systems
BarryG,
Menutitle() has no ID so you cannot process a click on it. I needed to open a message when Menutitle() was clicked. The sample code shows that you can closeSubMenu() after a menutitle() to start a menuItem() as a top menu item. Probably a Hack, but it works on Windows.

Norm.
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Clickable menuTitle

Post by Kwai chang caine »

ImageThe happiness is a road...
Not a destination
Post Reply