
    texteditor #win.te, 10, 10, 250, 250
    open "Enum Windows Example" for window as #win
    print #win, "trapclose [quit]"

    'set the variable named address to be the memory address for
    'enumWndProc() using types handle and ulong, and set
    'the return type of enumWndProc() to be a boolean
    callback address, enumWndProc(handle, ulong), boolean
    open "user32" for dll as #user32

    'call EnumWindows, which in turn calls back into the
    'BASIC function at address.
    calldll #user32, "EnumWindows", _
        address as ulong, _
        0 as long, _
        result as boolean
    close #user32
    wait

[quit]
    close #win
    end

function enumWndProc(hwnd, lparam)
    labelBuffer$ = space$(71)
    calldll #user32, "GetWindowTextA", _
        hwnd as ulong, _
        labelBuffer$ as ptr, _
        70 as long, _
        result as long
    if left$(labelBuffer$, 1) <> chr$(0) then
        print #win.te, labelBuffer$
        call setCount getCount()+1
    end if
    if getCount() = 5 then
        enumWndProc = 0   'returning 0 causes EnumWindows to return
      else
        enumWndProc = 1
    end if
end function

sub setCount value
    count(0) = value
end sub

function getCount()
    getCount = count(0)
end function
