First, its prototype
Bool enumwindows (
Wndenumproc lpenumfunc, // address of the callback function -- to put it bluntly, the callback function name is put in this
Lparam // if it is used to enumerate all windows on the desktop, add 0 or null.
);
Let's take a look at the callback function prototype.
Bool callback enumwindowsproc (
Hwnd, // handle parameter. Here the returned window handle is
Lparam // application-defined value -- I don't know what it means.
);
When using the callback function, you must write the prototype above. The name of the enumwindowsproc function must be the same.
Just start it, for example: bool callback ABCD (hwnd, lparam); remove ";" from the function body. The function body is what you want to execute. Code For example:
Bool callback ABCD (hwnd, lparam)
{
Cstring text;
Int Len =: getwindowtextlength (hwnd); // obtain the title length pointed to by the window handle hwnd.
: Getwindowtext (hwnd, (lpstr) (lpctstr) text, Len + 1); get the title of the window pointed to by the window handle hwnd
M_list.addstring (lpstr) (lpctstr) text); // m_list is the clistbox m_list pointing to the list box.
Return 1; // 1 must be returned here. If 0 is returned, it is not enumerated.
}
Example:
bool callback myenumproc (hwnd, lparam)
{< br> printf ("the window handle is % x, and the passed parameter is % d", hwnd, lparam);
}< br> main
{< br> int n = 3; // any parameter
enumwindows (myenumproc, (lparam) n);
...
}