func_maxgui_menus_createmenu.rst 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. .. _func_maxgui_menus_createmenu:
  2. ==========
  3. CreateMenu
  4. ==========
  5. CreateMenu -
  6. Description
  7. ===========
  8. .. code-block:: blitzmax
  9. CreateMenu:TGadget( text$,tag,parent:TGadget,hotKey=0,modifier=0 )
  10. Create a menu.
  11. Menu gadgets should be attached to either a #WindowMenu, other Menu gadgets
  12. or used with the #PopupWindowMenu command. The tag field should be a unique identifier
  13. that will be present in the #EventData field of EVENT_MENUACTION events.
  14. Keyboard shortcuts can be associated with a Menu by using the optional hotKey and
  15. modifier parameters.
  16. Please refer to the #{key codes} module for valid key and modifier codes.
  17. The MODIFIER_COMMAND value should be used instead of MODIFIER_CONTROL
  18. with Menu hotkeys for best crossplatform compatability.
  19. Menus now also support icons on most platforms through the use of #SetGadgetPixmap.
  20. See Also: #FreeMenu, #SetMenuText, #CheckMenu, #UncheckMenu, #EnableMenu, #DisableMenu,
  21. #MenuText, #MenuChecked, #MenuEnabled and #SetGadgetPixmap.
  22. Parameters
  23. ==========
  24. Return Values
  25. =============
  26. Nothing.
  27. Examples
  28. ========
  29. .. code-block:: blitzmax
  30. ' createmenu.bmx
  31. Import MaxGui.Drivers
  32. Strict
  33. Local window:TGadget
  34. Local filemenu:TGadget
  35. Local editmenu:TGadget
  36. Local helpmenu:TGadget
  37. Const MENU_NEW=101
  38. Const MENU_OPEN=102
  39. Const MENU_SAVE=103
  40. Const MENU_CLOSE=104
  41. Const MENU_EXIT=105
  42. Const MENU_CUT=106
  43. Const MENU_COPY=107
  44. Const MENU_PASTE=108
  45. Const MENU_ABOUT=109
  46. window=CreateWindow("My Window",40,40,320,240)
  47. filemenu=CreateMenu("&File",0,WindowMenu(window))
  48. CreateMenu"&New",MENU_NEW,filemenu,KEY_N,MODIFIER_COMMAND
  49. CreateMenu"&Open",MENU_OPEN,filemenu,KEY_O,MODIFIER_COMMAND
  50. CreateMenu"&Close",MENU_CLOSE,filemenu,KEY_W,MODIFIER_COMMAND
  51. CreateMenu"",0,filemenu
  52. CreateMenu"&Save",MENU_SAVE,filemenu,KEY_S,MODIFIER_COMMAND
  53. CreateMenu"",0,filemenu
  54. CreateMenu"E&xit",MENU_EXIT,filemenu,KEY_F4,MODIFIER_COMMAND
  55. editmenu=CreateMenu("&Edit",0,WindowMenu(window))
  56. CreateMenu "Cu&t",MENU_CUT,editmenu,KEY_X,MODIFIER_COMMAND
  57. CreateMenu "&Copy",MENU_COPY,editmenu,KEY_C,MODIFIER_COMMAND
  58. CreateMenu "&Paste",MENU_PASTE,editmenu,KEY_V,MODIFIER_COMMAND
  59. helpmenu=CreateMenu("&Help",0,WindowMenu(window))
  60. CreateMenu "&About",MENU_ABOUT,helpmenu
  61. UpdateWindowMenu window
  62. While True
  63. WaitEvent
  64. Select EventID()
  65. Case EVENT_WINDOWCLOSE
  66. End
  67. Case EVENT_MENUACTION
  68. Select EventData()
  69. Case MENU_EXIT
  70. End
  71. Case MENU_ABOUT
  72. Notify "Incrediabler~n(C)2005 Incredible Software"
  73. End Select
  74. End Select
  75. Wend
  76. See Also
  77. ========