get handle

Please discuss general Delphi programming topics here.

get handle

Postby firejocker » November 29th, 2004, 1:18 pm

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.
firejocker
Active Member
Active Member
 
Posts: 9
Joined: November 29th, 2004, 1:17 pm

Postby Kambiz » November 29th, 2004, 6:08 pm

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;
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2420
Joined: March 7th, 2003, 7:10 pm

Postby firejocker » November 30th, 2004, 7:11 am

Good !! it run !

Really thanks from france !!
firejocker
Active Member
Active Member
 
Posts: 9
Joined: November 29th, 2004, 1:17 pm

Postby firejocker » November 30th, 2004, 12:36 pm

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 ?
Last edited by firejocker on December 14th, 2004, 10:16 am, edited 1 time in total.
firejocker
Active Member
Active Member
 
Posts: 9
Joined: November 29th, 2004, 1:17 pm

Postby Kambiz » December 10th, 2004, 8:56 am

What's firefox?
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2420
Joined: March 7th, 2003, 7:10 pm

Postby firejocker » December 14th, 2004, 10:13 am

it's an internet browser
http://www.firefox.com/

it works neither with firefox nor IE
firejocker
Active Member
Active Member
 
Posts: 9
Joined: November 29th, 2004, 1:17 pm

Postby Kambiz » December 14th, 2004, 12:34 pm

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.
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2420
Joined: March 7th, 2003, 7:10 pm

Postby firejocker » December 14th, 2004, 1:08 pm

so bad news !

there isn't any way to send data like with normal edit ?
firejocker
Active Member
Active Member
 
Posts: 9
Joined: November 29th, 2004, 1:17 pm

Postby Kambiz » December 14th, 2004, 5:58 pm

If you get the browser COM interface, you have full access to the entire web elements of a page.
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2420
Joined: March 7th, 2003, 7:10 pm

Postby firejocker » December 15th, 2004, 7:07 am

How doing this ?
firejocker
Active Member
Active Member
 
Posts: 9
Joined: November 29th, 2004, 1:17 pm

Postby Stefan » December 20th, 2004, 11:15 am

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
User avatar
Stefan
Moderator
Moderator
 
Posts: 128
Joined: September 27th, 2004, 9:40 am
Location: Tilburg, The Netherlands

Postby firejocker » December 20th, 2004, 1:05 pm

I just want to get focus and send data like pressed on the keyboard,

It run with program but doesn't on a browser
firejocker
Active Member
Active Member
 
Posts: 9
Joined: November 29th, 2004, 1:17 pm

Postby Stefan » December 20th, 2004, 1:54 pm

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;
User avatar
Stefan
Moderator
Moderator
 
Posts: 128
Joined: September 27th, 2004, 9:40 am
Location: Tilburg, The Netherlands

Postby firejocker » December 20th, 2004, 2:52 pm

with this, is it possible to set data in an online form ?
firejocker
Active Member
Active Member
 
Posts: 9
Joined: November 29th, 2004, 1:17 pm

Postby Stefan » December 20th, 2004, 3:40 pm

User avatar
Stefan
Moderator
Moderator
 
Posts: 128
Joined: September 27th, 2004, 9:40 am
Location: Tilburg, The Netherlands

Next

Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron