home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 5 / CD_Magazyn_EXEC_nr_5.iso / Programy / Programowanie / BASIC / pmDevBas.lha / PullDownMenu.bas < prev    next >
Encoding:
BASIC Source File  |  2001-01-17  |  17.6 KB  |  754 lines

  1. ' *********************************************************************
  2. '   PullDownMenu © 1996-97 by Henrik Isaksson -- All Rights Reserved
  3. '                           V. 2.2 (20.07.00)
  4. '
  5. '                C to HBASIC conversion 1.1 (17.1.01)
  6. '               by Dámaso D. Estévez <amidde@arrakis.es>
  7. '              AmiSpaTra - http://www.arrakis.es/~amidde/
  8. '
  9. '   This example create a Workbench menu simulation and uses a hook
  10. ' Este ejemplo crea una simulación del menú del WB y utiliza un resorte
  11. ' *********************************************************************
  12.  
  13. REM $include pm.bh
  14. REM $include exec.bh
  15. REM $include intuition.bh
  16. REM $include utility.bc
  17.  
  18. pmb&  = NULL&    ' PopUpMenuBase
  19. ib&   = NULL&    ' IntuitionBase
  20. ub&   = NULL&    ' UtilityBase
  21. gb&   = NULL&    ' GfxBase
  22. w&    = NULL&    ' Window
  23.  
  24. im&   = NULL&    ' IntuiMessage
  25. p&    = NULL&    ' PopupMenu
  26. r&    = TRUE&    ' Status flag (loop) / Bandera de estado (bucle)
  27. ok&   = FALSE&   ' Status flag / Bandera de estado
  28.  
  29. DIM mtags&(40)   ' Window Taglist / Lista de atributos para la ventana
  30.  
  31. '     Hook struct simulation
  32. ' Simulación de la estructura Hook 
  33. ' --------------------------------
  34. DIM MenuHandler%(Hook_sizeof%\2)
  35.  
  36. '      Settings for to use hooks
  37. ' Preferencias para el uso de resortes
  38. ' ------------------------------------
  39. REM $NOAUTODIM
  40. REM $NOARRAY
  41. REM $NOBREAK
  42. REM $NOOVERFLOW
  43. REM $NOEVENT
  44. REM $NOSTACK
  45.  
  46. ' =====================================================================
  47.  
  48. FUNCTION MenuHandlerFunc&(BYVAL hook&,BYVAL object&,BYVAL msg&)
  49. SHARED r&
  50. STATIC i&
  51.  
  52.     MenuHandlerFunc& = FALSE&
  53.  
  54.     PRINT "---"
  55.     PRINT "Title:   "+CHR$(34)+PEEK$(PEEKL(object&+pm_Title%))+CHR$(34)
  56.     PRINT "UserData:";PEEKL(object&+pm_UserData%)
  57.     PRINT "ID:      ";PEEKL(object&+pm_ID%)
  58.  
  59.     '   Mr Issakson says what this is the way
  60.     ' of finding is the item is checked or not.
  61.     '       BEWARE! I've modified slighty
  62.     ' the HBasic names for theses (PM_->PMF_)...
  63.     ' C language:
  64.     '  #define PM_CHECKIT             0x40000000
  65.     '  #define PM_CHECKED             0x80000000
  66.     ' HBasic language:
  67.     '  CONST PMF_CHECKIT&          = &h40000000&
  68.     '  CONST PMF_CHECKED&          = &h80000000&
  69.     '
  70.     ' El Sr. Issakson señala que esta es la forma
  71.     '    de comprobar si un ítem está activado
  72.     '        (marca de verificación) o no.
  73.     '    ¡ATENCIÓN! He modificado ligeramente
  74.     '        el nombre de estas constantes
  75.     '          en HBasic (PM_->PMF_)...
  76.     ' Lenguaje C:
  77.     '  #define PM_CHECKIT             0x40000000
  78.     '  #define PM_CHECKED             0x80000000
  79.     ' Lenguaje HBasic:
  80.     '  CONST PMF_CHECKIT&          = &h40000000&
  81.     '  CONST PMF_CHECKED&          = &h80000000&
  82.     ' --------------------------------------------
  83.     IF(PEEKL(object&+pm_Flags%) AND PMF_CHECKIT&) THEN
  84.         print "Checked?  ";
  85.         IF (PEEKL(object&+pm_Flags%) AND PMF_CHECKED&) THEN
  86.              PRINT "Yes"
  87.         ELSE
  88.              PRINT "No"
  89.         END IF
  90.         PRINT
  91.     END IF
  92.  
  93.     IF(PEEKL(object&+pm_UserData%)=5&) THEN
  94.         '       Mr Issakson uses other solution more elegant
  95.         ' in your C code, I know... I tried convert it to HBasic,
  96.         '      but my code always finnished with a guru 8'(...
  97.         ' and I decided use the HBasic shared var for simulate it.
  98.         '
  99.         '   El Sr. Issakson utiliza otra solución más elegante
  100.         '  en su código en C, lo sé... he intentado reproducirla
  101.         '     pero mi código siempre acababa en un gurú 8'(..
  102.         '   así que decidí utilizar las variables compartidas
  103.         '          del HBasic para simular su función.
  104.         r&=FALSE&
  105.     END IF
  106.  
  107.     MenuHandlerFunc& = TRUE&
  108.  
  109. END FUNCTION
  110.  
  111. '               --------------------------------------------
  112.  
  113. FUNCTION MakeTestMenu&()
  114. LOCAL i&,pi&,mpi&,tags&
  115.  
  116. ' Taglist / Lista de atributos
  117. ' ----------------------------
  118. DIM tags&(24)
  119.  
  120. ' Items or menu pointer arrays / Matrices de punteros a ítems o menús
  121. ' -------------------------------------------------------------------
  122. DIM mpi&(10)    ' Main
  123. DIM  pi&(15)    ' Aux.
  124.  
  125.     ' Workbench item menu / Ítem del menú Workbench
  126.     ' =============================================
  127.  
  128.     ' PMCheckItem
  129.  
  130.     TAGLIST VARPTR(tags&(0)), _
  131.         PM_Title&,   SADD("Backdrop?"+CHR$(0)), _
  132.         PM_ID&,      1&, _
  133.         PM_Checkit&, TRUE&, _
  134.         PM_CommKey&, SADD("B"+CHR$(0)), _
  135.         TAG_DONE&
  136.  
  137.     pi&(1) = PM_MakeItemA&(VARPTR(tags&(0)))
  138.  
  139.     ' PMItem
  140.  
  141.     TAGLIST VARPTR(tags&(0)), _
  142.         PM_Title&,   SADD("Execute command..."+CHR$(0)), _
  143.         PM_CommKey&, SADD("E"+CHR$(0)), _
  144.         TAG_DONE&
  145.  
  146.     pi&(2) = PM_MakeItemA&(VARPTR(tags&(0)))
  147.  
  148.     TAGLIST VARPTR(tags&(0)), _
  149.         PM_Title&,   SADD("Redraw All"+CHR$(0)), _
  150.         TAG_DONE&
  151.  
  152.     pi&(3) = PM_MakeItemA&(VARPTR(tags&(0)))
  153.  
  154.     TAGLIST VARPTR(tags&(0)), _
  155.         PM_Title&,   SADD("Update All"+CHR$(0)), _
  156.         TAG_DONE&
  157.  
  158.     pi&(4) = PM_MakeItemA&(VARPTR(tags&(0)))
  159.  
  160.     TAGLIST VARPTR(tags&(0)), _
  161.         PM_Title&,   SADD("Last Message"+CHR$(0)), _
  162.         TAG_DONE&
  163.  
  164.     pi&(5) = PM_MakeItemA&(VARPTR(tags&(0)))
  165.  
  166.     TAGLIST VARPTR(tags&(0)), _
  167.         PM_Title&,   SADD("About..."+CHR$(0)), _
  168.         PM_CommKey&, SADD("?"+CHR$(0)), _
  169.         TAG_DONE&
  170.  
  171.     pi&(6) = PM_MakeItemA&(VARPTR(tags&(0)))
  172.  
  173.     TAGLIST VARPTR(tags&(0)), _
  174.         PM_Title&,   SADD("Quit"+CHR$(0)), _
  175.         PM_UserData&, 5&, _
  176.         PM_CommKey&,  SADD("Q"+CHR$(0)), _
  177.         TAG_DONE&
  178.  
  179.     pi&(7) = PM_MakeItemA&(VARPTR(tags&(0)))
  180.  
  181.     ' Grouping items / Agrupando ítems en un submenú
  182.     ' ----------------------------------------------
  183.  
  184.     TAGLIST VARPTR(tags&(0)), _
  185.         PM_Dummy&, 0&, _
  186.         TAG_DONE&
  187.  
  188.     FOR i& = 1 TO 7
  189.         TAGLIST VARPTR(tags&((i&-1)*2)), _
  190.             PM_Item&, pi&(i&), _
  191.             TAG_DONE&
  192.     NEXT i&
  193.  
  194.     mpi&(0) = PM_MakeMenuA&(VARPTR(tags&(0)))
  195.  
  196.     ' Creating the Workbench item and link with their submenu
  197.     '      Creando ítem Workbench y enlace con su submenú
  198.     ' -------------------------------------------------------
  199.  
  200.     TAGLIST VARPTR(tags&(0)), _
  201.         PM_Title&,    SADD("Workbench"+CHR$(0)), _
  202.         PM_Sub&,      mpi&(0), _
  203.         PM_UserData&, 5986&, _
  204.         PM_NoSelect&, FALSE&, _
  205.         TAG_DONE&
  206.  
  207.     mpi&(1) = PM_MakeItemA&(VARPTR(tags&(0)))
  208.  
  209.     ' =============================================================
  210.  
  211.     ' Window item menu / Ítem del menú Window
  212.     ' =======================================
  213.  
  214.     ' PMItem
  215.  
  216.     TAGLIST VARPTR(tags&(0)), _
  217.         PM_Title&,    SADD("New Drawer"+CHR$(0)), _
  218.         PM_CommKey&,  SADD("N"+CHR$(0)), _
  219.         PM_Disabled&, TRUE&, _
  220.         TAG_DONE&
  221.  
  222.     pi&(1) = PM_MakeItemA&(VARPTR(tags&(0)))
  223.  
  224.     TAGLIST VARPTR(tags&(0)), _
  225.         PM_Title&,    SADD("Open Parent"+CHR$(0)), _
  226.         PM_Disabled&, TRUE&, _
  227.         TAG_DONE&
  228.  
  229.     pi&(2) = PM_MakeItemA&(VARPTR(tags&(0)))
  230.  
  231.     TAGLIST VARPTR(tags&(0)), _
  232.         PM_Title&,   SADD("Close"+CHR$(0)), _
  233.         PM_CommKey&, SADD("K"+CHR$(0)), _
  234.         PM_Disabled&, TRUE&, _
  235.         TAG_DONE&
  236.  
  237.     pi&(3) = PM_MakeItemA&(VARPTR(tags&(0)))
  238.  
  239.     TAGLIST VARPTR(tags&(0)), _
  240.         PM_Title&,   SADD("Update"+CHR$(0)), _
  241.         PM_Disabled&, TRUE&,_
  242.         TAG_DONE&
  243.  
  244.     pi&(4) = PM_MakeItemA&(VARPTR(tags&(0)))
  245.  
  246.     TAGLIST VARPTR(tags&(0)), _
  247.         PM_Title&,   SADD("Select Contents"+CHR$(0)), _
  248.         PM_CommKey&, SADD("A"+CHR$(0)), _
  249.         TAG_DONE&
  250.  
  251.     pi&(5) = PM_MakeItemA&(VARPTR(tags&(0)))
  252.  
  253.     TAGLIST VARPTR(tags&(0)), _
  254.         PM_Title&,   SADD("Clean Up"+CHR$(0)), _
  255.         PM_CommKey&,  SADD("."+CHR$(0)), _
  256.         TAG_DONE&
  257.  
  258.     pi&(6) = PM_MakeItemA&(VARPTR(tags&(0)))
  259.  
  260.     ' Snapshot submenu / Submenú Snapshot
  261.  
  262.         ' Subitems
  263.  
  264.         TAGLIST VARPTR(tags&(0)), _
  265.             PM_Title&, SADD("Window"+CHR$(0)), _
  266.             TAG_DONE&
  267.  
  268.         pi&(7) = PM_MakeItemA&(VARPTR(tags&(0)))
  269.  
  270.         TAGLIST VARPTR(tags&(0)), _
  271.             PM_Title&, SADD("All"+CHR$(0)), _
  272.             TAG_DONE&
  273.  
  274.         pi&(8) = PM_MakeItemA&(VARPTR(tags&(0)))
  275.  
  276.         TAGLIST VARPTR(tags&(0)), _
  277.             PM_Dummy&, 0&, _
  278.             PM_Item&,  pi&(7), _
  279.             PM_Item&,  pi&(8), _
  280.             TAG_DONE&
  281.  
  282.         pi&(0) = PM_MakeMenuA&(VARPTR(tags&(0)))
  283.  
  284.     TAGLIST VARPTR(tags&(0)), _
  285.         PM_Title&, SADD("Snapshot"+CHR$(0)), _
  286.         PM_Sub&,   pi&(0), _
  287.         TAG_DONE&
  288.  
  289.     pi&(7) = PM_MakeItemA&(VARPTR(tags&(0)))
  290.  
  291.     ' Show submenu / Submenú Show
  292.  
  293.         ' Subitems
  294.  
  295.         ' Excluding items
  296.         TAGLIST VARPTR(tags&(0)), _
  297.             3&, 0&
  298.  
  299.         pi&(0)=PM_ExLstA&(VARPTR(tags&(0)))
  300.  
  301.         TAGLIST VARPTR(tags&(0)), _
  302.             PM_Title&,   SADD("Only Icons"+CHR$(0)), _
  303.             PM_ID&,      2&, _
  304.             PM_Checkit&, TRUE&, _
  305.             PM_Exclude&, pi&(0), _
  306.             PM_Checked&, TRUE&, _
  307.             TAG_DONE&
  308.  
  309.         pi&(8) = PM_MakeItemA&(VARPTR(tags&(0)))
  310.  
  311.         ' Excluding items
  312.  
  313.         TAGLIST VARPTR(tags&(0)), _
  314.             2&, 0&
  315.  
  316.         pi&(0)=PM_ExLstA&(VARPTR(tags&(0)))
  317.  
  318.         TAGLIST VARPTR(tags&(0)), _
  319.             PM_Title&,   SADD("All"+CHR$(0)), _
  320.             PM_ID&,      3&, _
  321.             PM_Checkit&, TRUE&, _
  322.             PM_Exclude&, pi&(0), _
  323.             TAG_DONE&
  324.  
  325.         pi&(9) = PM_MakeItemA&(VARPTR(tags&(0)))
  326.  
  327.         TAGLIST VARPTR(tags&(0)), _
  328.             PM_Dummy&,    0&, _
  329.             PM_Item&,     pi&(8), _
  330.             PM_Item&,     pi&(9), _
  331.             TAG_DONE&
  332.  
  333.         pi&(0) = PM_MakeMenuA&(VARPTR(tags&(0)))
  334.  
  335.     TAGLIST VARPTR(tags&(0)), _
  336.         PM_Title&,    SADD("Show"+CHR$(0)), _
  337.         PM_Sub&,      pi&(0),_
  338.         PM_Disabled&, TRUE&, _
  339.         TAG_DONE&
  340.  
  341.     pi&(8) = PM_MakeItemA&(VARPTR(tags&(0)))
  342.  
  343.     ' View By submenu / Submenu View By
  344.  
  345.         ' Subitems
  346.  
  347.         ' Excluding items
  348.  
  349.         TAGLIST VARPTR(tags&(0)), _
  350.             5&, 6&, 7&, 0&
  351.  
  352.         pi&(0)=PM_ExLstA&(VARPTR(tags&(0)))
  353.  
  354.         TAGLIST VARPTR(tags&(0)), _
  355.             PM_Title&,   SADD("Icon"+CHR$(0)), _
  356.             PM_ID&,      4&, _
  357.             PM_Checkit&, TRUE&, _
  358.             PM_Exclude&, pi&(0), _
  359.             PM_Checked&, TRUE&, _
  360.             TAG_DONE&
  361.  
  362.         pi&(9) = PM_MakeItemA&(VARPTR(tags&(0)))
  363.  
  364.         ' Excluding items
  365.  
  366.         TAGLIST VARPTR(tags&(0)), _
  367.             4&, 6&, 7&, 0&
  368.  
  369.         pi&(0)=PM_ExLstA&(VARPTR(tags&(0)))
  370.  
  371.         TAGLIST VARPTR(tags&(0)), _
  372.             PM_Title&,   SADD("Name"+CHR$(0)), _
  373.             PM_ID&,      5&, _
  374.             PM_Checkit&, TRUE&, _
  375.             PM_Exclude&, pi&(0), _
  376.             TAG_DONE&
  377.  
  378.         pi&(10) = PM_MakeItemA&(VARPTR(tags&(0)))
  379.  
  380.         ' Excluding items
  381.  
  382.         TAGLIST VARPTR(tags&(0)), _
  383.             4&, 5&, 7&, 0&
  384.  
  385.         pi&(0)=PM_ExLstA&(VARPTR(tags&(0)))
  386.  
  387.         TAGLIST VARPTR(tags&(0)), _
  388.             PM_Title&,   SADD("Date"+CHR$(0)), _
  389.             PM_ID&,      6&, _
  390.             PM_Checkit&, TRUE&, _
  391.             PM_Exclude&, pi&(0), _
  392.             TAG_DONE&
  393.  
  394.         pi&(11) = PM_MakeItemA&(VARPTR(tags&(0)))
  395.  
  396.         ' Excluding items
  397.  
  398.         TAGLIST VARPTR(tags&(0)), _
  399.             4&, 5&, 6&, 0&
  400.  
  401.         pi&(0)=PM_ExLstA&(VARPTR(tags&(0)))
  402.  
  403.         TAGLIST VARPTR(tags&(0)), _
  404.             PM_Title&,   SADD("Size"+CHR$(0)), _
  405.             PM_ID&,      7&, _
  406.             PM_Checkit&, TRUE&, _
  407.             PM_Exclude&, pi&(0), _
  408.             TAG_DONE&
  409.  
  410.         pi&(12) = PM_MakeItemA&(VARPTR(tags&(0)))
  411.  
  412.         TAGLIST VARPTR(tags&(0)), _
  413.             PM_Dummy&, 0&, _
  414.             PM_Item&,  pi&(9), _
  415.             PM_Item&,  pi&(10), _
  416.             PM_Item&,  pi&(11), _
  417.             PM_Item&,  pi&(12), _
  418.             PM_Disabled&, TRUE&, _
  419.             TAG_DONE&
  420.  
  421.         pi&(0) = PM_MakeMenuA&(VARPTR(tags&(0)))
  422.  
  423.     TAGLIST VARPTR(tags&(0)), _
  424.         PM_Title&,  SADD("View By"+CHR$(0)), _
  425.         PM_Sub&,    pi&(0), _
  426.         TAG_DONE&
  427.  
  428.     pi&(9) = PM_MakeItemA&(VARPTR(tags&(0)))
  429.  
  430.     ' Grouping items / Agrupando ítems en un submenú
  431.     ' ----------------------------------------------
  432.  
  433.     TAGLIST VARPTR(tags&(0)), _
  434.         PM_Dummy&, 0&, _
  435.         TAG_DONE&
  436.  
  437.     FOR i& = 1 TO 9
  438.         TAGLIST VARPTR(tags&((i&-1)*2)), _
  439.             PM_Item&, pi&(i&), _
  440.             TAG_DONE&
  441.     NEXT i&
  442.  
  443.     mpi&(0) = PM_MakeMenuA&(VARPTR(tags&(0)))
  444.  
  445.     TAGLIST VARPTR(tags&(0)), _
  446.         PM_Title&, SADD("Window"+CHR$(0)), _
  447.         PM_Sub&,   mpi&(0), _
  448.         TAG_DONE&
  449.  
  450.     mpi&(2) = PM_MakeItemA&(VARPTR(tags&(0)))
  451.  
  452.     ' =============================================================
  453.  
  454.     ' Icons item menu / Ítem del menú Icons
  455.     ' =====================================
  456.  
  457.     ' PMItem
  458.  
  459.     TAGLIST VARPTR(tags&(0)), _
  460.         PM_Title&,   SADD("Open"+CHR$(0)), _
  461.         PM_CommKey&, SADD("O"+CHR$(0)), _
  462.         TAG_DONE&
  463.  
  464.     pi&(1) = PM_MakeItemA&(VARPTR(tags&(0)))
  465.  
  466.     TAGLIST VARPTR(tags&(0)), _
  467.         PM_Title&,   SADD("Copy"+CHR$(0)), _
  468.         PM_CommKey&, SADD("C"+CHR$(0)), _
  469.         TAG_DONE&
  470.  
  471.     pi&(2) = PM_MakeItemA&(VARPTR(tags&(0)))
  472.  
  473.     TAGLIST VARPTR(tags&(0)), _
  474.         PM_Title&,   SADD("Rename..."+CHR$(0)), _
  475.         PM_CommKey&, SADD("R"+CHR$(0)), _
  476.         TAG_DONE&
  477.  
  478.     pi&(3) = PM_MakeItemA&(VARPTR(tags&(0)))
  479.  
  480.     TAGLIST VARPTR(tags&(0)), _
  481.         PM_Title&,   SADD("Information..."+CHR$(0)), _
  482.         PM_CommKey&, SADD("I"+CHR$(0)),_
  483.         TAG_DONE&
  484.  
  485.     pi&(4) = PM_MakeItemA&(VARPTR(tags&(0)))
  486.  
  487.     TAGLIST VARPTR(tags&(0)), _
  488.         PM_Title&,   SADD("Snapshot..."+CHR$(0)), _
  489.         PM_CommKey&, SADD("S"+CHR$(0)), _
  490.         TAG_DONE&
  491.  
  492.     pi&(5) = PM_MakeItemA&(VARPTR(tags&(0)))
  493.  
  494.     TAGLIST VARPTR(tags&(0)), _
  495.         PM_Title&,   SADD("UnSnapshot"+CHR$(0)), _
  496.         PM_CommKey&,  SADD("U"+CHR$(0)), _
  497.         TAG_DONE&
  498.  
  499.     pi&(6) = PM_MakeItemA&(VARPTR(tags&(0)))
  500.  
  501.     TAGLIST VARPTR(tags&(0)), _
  502.         PM_Title&,   SADD("Leave Out"+CHR$(0)), _
  503.         PM_CommKey&, SADD("L"+CHR$(0)), _
  504.         TAG_DONE&
  505.  
  506.     pi&(7) = PM_MakeItemA&(VARPTR(tags&(0)))
  507.  
  508.     TAGLIST VARPTR(tags&(0)), _
  509.         PM_Title&,   SADD("Put Away"+CHR$(0)), _
  510.         PM_CommKey&,  SADD("P"+CHR$(0)), _
  511.         TAG_DONE&
  512.  
  513.     pi&(8) = PM_MakeItemA&(VARPTR(tags&(0)))
  514.  
  515.     TAGLIST VARPTR(tags&(0)), _
  516.         PM_TitleBar&, TRUE&, _
  517.         TAG_DONE&
  518.  
  519.     pi&(9) = PM_MakeItemA&(VARPTR(tags&(0)))
  520.  
  521.     TAGLIST VARPTR(tags&(0)), _
  522.         PM_Title&,    SADD("Delete..."+CHR$(0)), _
  523.         PM_Disabled&, TRUE&, _
  524.         TAG_DONE&
  525.  
  526.     pi&(10) = PM_MakeItemA&(VARPTR(tags&(0)))
  527.  
  528.     TAGLIST VARPTR(tags&(0)), _
  529.         PM_Title&,   SADD("Format Disk..."+CHR$(0)), _
  530.         TAG_DONE&
  531.  
  532.     pi&(11) = PM_MakeItemA&(VARPTR(tags&(0)))
  533.  
  534.     TAGLIST VARPTR(tags&(0)), _
  535.         PM_Title&,   SADD("Empty Trash"+CHR$(0)), _
  536.         PM_CommKey&, TRUE&, _
  537.         TAG_DONE&
  538.  
  539.     pi&(12) = PM_MakeItemA&(VARPTR(tags&(0)))
  540.  
  541.     ' Grouping items / Agrupando ítems en un submenú
  542.     ' ----------------------------------------------
  543.  
  544.     TAGLIST VARPTR(tags&(0)), _
  545.         PM_Dummy&, 0&, _
  546.         TAG_DONE&
  547.  
  548.     FOR i& = 1 TO 12
  549.         TAGLIST VARPTR(tags&((i&-1)*2)), _
  550.             PM_Item&, pi&(i&), _
  551.             TAG_DONE&
  552.     NEXT i&
  553.  
  554.     mpi&(0) = PM_MakeMenuA&(VARPTR(tags&(0)))
  555.  
  556.     TAGLIST VARPTR(tags&(0)), _
  557.         PM_Title&, SADD("Icons"+CHR$(0)), _
  558.         PM_Sub&,   mpi&(0), _
  559.         TAG_DONE&
  560.  
  561.     mpi&(3) = PM_MakeItemA&(VARPTR(tags&(0)))
  562.  
  563.     ' =============================================================
  564.  
  565.     ' Tools item menu / Ítem del menú Tools
  566.     ' =====================================
  567.  
  568.     ' PMItem
  569.     ' ------
  570.  
  571.     TAGLIST VARPTR(tags&(0)), _
  572.         PM_Title&, SADD("ResetWB"+CHR$(0)), _
  573.         TAG_DONE&
  574.  
  575.     pi&(1) = PM_MakeItemA&(VARPTR(tags&(0)))
  576.  
  577.     ' Grouping items / Agrupando ítems en un submenú
  578.     ' ----------------------------------------------
  579.  
  580.     TAGLIST VARPTR(tags&(0)), _
  581.         PM_Dummy&, 0&, _
  582.         PM_Item&,  pi&(1),_
  583.         TAG_DONE&
  584.  
  585.     mpi&(0) = PM_MakeMenuA&(VARPTR(tags&(0)))
  586.  
  587.     TAGLIST VARPTR(tags&(0)), _
  588.         PM_Title&, SADD("Tools"+CHR$(0)), _
  589.         PM_Sub&,   mpi&(0), _
  590.         TAG_DONE&
  591.  
  592.     mpi&(4) = PM_MakeItemA&(VARPTR(tags&(0)))
  593.  
  594.     ' =========================
  595.     '  Creating the popup menu
  596.     ' Creando el menú emergente
  597.     ' =========================
  598.  
  599.     FOR i& = 1 TO 4
  600.         TAGLIST VARPTR(tags&((i&-1)*2)), _
  601.             PM_Item&, mpi&(i&), _
  602.             TAG_DONE&
  603.     NEXT i&
  604.  
  605.     MakeTestMenu& = PM_MakeMenuA&(VARPTR(tags&(0)))
  606.  
  607. END FUNCTION
  608.  
  609. ' =====================================================================
  610. '                          The code / El código
  611. ' =====================================================================
  612.  
  613. '            "Opening" all libraries needed
  614. ' Abriendo y preparando todas las bibliotecas necesarias
  615. ' ------------------------------------------------------
  616.  
  617. LIBRARY OPEN "exec.library"
  618. LIBRARY OPEN "popupmenu.library",POPUPMENU_VERSION&
  619.  
  620. pmb&=LIBRARY("popupmenu.library")
  621.  
  622. IF pmb& <> NULL& THEN
  623.     LIBRARY VARPTR "popupmenu.library", pmb&
  624.     ib& = PEEKL(pmb& + pmb_IntuitionBase%)
  625.     IF ib& <> NULL& THEN
  626.         LIBRARY VARPTR "intuition.library", ib&
  627.         gb& = PEEKL(pmb& + pmb_GfxBase%)
  628.         IF gb& <> NULL& THEN
  629.             LIBRARY VARPTR "graphics.library", gb&
  630.             ok& = TRUE&
  631.         END IF
  632.     END IF
  633. END IF
  634.  
  635. '  First, a C struct simulation (see the imsg var in original C code)
  636. '      Primero, reservo espacio para simular una estructura en C
  637. ' (consulte la función de la variable imsg en el código original en C)
  638. ' --------------------------------------------------------------------
  639. imsg&=AllocMem&(IntuiMessage_sizeof%,MEMF_ANY& OR MEMF_CLEAR&)
  640. IF imsg& = NULL& THEN
  641.     ok&= FALSE&
  642. END IF
  643.  
  644. IF ok& = TRUE& THEN
  645.  
  646.     ' Preparing my menu / Preparando mi menú
  647.     ' --------------------------------------
  648.     p& = MakeTestMenu&()
  649.  
  650.     IF p& <> NULL& THEN
  651.  
  652.         '   Window properties
  653.         ' Atributos de la ventana
  654.         ' -----------------------
  655.         TAGLIST VARPTR(mtags&(0)),_
  656.             WA_IDCMP&,       IDCMP_CLOSEWINDOW& OR IDCMP_MOUSEBUTTONS& OR IDCMP_VANILLAKEY&, _
  657.             WA_RMBTrap&,     TRUE&, _
  658.             WA_DragBar&,     TRUE&, _
  659.             WA_Width&,       150, _
  660.             WA_Height&,      100, _
  661.             WA_Left&,        0, _
  662.             WA_Top&,         100, _
  663.             WA_Title&,       SADD("PullDown Menus"+CHR$(0)), _
  664.             WA_CloseGadget&, TRUE&,_
  665.             TAG_DONE&
  666.  
  667.         '    Opening the window: this window is only needed to find out
  668.         '  when AND where the MENU should appear AND wich SCREEN it's on.
  669.         ' Abriendo la ventana: sólo es necesaria para saber dónde y cuándo
  670.         '       el menú emergente debe aparecer y sobre qué pantalla.
  671.         ' ----------------------------------------------------------------
  672.         w& = OpenWindowTagList&(NULL&, VARPTR(mtags&(0)))
  673.  
  674.         IF w& <> NULL& THEN
  675.  
  676.             ' Creating a Hook struct / Creando una estructura Hook
  677.             ' ----------------------------------------------------
  678.             INITHOOK VARPTR(MenuHandler%(0)),VARPTRS(MenuHandlerFunc&)
  679.  
  680.             WHILE r&
  681.  
  682.                 '  Waiting a message
  683.                 ' Esperando un mensaje
  684.                 ' --------------------
  685.                 dummy& = WaitPort&(PEEKL(w&+UserPort%))
  686.  
  687.                 DO
  688.  
  689.                     '    Get the message
  690.                     ' Se obtiene el mensaje
  691.                     ' ---------------------
  692.                     im& = GetMsg&(PEEKL(w&+UserPort%))
  693.                     IF im& THEN
  694.  
  695.                         '   ... but we will work with a copy
  696.                         ' ... pero se trabajará con una copia
  697.                         ' -----------------------------------
  698.                         CopyMem im&, imsg&, IntuiMessage_sizeof%
  699.                         ReplyMsg im&
  700.  
  701.                         TAGLIST VARPTR(mtags&(0)),_
  702.                             PM_AutoPullDown&, TRUE&,_
  703.                             PM_MenuHandler&,  VARPTR(MenuHandler%(0)), _
  704.                             TAG_DONE&
  705.  
  706.                         dummy& = PM_FilterIMsgA&(w&,p&,imsg&,VARPTR(mtags&(0)))
  707.  
  708.                         IF PEEKL(imsg&+Class%) =IDCMP_CLOSEWINDOW& THEN r&=FALSE&
  709.                         
  710.                     ELSE
  711.  
  712.                         EXIT LOOP
  713.  
  714.                     END IF
  715.  
  716.                 LOOP
  717.  
  718.             WEND
  719.  
  720.             CloseWindow& w&
  721.  
  722.         ELSE
  723.  
  724.             PRINT "Window error!"
  725.  
  726.         END IF
  727.  
  728.         PM_FreePopupMenu& p&
  729.  
  730.     ELSE
  731.  
  732.         PRINT "Menu error!"
  733.  
  734.     END IF
  735.  
  736. ELSE
  737.  
  738.     PRINT "The hook struct allocation or the libraries have failed!"
  739.  
  740. END IF
  741.  
  742. IF imsg& <> NULL& THEN FreeMem imsg&,IntuiMessage_sizeof%
  743.  
  744. IF gb& <> NULL& THEN LIBRARY VARPTR "graphics.library",  NULL&
  745. IF ib& <> NULL& THEN LIBRARY VARPTR "intuition.library", NULL&
  746.  
  747. '          Safe, even if the program fails to open the libraries
  748. ' Método seguro, incluso aunque el programa falle al abrir las bibliotecas
  749. ' ------------------------------------------------------------------------
  750. LIBRARY CLOSE "popupmenu.library"
  751. LIBRARY CLOSE "exec.library"
  752.  
  753. END
  754.