Page 1 of 2
get handle

Posted:
November 29th, 2004, 1:18 pm
by firejocker
Hello all,
So, sorry for my writed, but I'm a french developper with a bad english.
I'm looking how to get the handle of a text area (witch can be memo, edit ...) of another software where is the keyboad focus.
my program run being hidded, and i have to get the handle od the area where the user is writting (notepad, word, ...) to modify some data.
how can i get it ?
Thanks all.
FireJocker.

Posted:
November 29th, 2004, 6:08 pm
by Kambiz
- Code: Select all
function GetGlobalFocus: THandle;
var
GUIThreadInfo: TGUIThreadInfo;
begin
GUIThreadInfo.cbSize := SizeOf(TGUIThreadInfo);
if GetGUIThreadInfo(0, GUIThreadInfo) then
Result := GUIThreadInfo.hwndFocus
else
Result := 0;
end;

Posted:
November 30th, 2004, 7:11 am
by firejocker
Good !! it run !
Really thanks from france !!

Posted:
November 30th, 2004, 12:36 pm
by firejocker
I don't understand something ...
Why
- Code: Select all
procedure TForm1.test;
var
h,hedit: hwnd;
s: pchar;
str : string;
debut,fin:integer;
begin
hedit := GetGlobalFocus;
str := 'test';
SendMessage(hedit, WM_SETTEXT, 0,integer(Str));
end;
works with notepad ... but doesn't with firefox ?

Posted:
December 10th, 2004, 8:56 am
by Kambiz
What's firefox?

Posted:
December 14th, 2004, 10:13 am
by firejocker
it's an internet browser
http://www.firefox.com/
it works neither with firefox nor IE

Posted:
December 14th, 2004, 12:34 pm
by Kambiz
Edit fields in a browser are not as same as Windows edit fields. Therefor, you cannot use WM_SETTEXT message to set the text of a field.
I guess browser uses handleless control for edit fields of the forms.

Posted:
December 14th, 2004, 1:08 pm
by firejocker
so bad news !
there isn't any way to send data like with normal edit ?

Posted:
December 14th, 2004, 5:58 pm
by Kambiz
If you get the browser COM interface, you have full access to the entire web elements of a page.

Posted:
December 15th, 2004, 7:07 am
by firejocker
How doing this ?

Posted:
December 20th, 2004, 11:15 am
by Stefan
I don't know if FF support ActiveX or COM, I believe there is a way to build FF so that it supports ActiveX. I think you might want to look for XPConnect for FF (or something like that).
To get a (IE) browser in Delphi, simply drop the TWebBrowser control (on the Internet tab) on your form et voila!
It all depends on what you want to do though. If you want to interact with a running instance of IE that the user is using try:
- Code: Select all
function GetRunningInstance: IWebBrowser2;
var
ShWindows: IShellWindows;
i: integer;
begin
ShWindows := CoShellWindows.Create;
for i := 0 to ShWindows.Count - 1 do
begin
Result := ShWindows.Item(i) as IWebBrowser2;
if Result.LocationURL =
'http://sourceforge.net/projects/extgraph' then
Break;
end;
end;
This returns a IWebBrowser2 interface for the user's current IE session if the LocationURL property equals 'http://sourceforge.net/projects/extgraph'.
Cheers
Stefan

Posted:
December 20th, 2004, 1:05 pm
by firejocker
I just want to get focus and send data like pressed on the keyboard,
It run with program but doesn't on a browser

Posted:
December 20th, 2004, 1:54 pm
by Stefan
This does not do *exactly* what you want. It does not allow you to get the handle of the control, though it does allow you to set the text and navigate to the specified URL:
- Code: Select all
function GetActiveIEBrowser: IWebBrowser2;
var
shellWindows: IShellWindows;
i: Integer;
webBrowser: IWebBrowser2;
begin
Result := nil;
shellWindows:= CoShellWindows.Create;
for i:=0 to shellWindows.Count -1 do
if Supports(shellWindows.Item(i), IWebBrowser2, webBrowser) then begin
// Separates IE from Explorer
if AnsiLowerCase(ExtractFileName(webBrowser.FullName)) = 'iexplore.exe' then begin
Result:= webBrowser;
Break;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
brwsr: IWebBrowser2;
begin
brwsr := GetActiveIEBrowser;
brwsr.Navigate('http://sourceforge.net/projects/extgraph', emptyparam,emptyparam,emptyparam,emptyparam);
end;

Posted:
December 20th, 2004, 2:52 pm
by firejocker
with this, is it possible to set data in an online form ?

Posted:
December 20th, 2004, 3:40 pm
by Stefan