dumpwindow.f


\ DumpWindow.f
\
\ This is an example of how to use a callback's in Win32Forth.
\ It dump's all Top-Level-Windows to the console.
\
\ Written May 29th, 2003 - 11:37 by Dirk Busch (dbu)

[UNDEFINED] zCount [if]
: zCount    ( a1 -- a2 len ) \ get length of zstring
    TRUE 2dup 0 scan nip - ;
[then]

: GetProcessId { hWnd -- ProcessID } \ get ProcessId for given window
        here rel>abs hWnd call GetWindowThreadProcessId drop here @
;

: GetThreadId { hWnd -- ThreadID } \ get ThreadId for given window
        0 hWnd call GetWindowThreadProcessId
;

\ Define the callback function.
\
\ CallBack: Need's the NUMBER OF PARAMTERS passed to the funtion by
\           Windows on TOS
\
\ CallBack: Creates TWO definitions!  The first has the name you specify,
\           and the second has the same name, prefixed with a '&' meaning
\           'address of' This second definition is the one which returns the
\           address of the callback, and must be passed to Windows.

2 CallBack: DumpWindowCallback { hWnd lParam \ buff$ -- int } \ callback function for EnumWindows
        LMAXCOUNTED localalloc: buff$

        cr
        hWnd h.8 space
        hWnd GetProcessId h.8 space
        hWnd GetThreadId h.8 space

        LMAXCOUNTED buff$ rel>abs  hWnd
        call GetClassName 0<> if buff$ zcount type then cr 27 spaces

        LMAXCOUNTED buff$ rel>abs  hWnd
        call GetWindowText 0<> if buff$ zcount type else ." <no title>" then

        true \ default return value
;

: .Windows ( -- ) \ dump all Top-Level-Windows to the console
        cr cr ." Top-Level-Windows:"
        cr ." hWnd     ProcId   ThreadId ClassName - WindowTitle"

        0 \ lParam is passed to the callback funtion by Windows
        &DumpWindowCallback rel>abs \ get address of the callback function
        Call EnumWindows drop \ and use it
        cr
;

cls .Windows


This page was created with Forth to HTML.