Re: Auto Fill Web Forms




Thanks for the help guys!

The thing is that, I don't want to go down the 'HTML parser' route as
I want to extend my form filling to windows applications other than
just IE so I'm looking to do something that has to use the Windows API
(unfortunately).

The code I've got to at the moment is something like this:

TimeOut is a global boolean set true by Timer1 after 10s (say).

Var
WndStart, WndNew, Wnd: HWnd;
ProcessId: DWord;
begin
WndStart := GetForegroundWindow; // get my apps handle
// (application.handle doesn't seem to give result I want)
RunApplication('notepad.exe'); // RunApplication does ShellExecute
// or could be something like this
//RunApplication('http://www.google.com');
TimeOut := False;
Timer1.Enabled := true;
Repeat // wait until new application is in foreground
Application.ProcessMessages;
WndNew := GetForegroundWindow;
Until TimeOut or (WndStart <> WndNew);
Timer1.Enabled := false;
If not TimeOut then
begin
Wnd := GetWindowThreadProcessId(WndNew, ProcessId);
z := WaitForInputIdle(ProcessId,10000);
// this always fails with z = $0FFFFFFFF

// If z = $0FFFFFFFF then deal with error
end;

SendKeys('test message'); // sends key presses to new application
end;

The above works except for the 'WaitForInputIdle' part which always
fails with an incorrect handle error. I've checked the ProcessId and
this is correct though. Maybe I can't use this call in this way? I
need something that waits until a webpage is fully downloaded - how
else could my app detect this? Currently, it works with notepad but
the text is sent too quickly to register on a webpage. I don't want to
delay everything with timers set to several seconds as this seems
imprecise!

The SendKeys looks like the simplest option to deliver the data to the
new app as it automatically targets the active window although I'd
prefer to enumerate the controls and activate a control rather than
just 'Tab' to a control and hope!

I'm finding this Windows API stuff quite a challenge and different
from what I'm used to!!!

Thanks again!

--
Z
.



Relevant Pages