Consultor Eletrônico



Kbase P19704: How to access a widget's popup-menu information?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   2/20/2003
Status: Unverified

GOAL:

How to access a widget's popup-menu information?

FACT(s) (Environment):

windows

FIX:

1. Create a new regular window.

2. Add the following code to the Definition section:

DEFINE VARIABLE hCurrentWidget AS WIDGET-HANDLE NO-UNDO.

DEFINE TEMP-TABLE MenuItem NO-UNDO
FIELD MenuItemHandle AS WIDGET-HANDLE
FIELD MenuItemName AS CHARACTER
FIELD MenuItemLabel AS CHARACTER
FIELD MenuItemType AS CHARACTER
FIELD MenuItemSubType AS CHARACTER
FIELD MenuItemParent AS WIDGET-HANDLE.

3. Drop a button on the window and define a popup menu with sub-menus for it.

4. Define an internal procedure "GetMenu" with following code:

DEFINE INPUT PARAMETER hCurrentWidget AS WIDGET-HANDLE NO-UNDO.

hCurrentWidget = hCurrentWidget:FIRST-CHILD NO-ERROR.
DO WHILE VALID-HANDLE(hCurrentWidget):
CREATE MenuItem.
ASSIGN
MenuItemHandle = hCurrentWidget
MenuItemName = hCurrentWidget:NAME
MenuItemLabel = hCurrentWidget:LABEL
MenuItemType = hCurrentWidget:TYPE
MenuItemSubType = hCurrentWidget:SUBTYPE
MenuItemParent = hCurrentWidget:OWNER NO-ERROR.
RUN GetMenu(hCurrentWidget).
hCurrentWidget = hCurrentWidget:NEXT-SIBLING.
END.

END PROCEDURE.

5. Define the following CHOOSE event trigger code for the button:

DO:
OUTPUT TO myFile.txt.

hCurrentWidget = SELF:POPUP-MENU.
CREATE MenuItem.
ASSIGN
MenuItemHandle = hCurrentWidget
MenuItemName = hCurrentWidget:NAME
MenuItemLabel = hCurrentWidget:LABEL
MenuItemType = hCurrentWidget:TYPE
MenuItemSubType = hCurrentWidget:SUBTYPE
MenuItemParent = hCurrentWidget:OWNER NO-ERROR.

RUN GetMenu(hCurrentWidget).

FOR EACH MenuItem NO-LOCK:
DISPLAY
INTEGER(MenuItemHandle) FORMAT "999999" LABEL "Handle"
MenuItemName FORMAT "X(15)" LABEL "Name"
MenuItemLabel FORMAT "X(10)" LABEL "Label"
MenuItemType FORMAT "X(10)" LABEL "Type"
MenuItemSubType FORMAT "X(10)" LABEL "Type".
END.
OUTPUT CLOSE.
END.

6. Save and Run the window.

7. The file myFile.txt contains all the selected information about the popup menu and its sub menu items.