More WinAPI functions for CallBack
Marching ahead from the last post WinAPI CallBack functions, we will discuss here four other WinAPI functions that enables CallBacks, the EnumWindows, EnumDesktopWindows, EnumThreadWindows and EnumChildWindows
EnumWindows function enumerates all top-level windows by making a callback to the application defined function for each window it encounters passing the handle to the window. The first parameter it takes is the pointer to the application defined function that will handle the callback. The send parameter is a parameter of type long that the function handling the callback needs to receive when callback occurs.
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, _ ByVal lParam As Long) As Long
The function that receives the callback is required to be defined with parameters as below. The first parameter received is the handle to the window and the second parameter is the parameter that was defined by the EnumWindows to be passed while making a callback. As already mention in previous post Where’s TimerProc Function?, the function name, as above, is just a placeholder to the application-defined function and can be named anything.
Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Similarly EnumChildWindows passes the handle to the parent window in addition to the parameters passed by EnumWindows, causing the system to enumerate the Child windows of the given parent window calling the callback function for each and passing the handle to the windows.
Public Declare Function EnumChildWindows Lib "user32" Alias "EnumChildWindows" ( _ ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Now what type of function is to be defined for handling the callback? Well, it’s same as the EnumWindowsProc defined above and Microsoft calls it EnumChildProc. As already mentioned it can be named anything!
EnumDesktopWindows is similar to EnumChildWindows except that it takes handle to the desktop instead of parent window. The callback function should be declared as EnumWindowsProc above.
Public Declare Function EnumDesktopWindows Lib "user32" Alias "EnumDesktopWindows" ( _ ByVal hDesktop As Long, ByVal lpfn As Long, ByVal lParam As Long) As Long
EnumThreadWindows enumerates all non-child windows associated with the thread as passed through first parameter calling the application defined callback function passing the handle to he windows for each of the windows. The callback function EnumThreadWndProc is declared similar to EnumWindowsProc function.
Public Declare Function EnumThreadWindows Lib "user32" Alias "EnumThreadWindows" ( _ ByVal dwThreadId As Long, ByVal lpfn As Long, ByVal lParam As Long) As Long
