Code:
// Automater.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam)
{
LPTSTR szBuff;
if (GetWindowText(hwnd, szBuff, sizeof(szBuff)))
{
if (!strcmp("SysTreeView32", szBuff))
{
//We found the button!
TCHAR szBuff2[512];
_stprintf_s(szBuff2, _T("%p\n"), szBuff);
MessageBox(NULL, szBuff2, _T("Found Windows"), MB_OK);
return true;
}
}
//No button was found
return false;
}
int _tmain(int argc, _TCHAR* argv[])
{
//Hide Console Window
FreeConsole();
//Start our Application
ShellExecute(NULL, "open", "c:\\Program Files\\AD Pictures\\AD Pictures.exe", NULL, NULL, SW_SHOWNORMAL);
Sleep(3000);
//Get Parent Handle of Application
HWND mainApp = FindWindow("#32770", "AD Pictures by Exclaimer");
//EnumChildWindows(mainApp , FindWindow("SysTreeView32", NULL), 0);
EnumChildWindows(mainApp, (WNDENUMPROC)&EnumChildProc, 0);
HWND child1 = FindWindowEx(mainApp, NULL, "#32770", "AD Pictures by Exclaimer");
HWND child2 = FindWindowEx(child1, NULL, "#32770", "Browse For Folder");
HWND child3 = FindWindowEx(child2, NULL, "SHBrowseForFolder ShellNameSpace Control", NULL);
HWND child4 = FindWindowEx(child3, NULL, "SysTreeView32", NULL);
HWND child5 = GetWindow(child4, NULL);
/*
HWND child1 = GetWindow(mainApp, GW_CHILD);
HWND child2 = GetWindow(child1, GW_CHILD);
HWND child3 = GetWindow(child2, GW_CHILD);
HWND child4 = GetWindow(child3, GW_CHILD);
HWND child5 = GetWindow(child4, GW_CHILD);
*/
//Get handle for next button
HWND DialogButtonHandle = FindWindowEx(mainApp, 0, "Button", "&Next >");
//First next button
SendMessage(DialogButtonHandle, BM_CLICK, 1, 0);
Sleep(500);
//Select "Import Multiple Images" radio button
keybd_event(VK_UP, NULL, NULL, NULL);
keybd_event(VK_UP, NULL, KEYEVENTF_KEYUP, NULL);
Sleep(500);
//Second next button
SendMessage(DialogButtonHandle, BM_CLICK, 1, 0);
Sleep(500);
//Make sure our app is running, if it's not wait 5 seconds
TCHAR szBuff[512];
_stprintf_s(szBuff, _T("%p\n%p\n%p\n%p\n%p\n%p\n"), mainApp, child1, child2, child3, child4, child5);
MessageBox(NULL, szBuff, _T("Found Windows"), MB_OK);
system("Pause");
return 0;
}