OK, here is a rough description of how it works in C++ using WinAPI calls, so I am sure its similar in Delphi.
First you need to get the window handle of the target process, lets say you were trying to get the Window handle of AOL IM.
You tell WinAPI that you want it to enumerate all active windows for you and call your callback function for each:
Code:
EnumWindows(MyEnumWindows_CallbackFunc,NULL);
Then, for every window, your callback is called:
Code:
BOOL CALLBACK MyEnumWindows_CallbackFunc(HWND hwnd, LPARAM lParam)
{
CWnd *temp;
char buffer[255];
temp = CWnd::FromHandle(hwnd);
if (!temp) return 0;
GetClassName(hwnd,buffer,254);
// Check and see if buffer = the window you want, i.e. AIM_ChatWnd
// If it is, then you can grab the title bar like such:
temp->GetWindowText(buffer);
return 1;
}
Now that you have the hwnd to your target window, save it somewhere as a long unsigned int. (Pointer)
Then you have to find hWnd handles to each of the components of the menus or buttons within. You can do this with a program called Spy++.
So, lets say I wanted to grab a button from an AIM chat window and click it.
I could do:
Code:
hChatBtn = temp->FindWindowEx(temp->m_hWnd,NULL,"_Oscar_IconBtn",NULL);
if (!hChatBtn) return 0;
// Since you do this in the background you want to save the current focused window
hFocus = CWnd::GetFocus();
// Now you click it if you want by sending WinAPI messages
hChatBtn->SendMessage(WM_LBUTTONDOWN, 0, 0);
hChatBtn->SendMessage(WM_LBUTTONUP, 0, 0);
// Return the window focus
if (hFocus) hFocus->SetFocus();
You can use or manipulate any program this way as long as you can search through its Window handles in Spy++. Try it for yourself.
I hope this helps you with doing it in Delphi, even though this is C++ crap.