Árvore de páginas

Cria um objeto do tipo menu/item de menu.

Hierarquia

Construtores

Propriedades

Métodos

Exemplos

Exemplo 1
  #include "TOTVS.CH"

  User Function TMenuItem()
    local oDialog := nil
    local oFolder := nil
    local aFnctns := __funArr()
    aScan(aFnctns, {|x|lower(x[1]) == "tmenuitem"})
    
    // cria a janela do teste 
    oDialog := msDialog():new(0, 0, 600, 800, , , , , , , , , , .T.)
    
    oDialog:lCentered := .T. 
    // centraliza a janela e ignora a definição anterior de nTop e nLeft
    // cria as pastas 
    oFolder := tFolder():New(, , , , oDialog, , , , , , , , , ) 
    oFolder:nLeft   := 5  
    oFolder:nTop    := 5  
    oFolder:nWidth  := oDialog:nClientWidth - 10  
    oFolder:nHeight := oDialog:nClientHeight - 10 
    oFolder:AddItem("tButton", .T.) 
    oFolder:AddItem("tMenu", .T.) 
    oFolder:AddItem("tMenuBar", .T.)
  
    // tButton  
    exemploa(oFolder:aDialogs[1])

    // tMenu  
    exemplob(oFolder:aDialogs[3])

    // tMenuBar 
    exemploc(oFolder:aDialogs[2])

    // apresenta a janela 
    oDialog:activate()
  return

  static function exemploa(oParent)
    local oMenu := nil
    local oButton1 := nil, oMenu01 := nil, oMenu0101 := nil, oMenu0102 := nil, oMenu0103 := nil 
    local oButton2 := nil, oMenu02 := nil, oMenu0201 := nil, oMenu0202 := nil, oMenu0203 := nil 
    local oButton3 := nil, oMenu03 := nil, oMenu0301 := nil, oMenu0302 := nil, oMenu0303 := nil 
    local oSubMenu := nil
    
    // cria os menus  
    oMenu01 := tMenu():new(0, 0, 0, 0, .T., , oMenu)  
    oMenu02 := tMenu():new(0, 0, 0, 0, .T., , oMenu)  
    oMenu03 := tMenu():new(0, 0, 0, 0, .T., , oMenu)
    
    // cria os itens dos menus  
    oMenu0101 := tMenuItem():new(oMenu01, "Menu 01, item 01", , , , {|| }, , , , , , , , , .T.) 
    oMenu0102 := tMenuItem():new(oMenu01, "Menu 01, item 02", , , , {||msgInfo("Menu 01, item 02")}, , , , , , , , , .T.) 
    oMenu0103 := tMenuItem():new(oMenu01, "Menu 01, item 03", , , .F., {||msgInfo("Menu 01, item 03")}, , , , , , , , , .T.)  
    oMenu0201 := tMenuItem():new(oMenu02, "Menu 02, item 01", , , , {||msgInfo("Menu 02, item 01")}, , , , , , , , , .T.) 
    oMenu0202 := tMenuItem():new(oMenu02, "Menu 02, item 02", , , , {||msgInfo("Menu 02, item 02")}, , , , , , , , , .T.) 
    oMenu0203 := tMenuItem():new(oMenu02, "Menu 02, item 03", , , , {||msgInfo("Menu 02, item 03")}, , , , , , , , , .T.) 
    oMenu0301 := tMenuItem():new(oMenu03, "Menu 03, item 01", , , , {||msgInfo("Menu 03, item 01")}, , , , , , , , , .T.) 
    oMenu0302 := tMenuItem():new(oMenu03, "Menu 03, item 02", , , .F., {||msgInfo("Menu 03, item 02")}, , , , , , , , , .T.)  
    oMenu0303 := tMenuItem():new(oMenu03, "Menu 03, item 03", , , , {||msgInfo("Menu 03, item 03")}, , , , , , , , , .T.)
    
    // adiciona os itens dos menus  
    oMenu01:add(oMenu0101)  
    
    // cria um subitem de um submenu    
    oSubMenu := tMenuItem():new(oMenu0101, "SubMenu 01, item 01", , , , {||msgInfo("SubMenu 01, item 01")}, , , , , , , , , .T.)  
    
    // adiciona o subitem do submenu    
    oMenu0101:add(oSubMenu) 
    oMenu01:add(oMenu0102)  
    oMenu01:add(oMenu0103)  
    oMenu02:add(oMenu0201)  
    oMenu02:add(oMenu0202)  
    oMenu02:add(oMenu0203)  
    oMenu03:add(oMenu0301)  
    oMenu03:add(oMenu0302)  
    oMenu03:add(oMenu0303)  
    
    // cria os botões que receberão os menus  
    oButton1 := tButton():create(oParent) 
    oButton1:cCaption := "Button 01"  
    oButton1:nWidth   := 100  
    oButton1:nTop     := 30 
    oButton1:nLeft    := 10 
    oButton1:bAction  := {|| }  
    oButton1:setPopupMenu(oMenu01)  
    oButton2 := tButton():create(oParent) 
    oButton2:cCaption := "Button 02"  
    oButton2:nWidth   := 100  
    oButton2:nTop     := oButton1:nBottom + 10  
    oButton2:nLeft    := 10 
    oButton2:bAction  := {|| }  
    oButton2:setPopupMenu(oMenu02)  
    oButton3 := tButton():create(oParent) 
    oButton3:cCaption := "Button 03"  
    oButton3:nWidth   := 100  
    oButton3:nTop     := oButton2:nBottom + 10  
    oButton3:nLeft    := 10 
    oButton3:bAction  := {|| }  
    oButton3:setPopupMenu(oMenu03)
  return
  
  static function exemplob(oParent)
    local oMenu := nil
    local oMenu01 := nil, oMenu0101 := nil, oMenu0102 := nil, oMenu0103 := nil 
    local oMenu02 := nil, oMenu0201 := nil, oMenu0202 := nil, oMenu0203 := nil 
    local oMenu03 := nil, oMenu0301 := nil, oMenu0302 := nil, oMenu0303 := nil 
    local oSubMenu := nil 
    oMenu := tMenu():new(0, 0, 0, 0, .F., "", oParent)
    
    // cria os submenus utilizando o construtor new 
    oMenu01 := tMenuItem():new(oMenu, "Menu 01")
    
    // cria os submenus utilizando o construtor new2  
    oMenu02 := tMenuItem():new2(oMenu, "Menu 02") 
    oMenu03 := tMenuItem():new2(oMenu, "Menu 03")
    
    // cria os itens dos submenus utilizando o construtor new2  
    oMenu0101 := tMenuItem():new(oMenu01, "Menu 01, item 01", , , , {|| })  
    
    // cria um subitem de um submenu    
    oSubMenu := tMenuItem():new(oMenu0101, "SubMenu 01, item 01", , , , {||msgInfo("SubMenu 01, item 01")}) 
    
    // adiciona o subitem do submenu    
    oMenu0101:add(oSubMenu) 
    oMenu0102 := tMenuItem():new2(oMenu01, "Menu 01, item 02", , , {||msgInfo("Menu 01, item 02")}) 
    oMenu0103 := tMenuItem():new2(oMenu01, "Menu 01, item 03", , .F., {||msgInfo("Menu 01, item 03")})  
    oMenu0201 := tMenuItem():new2(oMenu02, "Menu 02, item 01", , , {||msgInfo("Menu 02, item 01")}) 
    oMenu0202 := tMenuItem():new2(oMenu02, "Menu 02, item 02", , , {||msgInfo("Menu 02, item 02")}) 
    oMenu0203 := tMenuItem():new2(oMenu02, "Menu 02, item 03", , , {||msgInfo("Menu 02, item 03")})
    
    // cria os itens dos submenus utilizando o construtor new 
    oMenu0301 := tMenuItem():new(oMenu03, "Menu 03, item 01", , , , {||msgInfo("Menu 03, item 01")})  
    oMenu0302 := tMenuItem():new(oMenu03, "Menu 03, item 02", , , .F., {||msgInfo("Menu 03, item 02")}) 
    oMenu0303 := tMenuItem():new(oMenu03, "Menu 03, item 03", , , , {||msgInfo("Menu 03, item 03")})
    
    // adiciona os itens dos submenus 
    oMenu01:add(oMenu0101)  
    oMenu01:add(oMenu0102)  
    oMenu01:add(oMenu0103)  
    oMenu02:add(oMenu0201)  
    oMenu02:add(oMenu0202)  
    oMenu02:add(oMenu0203)  
    oMenu03:add(oMenu0301)  
    oMenu03:add(oMenu0302)  
    oMenu03:add(oMenu0303)
    
    // adiciona os submenus ao menu principal 
    oMenu:add(oMenu01)  
    oMenu:add(oMenu02)  
    oMenu:add(oMenu03)
  return
  
  static function exemploc(oParent)
    local oMenu := nil
    local oMenu01 := nil, oMenu0101 := nil, oMenu0102 := nil, oMenu0103 := nil 
    local oMenu02 := nil, oMenu0201 := nil, oMenu0202 := nil, oMenu0203 := nil 
    local oMenu03 := nil, oMenu0301 := nil, oMenu0302 := nil, oMenu0303 := nil 
    local oSubMenu := nil  
    oMenu := tMenuBar():new(oParent)
    
    // cria os submenus 
    oMenu01 := tMenu():new(0, 0, 0, 0, .T., , oMenu)  
    oMenu02 := tMenu():new(0, 0, 0, 0, .T., , oMenu)  
    oMenu03 := tMenu():new(0, 0, 0, 0, .T., , oMenu)
  
    // cria os itens dos submenus 
    oMenu0101 := tMenuItem():new(oMenu01, "Menu 01, item 01", , , , {|| }, , , , , , , , , .T.) 
    oMenu0102 := tMenuItem():new(oMenu01, "Menu 01, item 02", , , , {||msgInfo("Menu 01, item 02")}, , , , , , , , , .T.) 
    oMenu0103 := tMenuItem():new(oMenu01, "Menu 01, item 03", , , .F., {||msgInfo("Menu 01, item 03")}, , , , , , , , , .T.)  
    oMenu0201 := tMenuItem():new(oMenu02, "Menu 02, item 01", , , , {||msgInfo("Menu 02, item 01")}, , , , , , , , , .T.) 
    oMenu0202 := tMenuItem():new(oMenu02, "Menu 02, item 02", , , , {||msgInfo("Menu 02, item 02")}, , , , , , , , , .T.) 
    oMenu0203 := tMenuItem():new(oMenu02, "Menu 02, item 03", , , , {||msgInfo("Menu 02, item 03")}, , , , , , , , , .T.)
    oMenu0301 := tMenuItem():new(oMenu03, "Menu 03, item 01", , , , {||msgInfo("Menu 03, item 01")}, , , , , , , , , .T.)
    oMenu0302 := tMenuItem():new(oMenu03, "Menu 03, item 02", , , .F., {||msgInfo("Menu 03, item 02")}, , , , , , , , , .T.)
    oMenu0303 := tMenuItem():new(oMenu03, "Menu 03, item 03", , , , {||msgInfo("Menu 03, item 03")}, , , , , , , , , .T.)
    
    // adiciona os itens dos submenus 
    oMenu01:add(oMenu0101)  
    
    // cria um subitem de um submenu    
    oSubMenu := tMenuItem():new(oMenu0101, "SubMenu 01, item 01", , , , {||msgInfo("SubMenu 01, item 01")}, , , , , , , , , .T.)  
    
    // adiciona o subitem do submenu    
    oMenu0101:add(oSubMenu) 
    oMenu01:add(oMenu0102)  
    oMenu01:add(oMenu0103)  
    oMenu02:add(oMenu0201)  
    oMenu02:add(oMenu0202)  
    oMenu02:add(oMenu0203)  
    oMenu03:add(oMenu0301)  
    oMenu03:add(oMenu0302)  
    oMenu03:add(oMenu0303)
    
    // adiciona os submenus ao menu principal 
    oMenu:addItem("Menu 01", oMenu01, .T.)  
    oMenu:addItem("Menu 02", oMenu02, .T.)  
    oMenu:addItem("Menu 03", oMenu03, .T.)
  return

Resultado do Exemplo

Abrangência

Microsiga Protheus 8.11, Microsiga Protheus 11, Protheus 10, TOTVS Application Server 10, ByYou Application Server

  • Sem rótulos