BBC BASIC for Windows
Programming >> BBC BASIC language >> Drop Down Menus
http://bb4w.conforums.com/index.cgi?board=language&action=display&num=1225969502

Drop Down Menus
Post by GordonSweet on Nov 6th, 2008, 10:05am

Richard how do we close down all the menu options below so that the pop menu is no longer shown and active, also is it possible to have more than 16 options?
Gordon

SYS "CreatePopupMenu" TO hsub%
:
SYS "CreatePopupMenu" TO hpop1%
SYS "AppendMenu", hpop1%, 0, 1, "&Red"
SYS "AppendMenu", hpop1%, 0, 2, "&Green"
SYS "AppendMenu", hpop1%, 0, 4, "&Blue"
SYS "AppendMenu", hpop1%, 0, 3, "&Yellow"
SYS "AppendMenu", hpop1%, 0, 5, "&Magenta"
SYS "AppendMenu", hpop1%, 0, 6, "&Cyan"
:
SYS "CreateMenu" TO hmenu%
SYS "AppendMenu", hmenu%, 16, hpop1%, "&Primary"
SYS "SetMenu", @hwnd%, hmenu%
SYS "DrawMenuBar", @hwnd%
:
ON SYS PROCmenu(@wparam%) : RETURN
REPEAT UNTIL INKEY(10)=0
END
:
DEF PROCmenu(col%)
PRINTcol%
ENDPROC


Re: Drop Down Menus
Post by admin on Nov 6th, 2008, 12:31pm

Quote:
how do we close down all the menu options

It's a relatively unusual thing to want to do, but you can use SYS "DestroyMenu" to get rid of any menus you have created:

Code:
      SYS "DestroyMenu", hpop1%
      SYS "DestroyMenu", hmenu% 


Quote:
is it possible to have more than 16 options

Yes, there's no practical limit. Think of the right-click context menu in the BB4W IDE (the one that lists all the procedures and functions). That commonly has hundreds of items.

Richard.
Re: Drop Down Menus
Post by GordonSweet on Nov 6th, 2008, 1:24pm

Thanks Richard but I must be doing something wrong below. Gordon

Code:
      SYS "CreatePopupMenu" TO hsub%
      :
      SYS "CreatePopupMenu" TO hpop1%
      SYS "AppendMenu", hpop1%, 0, 1, "&Red"
      SYS "AppendMenu", hpop1%, 0, 2, "&Green"
      SYS "AppendMenu", hpop1%, 0, 4, "&Blue"
      SYS "AppendMenu", hpop1%, 0, 3, "&Yellow"
      SYS "AppendMenu", hpop1%, 0, 5, "&Magenta"
      SYS "AppendMenu", hpop1%, 0, 6, "&Cyan"
      :
      SYS "CreateMenu" TO hmenu%
      SYS "AppendMenu", hmenu%, 16, hpop1%, "&Primary"
      SYS "SetMenu", @hwnd%, hmenu%
      SYS "DrawMenuBar", @hwnd%
      :
      ON SYS PROCmenu(@wparam%) : RETURN
      REPEAT UNTIL INKEY$(10)="/"
      SYS "DestroyMenu", hpop1%
      SYS "DestroyMenu", hmenu%
      G=GET : QUIT
      END
      :
      DEF PROCmenu(col%)
      PRINTcol%
      ENDPROC
 

Re: Drop Down Menus
Post by admin on Nov 6th, 2008, 2:32pm

Quote:
Thanks Richard but I must be doing something wrong

Before you can destroy the main menu you need to 'detach' it from the window:

Code:
      SYS "SetMenu", @hwnd%, 0
      SYS "DestroyMenu", hpop1%
      SYS "DestroyMenu", hmenu% 

Richard.
Re: Drop Down Menus
Post by GordonSweet on Nov 6th, 2008, 5:17pm

Thanks again Richard I neded it to upgrade my HTML coder that also reformats text Pasted from the clipboard. I will publish it when finished in the Yahoo Group's Files

Gordon