Consultor Eletrônico



Kbase P19700: How to list all widgets in the current window that have own
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   20/02/2003
Status: Unverified

GOAL:

How to list all widgets in the current window that have own popup menus?

FACT(s) (Environment):

Windows

FIX:

1. Use the AppBuilder to Create a new window.
2. Drop an assortment of widgets on this window.
3. Define some popup menus for some of the above widgets.
4. Add the following code to the definition section:

DEFINE VARIABLE hCurrentWidget AS WIDGET-HANDLE NO-UNDO.
DEFINE VARIABLE hTempVariable AS HANDLE NO-UNDO.

DEFINE TEMP-TABLE MenuWidgets NO-UNDO
FIELD WidgetHandle AS WIDGET-HANDLE
FIELD WidgetName AS CHARACTER
FIELD WidgetLabel AS CHARACTER
FIELD WidgetType AS CHARACTER
FIELD WidgetParent AS WIDGET-HANDLE.

5. Define an internal procedure, "GetWidgets" with the following code:

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

hCurrentWidget = hCurrentWidget:FIRST-CHILD NO-ERROR.
DO WHILE VALID-HANDLE(hCurrentWidget):
hTempVariable = hCurrentWidget:POPUP-MENU NO-ERROR.
IF VALID-HANDLE(hTempVariable) THEN DO:
CREATE MenuWidgets.
ASSIGN
WidgetHandle = hCurrentWidget
WidgetName = hCurrentWidget:NAME
WidgetType = hCurrentWidget:TYPE
WidgetLabel = hCurrentWidget:LABEL
WidgetParent = hCurrentWidget:PARENT NO-ERROR.

END.
RUN GetWidgets(hCurrentWidget).
hCurrentWidget = hCurrentWidget:NEXT-SIBLING.
END.

END PROCEDURE.

6. Drop a button on the window with the following CHOOSE event trigger code:

DO:
OUTPUT TO myFile.txt.
RUN GetWidgets(CURRENT-WINDOW).
FOR EACH MenuWidgets NO-LOCK:
DISPLAY
INTEGER(WidgetHandle) FORMAT "999999" LABEL "Handle"
WidgetName FORMAT "X(15)" LABEL "Name"
WidgetType FORMAT "X(10)" LABEL "Type"
WidgetLabel FORMAT "X(10)" LABEL "Label"
INTEGER(WidgetParent) FORMAT "999999" LABEL "Parent".
END.
OUTPUT CLOSE.
END.

7. Save the window.
8. Run the window.
9. Open "myFile.txt" using the procedure editor or notepad.
10. Selected data on all widgets with associated POPUP menus are listed.