\ File: DumpWindows.f \ Author: Dirk Busch \ Created: May 29th, 2003 - 11:37 - dbu \ Updated: January 24th, 2004 - 9:06 - dbu \ \ This is an example of how to use a callback's in Win32Forth. \ It dump's all Top-Level-Windows to the console. anew DumpWindows.f INTERNAL [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 for EnumWindows(). \ \ 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 ." " then true ; \ default return value : (.Windows) ( -- ) \ dump all Top-Level-Windows to the console 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 EXTERNAL : .Windows ( -- ) \ dump all Top-Level-Windows to the console cr cr ." Top-Level-Windows:" cr ." hWnd ProcId ThreadId ClassName - WindowTitle" (.Windows) cr ; MODULE