How to Walk the Widget Tree

/* walk_widget_tree.p 
   Example:  Press F5 to test
   Dmitri Levin 07/26/1999
   */

define variable c1 as char.
define variable a1 as char.
define variable a2 as char.
define variable b1 as char.
define variable b2 as char.
define frame aa  a1 a2.
define frame bb  b1 b2.

on "F5" anywhere run find-all-widgets( active-window:handle ).

enable c1.
enable all with frame bb.
enable all with frame aa.

wait-for window-close of current-window.  

procedure find-all-widgets.
  define input parameter wh-handle as handle  no-undo.

  if not valid-handle( wh-handle ) then return.
  wh-handle = wh-handle:first-child /* First Frame */.

  do while wh-handle <> ?:
    if not valid-handle( wh-handle ) then return.

    if lookup("screen-value",LIST-QUERY-ATTRS(wh-handle)) > 0 then
      message "TYPE:" wh-handle:type skip
              "NAME:" wh-handle:name skip
              "VALUE:" wh-handle:screen-value 
         view-as alert-box.
    else 
      message "TYPE:" wh-handle:type skip
              "NAME:" wh-handle:name skip
         view-as alert-box.

    if wh-handle:type = "FRAME" or wh-handle:type = "FIELD-GROUP" then 
      run find-all-widgets( wh-handle:handle ).

    wh-handle = wh-handle:next-sibling.
  end. /* do while */

end procedure. /*find-all-widgets*/