- Example: Calling a function of the Windows API with Callback
Example: Calling a function of the Windows API with Callback
The following example is used to implement a trace file containing all the identifiers (handles) of the windows currently opened on the current computer.
The StartATrace procedure opens the trace file and lists the windows via the ListWindows function of the User32 API.
The ListWindowProc procedure is called by the ListWindows function of the User32 API for each window found. This procedure is used to write the identifier of the window found into the trace file.
// Open file
nFile is int = fOpen(fDataDir() + ...
IF nFile = -1 THEN
Error("Problem with the file")
// Start the enumeration with the identifier of the opened file as parameter
// (it will be passed as parameter to the CallBack)
API("User32", "ListWindows", &ListWindowProc, nFile)
// Close the file
// Display in a trace window
Trace(fLoadText(fDataDir() + "\TitlesAndClassesOfWindows.txt"))
// ----- With the following procedure:
// nHwnd is the parameter received from the API function
// with the handle of the window
// nFileID is the parameter that was passed
// during the call to the API function
PROCEDURE ListWindowProc(nHwnd is int system, ...
nFileID is int system)
nClassNameMaxSize is int = 1024
sWindowClassName is ASCIIZ string on 1024
sWindowTitle is string
// Retrieve the Windows class of the window
API( "user32.dll", "GetClassNameA", nHwnd, &sWindowClassName, ...
// Retrieve the title of the window
sWindowTitle = SysWinTitle(nHwnd)
IF sWindowTitle ~= "" THEN sWindowTitle="<no title>"
// Write the identifier passed as parameter into the file
fWriteLine(nFileID, sWindowTitle + "," + sWindowClassName)
IF sWindowClassName ~= "Name of the window class" THEN
// Stop the enumeration
// The enumeration continues
This page is also available for…