Yes, the EnumWindows function is tailor made for that task.
You pass a callback function to it, in which you can simply call EnumChildWindows on all the window handles you get.
Here's something I was playing with a long time ago, I'll just post it as is, so it might have a few errors, but it still demonstrates its use. The purpose of it was to find a notepad window and type the message in it using SendMessage.
Code:
#include <windows.h>
#include <stdio.h>
char message[] = "\n\nI can see you.\n\nI herd u like mudkipz.\n\n .. Is dat right?\n";
BOOL CALLBACK EnumChildProc(HWND hWnd, LPARAM lParam)
{
char buffer[100] = {0};
unsigned int i = 0;
if(!hWnd) return TRUE;
if(GetClassName(hWnd, buffer, 100) == 0) return TRUE;
printf(" - %s\n", buffer);
/*for(i = 0; i < strlen(message); i++)
{
SendMessage(hWnd, WM_CHAR, message[i], 0);
sleep(200);
}*/
memset(buffer, 0, 100);
}
BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam)
{
char buffer[100] = {0};
int i = 0;
if(!hWnd) return TRUE;
if(GetWindowText(hWnd, buffer, 100) == 0) return TRUE;
printf("Child windows for '%s':\n", buffer);
//SetForegroundWindow(hWnd);
EnumChildWindows(hWnd, EnumChildProc, 0);
memset(buffer, 0, 100);
}
int main(void)
{
//ShellExecute(NULL, "open", "notepad.exe", NULL, "C:\\Windows", SW_SHOW);
sleep(500);
EnumWindows(EnumWindowsProc, 0);
}