Retrieve text of focused control in another application, namely IE
Posted on 2003-12-02
I want to write a function to retrieve the text of the active (focused) control, even if the control belongs to another application.
The function below does that in most cases. However, it doesn't work if Internet Explorer is the foreground application and the user is in, for example, a TEXTAREA field. (Like the one that I am typing in right now.) Does that control not respond to the WM_GetText message or do you think GetFocus() is returning the wrong handle? In either case, how would I go about reading the text from this type of control within IE?
function GetActiveText: String;
MaxTextLen = 5000;
FW, FC : HWND;
ThID : DWORD;
Buf : array[0..MaxTextLen] of Char;
FW := 0;
FC := 0;
FW := GetForegroundWindow;
ThID := GetWindowThreadProcessId(FW,0);
FC := GetFocus();
Result := Buf;